-
-
Notifications
You must be signed in to change notification settings - Fork 40
Add option to limit export of (large) arrays (to speed up PHPUnit) #59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
5476a73
071c55d
a028fa5
539209a
0a94d0c
deb644f
96c4edd
4c25986
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -38,6 +38,8 @@ | |
|
|
||
| final readonly class Exporter | ||
| { | ||
| private const MAX_SHORTENED_ITEMS = 10; | ||
|
|
||
| /** | ||
| * Exports a value as a string. | ||
| * | ||
|
|
@@ -69,7 +71,16 @@ public function shortenedRecursiveExport(array &$data, ?RecursionContext $proces | |
| /* @noinspection UnusedFunctionResultInspection */ | ||
| $processed->add($data); | ||
|
|
||
| $i = 0; | ||
| $count = count($data, COUNT_RECURSIVE); | ||
|
staabm marked this conversation as resolved.
Outdated
|
||
|
|
||
| foreach ($array as $key => $value) { | ||
| if ($count > self::MAX_SHORTENED_ITEMS && $i > self::MAX_SHORTENED_ITEMS) { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. since we are in the before this PR running phpunit on a dataprovider with lots of elements resulted in a big wall-of-text description like so I think this is also a DX improvement
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Completely agree and thank you for this PR! |
||
| $result[] = sprintf('...%d more elements', $count - 10); | ||
|
|
||
| break; | ||
| } | ||
|
|
||
| if (is_array($value)) { | ||
| if ($processed->contains($data[$key]) !== false) { | ||
| $result[] = '*RECURSION*'; | ||
|
|
@@ -79,6 +90,8 @@ public function shortenedRecursiveExport(array &$data, ?RecursionContext $proces | |
| } else { | ||
| $result[] = $this->shortenedExport($value); | ||
| } | ||
|
|
||
| $i++; | ||
| } | ||
|
|
||
| return implode(', ', $result); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.