Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get PHPUnit to print the full input to a failed test case?

Tags:

php

phpunit

PHPUnit appears to print failed test cases by serializing the expected and actual values, and showing a diff between them. Also, the serialization truncates values with ellipses, hiding information that I want.

Here's an example of the output that PHPUnit produces:

/Foo/Bar/Baz.php:31

8) Foo\Bar\Baz::test with data set #7 ('foo,bar,baz,qux', array(array('foo', 'bar'), array('baz', 'qux')))
Failed asserting that two arrays are equal.
--- Expected
+++ Actual
@@ @@
 Array (
-    0 => Array (...)
-    1 => Array (...)
+    'j' => 16
+    'args' => Array (...)
 )

I want to see the full expected value, and the full actual value. I also want it to expand those ... elided values. How do I get it to do that?

like image 660
jameshfisher Avatar asked Jan 29 '14 15:01

jameshfisher


2 Answers

You can print whatever you want when an assertion fails by passing an additional parameter.

$this->assertEquals($a,$b,print_r($a,true)." does not equal ".print_r($b,true));
like image 54
Dwayne Towell Avatar answered Oct 18 '22 01:10

Dwayne Towell


According to this issue: https://github.com/sebastianbergmann/phpunit/issues/669, it looks like to be an XDebug issue.

In the source code, isEquals redirects to this: https://github.com/sebastianbergmann/phpunit/blob/58f3a0e212a8df66858f22fc9a58f138bb5a2e9d/src/Util/GlobalState.php#L361, and there is no form of "shortening"

You can test using php -d xdebug.overload_var_dump=0 /usr/bin/phpunit testCase.php or phpunit -d xdebug.overload_var_dump=0 testCase.php to overwrite xdebug settings

like image 42
punkeel Avatar answered Oct 17 '22 23:10

punkeel