sebastianbergmann/phpunit — pull request #773 by LawnGnome (2013-01-08 08:36:41+00:00)
Title: Handle recursive and repeated arrays more gracefully when exporting

This PR largely replaces `PHPUnit_Util_Type::recursiveExport()` with a more robust implementation that doesn't rely on `print_r()` to detect array recursion.

Test suites that have heavily nested arrays don't seem to have recursion picked up completely reliably — this seems to particularly manifest itself when dealing with codebases that use Symfony 2 and Doctrine ORM, where the proxied entity objects often include recursed and repeated arrays. As a result, when an assertion fails and the data structure has to be exported, PHP typically runs out of memory while looping infinitely. (For example, my memory_limit is set to 8G. At the risk of invoking Bill Gates, that should be enough for anyone.)

This implementation uses a completely userland approach to detect array recursion, and keeps the list of previously seen arrays and objects in a new context object (which also uses SplObjectStorage for more efficient storage of the seen object set).

The output format of `recursiveExport()` has changed in this PR: arrays now include a numeric ID, and objects now include a hexadecimal hash from `spl_object_hash()`. The initial reference to an array or object will dump the entire array or object as it does now, while subsequent references will simply show the ID/hash.