如何让PHPUnit打印失败的测试用例的完整输入?

jam*_*her 9 php phpunit

PHPUnit似乎通过序列化预期值和实际值来打印失败的测试用例,并显示它们之间的差异.此外,序列化使用省略号截断值,隐藏我想要的信息.

这是PHPUnit生成的输出示例:

/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 (...)
 )
Run Code Online (Sandbox Code Playgroud)

我希望看到完整的预期值和完整的实际值.我也希望它扩展那些...被忽略的价值观.我怎么做到这一点?

Dwa*_*ell 5

通过传递附加参数,您可以在断言失败时打印任何所需内容.

$this->assertEquals($a,$b,print_r($a,true)." does not equal ".print_r($b,true));
Run Code Online (Sandbox Code Playgroud)


pun*_*eel 3

根据这个问题: https: //github.com/sebastianbergmann/phpunit/issues/669,它看起来像是一个 XDebug 问题。

在源代码中, isEquals 重定向到此:https://github.com/sebastianbergmann/phpunit/blob/58f3a0e212a8df66858f22fc9a58f138bb5a2e9d/src/Util/GlobalState.php#L361,并且没有任何形式的“缩短”

您可以使用php -d xdebug.overload_var_dump=0 /usr/bin/phpunit testCase.phpphpunit -d xdebug.overload_var_dump=0 testCase.php覆盖 xdebug 设置进行测试