When in PHPUnit test fails, actual and expected values are displayed.
But when the test passes, this information is not displayed.
How to force PHPUnit to always display expected and actual assertion result?
When in PHPUnit test fails, actual and expected values are displayed.
But when the test passes, this information is not displayed.
How to force PHPUnit to always display expected and actual assertion result?
Since you're most likely calling the assertions with $this->assert...(), you can just overwrite those methods in your test case. Quick example:
class YourTestCase extends PHPUnit_Framework_TestCase { ... static private $messages = array(); ... static public function assertSame($var1, $var2, $message = '') { parent::assertSame($var1, $var2, $message); // assertSame() throws an exception if not true, so the following // won't occur unless the messages actually are the same $success = print_r($var1, true) . ' is the same as ' . print_r($var2, true); self::$messages = array_merge(self::$messages, array($success)); } static public function tearDownAfterClass() { echo implode("\n", self::$messages); } } Of course, tearDownAfterClass() may not be late enough for your liking. It's not the same as an assertion failure would be.
I came to this post looking for something similar. I have this testcase:
/** * test routing logic (numbers method returns an array of numbers and expected outputs to test) * @dataProvider numbers */ function testRoute($input,$expected) { $route = new Route($input,'',false); $route->route(); $this->assertEquals($expected,$route->routingResult); } and my numbers method is this:
/** * read pairs of numbers (input <tab> expected) from tests.input separater by tab * return an array like this: array(array(number1,expected1), array(number2,expected2), ...) * provide this array to my tests by returning it */ function numbers() { $testcases = file('tests.input'); $tests = array(); foreach($testcases as $test_case) { list($input,$output) = explode("\t",$test_case,2); $tests[] = array(trim($input),trim($output)); } return $tests; } What happens is you get an output like this from phpunit:
Starting test 'RouteTest::testRoute with data set #0 ('8596000000', 'rejected (dp not found)x')'. F Starting test 'RouteTest::testRoute with data set #1 ('8596000001', 'rejected (rejected by scheme)')'. . Starting test 'RouteTest::testRoute with data set #2 ('8596000003', '1599000003')'. . It won't tell you the actual result of the tested function unless the test fails but at least you get to see all the asserted values.
Either create your own Assertion class and have it behave like a proxy to the actual assertion class and echoing the values before delegating to the actual assertion, e.g.
$this->assertWithLogging('assertion', $expected, $actual, $message); or override PHPUnit's own class (which I think will be very tricky) or simply do
$this->assertSame($expected, $actual, $message); echo "$expected is $actual"; That's not pretty either, because it will screw up output when running through CLI. If you happen to use Zend Studio, you will see the output in the Debug Output Tab.
Another route would be with TestListeners, but I don't know enough about them to tell you any details. Looks like you can hook into the testing process.
PHPUnit_Assert, but I was hoping for some command line switch to have this feature on demand…