In PHPUnit, there are times when an assertion fails, and when reporting the assertion, PHPUnit automatically calls var_export() on the variable. Let's say you called this chunk of code:
$foo = new StdClass();
$foo->bar = 123;
$foo->baz = "Hi there";
$this->assertTrue($foo);
The output of that is:
Failed asserting that
stdClass Object
(
[bar] => 123
[baz] => Hi there
)
is true.
If the variable is an Exception object, this can cause the unit test to print out megabytes of text when walking the object tree, including the stack traces and other info. Sometimes PHPUnit dies 'cause it runs out of memory trying to output it all.
I know one solution is to add an additional test, checking if the variable is an object before doing the assertTrue, or an assertEquals. But my team currently has a LOT of unit tests.
So I was wondering if there's a way to override PHPUnit's default behavior of calling var_export on a variable when generating the error report.
Thanks in advance.
$this->assertTrue($foo === true)... - ircmaxell