PHPUnit: How to show more info in testdox output when using data providers

Probably the geekiest and most obscure blog post title I’ll ever write, but we’ll see!

class DataProviderExampleTest extends PHPUnit_Framework_TestCase
{
/**
* @dataProvider colourStatementsProvider
*/
public function testItemIsCorrectColour($statement, $item, $colour)
{
$parts = explode(' is ', $statement);
$this->assertEquals($parts[0], $item);
$this->assertEquals($parts[1], $colour);
}

public function colourStatementsProvider()
{
return array(
'apple-is-green' => array('apple is green', 'apple', 'green'),
'apple-is-red' => array('apple is red', 'apple', 'red'),
'sky-is-blue' => array('sky is blue', 'sky', 'grey'),
);
}
}

Now run the test:

% phpunit DataProviderExampleTest.php
PHPUnit 3.4.3 by Sebastian Bergmann.

..F

Time: 0 seconds

There was 1 failure:

1) DataProviderExampleTest::testItemIsCorrectColour with data set "sky-is-blue" ('sky is blue', 'sky', 'grey')
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-blue
+grey

/Users/tim/Desktop/DataProviderExampleTest.php:12

FAILURES!
Tests: 3, Assertions: 6, Failures: 1.

Here’s the testdox output:

% phpunit --testdox DataProviderExampleTest.php
PHPUnit 3.4.3 by Sebastian Bergmann.

DataProviderExample
[ ] Item is correct colour

In previous versions of PHPUnit there used to be more info…

in PHPUnit_Util_TestDox_ResultPrinter change the following line (246) from (part of the startTest function)

from:

$this->currentTestMethodPrettified = $this->prettifier->prettifyTestMethod($test->getName(FALSE));

to:

$this->currentTestMethodPrettified = $this->prettifier->prettifyTestMethod($test->getName());
% phpunit --testdox DataProviderExampleTest.php
PHPUnit 3.4.3 by Sebastian Bergmann.

DataProviderExample
[x] Item is correct colour with data set "apple-is-green"
[x] Item is correct colour with data set "apple-is-red"
[ ] Item is correct colour with data set "sky-is-blue"

much better.

Comments