PHPUnit: force display of asserted values
php, phpunit, unit-testing
Solution
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.
Problem
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?