Skip to content

Commit

Permalink
WIP: Fix test names with data set (#19)
Browse files Browse the repository at this point in the history
* Add tests for data set names.

* Fix test names with data set

Fixes #18
  • Loading branch information
alexeymenkov authored and rudowastaken committed Feb 20, 2019
1 parent a61005f commit b35aae5
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 8 deletions.
6 changes: 4 additions & 2 deletions src/Printer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
17 changes: 17 additions & 0 deletions tests/_files/PrinterNamesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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],
];
}
}
23 changes: 17 additions & 6 deletions tests/names-test.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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.

0 comments on commit b35aae5

Please sign in to comment.