Handle recursive and repeated arrays more gracefully when exporting - #773
Merged
sebastianbergmann merged 12 commits intoJan 8, 2013
Merged
Conversation
…ursive data structures more gracefully (and with less memory usage).
…handles undeclared properties correctly.
…here. Specifically, we don't want to move to a newline for the leading line of exported arrays and objects, and we don't want a newline before the opening parenthesis.
recursiveExport().
sebastianbergmann
added a commit
that referenced
this pull request
Jan 8, 2013
Owner
|
Thanks! I do get the following failure on my machine: Any idea? |
Contributor
Author
|
I can't reproduce it locally. What version of PHP are you running? |
Owner
|
falkenhawk
added a commit
to zf1s/phpunit
that referenced
this pull request
May 8, 2019
- to avoid looping/memory leaks/segfaults on PHP 7.x - Alter PHPUnit_Util_Type::recursiveExport() to handle repeated and recursive data structures more gracefully (and with less memory usage).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR largely replaces
PHPUnit_Util_Type::recursiveExport()with a more robust implementation that doesn't rely onprint_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 fromspl_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.