From b35aae5f632518a6e413761f077a188b2c088f24 Mon Sep 17 00:00:00 2001 From: Alexey Menkov Date: Wed, 20 Feb 2019 13:28:19 +0300 Subject: [PATCH] WIP: Fix test names with data set (#19) * Add tests for data set names. * Fix test names with data set Fixes #18 --- src/Printer.php | 6 ++++-- tests/_files/PrinterNamesTest.php | 17 +++++++++++++++++ tests/names-test.phpt | 23 +++++++++++++++++------ 3 files changed, 38 insertions(+), 8 deletions(-) diff --git a/src/Printer.php b/src/Printer.php index bf8b053..27b8a6d 100644 --- a/src/Printer.php +++ b/src/Printer.php @@ -114,9 +114,11 @@ public function addSkippedTest(Test $test, \Throwable $e, float $time) : void */ public function endTest(Test $test, float $time) : void { - $testName = UtilTest::describe($test); + $testName = UtilTest::describeAsString($test); - $this->buildTestRow($testName[0], $testName[1], $time); + list($className, $methodName) = explode("::", $testName); + + $this->buildTestRow($className, $methodName, $time); parent::endTest($test, $time); } diff --git a/tests/_files/PrinterNamesTest.php b/tests/_files/PrinterNamesTest.php index 781d50f..6453c1e 100644 --- a/tests/_files/PrinterNamesTest.php +++ b/tests/_files/PrinterNamesTest.php @@ -28,4 +28,21 @@ public function test_Supports_whateverCase() { $this->assertTrue(true); } + + /** + * @test + * @dataProvider dataSetExamples + */ + public function itSupportsDataProvider($a, $b, $expected) + { + $this->assertTrue($expected); + } + + public function dataSetExamples() + { + return [ + ['a', 'b', true], + [1, [1, 2], false], + ]; + } } diff --git a/tests/names-test.phpt b/tests/names-test.phpt index 34967f7..febe0d8 100644 --- a/tests/names-test.phpt +++ b/tests/names-test.phpt @@ -15,13 +15,24 @@ PHPUnit\TextUI\Command::main(); --EXPECTF-- PHPUnit %s by Sebastian Bergmann and contributors. -(1/5) ✔ PrinterNamesTest: Test It Supports Camel Case (%s ms) -(2/5) ✔ PrinterNamesTest: Test It Supports Camel Case With CAPS Parts (%s ms) -(3/5) ✔ PrinterNamesTest: It supports snake case (%s ms) -(4/5) ✔ PrinterNamesTest: Itworkswithoutspacesaswell (%s ms) -(5/5) ✔ PrinterNamesTest: Test Supports whatever Case (%s ms) +(1/7) ✔ PrinterNamesTest: Test It Supports Camel Case (%s ms) +(2/7) ✔ PrinterNamesTest: Test It Supports Camel Case With CAPS Parts (%s ms) +(3/7) ✔ PrinterNamesTest: It supports snake case (%s ms) +(4/7) ✔ PrinterNamesTest: Itworkswithoutspacesaswell (%s ms) +(5/7) ✔ PrinterNamesTest: Test Supports whatever Case (%s ms) +(6/7) ✔ PrinterNamesTest: It Supports Data Provider with data set #0 ('a', 'b', true) (%s ms) +(7/7) ✖ PrinterNamesTest: It Supports Data Provider with data set #1 (%s ms) Time: %s, Memory: %sMB -OK (5 tests, 5 assertions) +There was 1 failure: + +1) PrinterNamesTest::itSupportsDataProvider with data set #1 (1, array(1, 2), false) +Failed asserting that false is true. + +%sPrinterNamesTest.php:38 + +FAILURES! +Tests: 7, Assertions: 7, Failures: 1. +