bug #13004 add a limit and a test to FlattenExceptionTest. (Daniel Wehner)
This PR was submitted for the master branch but it was merged into the 2.3 branch instead (closes #13004).
Discussion
----------
add a limit and a test to FlattenExceptionTest.
| Q | A
| ------------- | ---
| Bug fix? | yes
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | #13003
| License | MIT
| Doc PR |
Commits
-------
c6bcf05
add a limit and a test to FlattenExceptionTest.
This commit is contained in:
commit
ba9266f3f2
@ -239,17 +239,20 @@ class FlattenException
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function flattenArgs($args, $level = 0)
|
private function flattenArgs($args, $level = 0, &$count = 0)
|
||||||
{
|
{
|
||||||
$result = array();
|
$result = array();
|
||||||
foreach ($args as $key => $value) {
|
foreach ($args as $key => $value) {
|
||||||
|
if (++$count > 1e4) {
|
||||||
|
return array('array', '*SKIPPED over 10000 entries*');
|
||||||
|
}
|
||||||
if (is_object($value)) {
|
if (is_object($value)) {
|
||||||
$result[$key] = array('object', get_class($value));
|
$result[$key] = array('object', get_class($value));
|
||||||
} elseif (is_array($value)) {
|
} elseif (is_array($value)) {
|
||||||
if ($level > 10) {
|
if ($level > 10) {
|
||||||
$result[$key] = array('array', '*DEEP NESTED ARRAY*');
|
$result[$key] = array('array', '*DEEP NESTED ARRAY*');
|
||||||
} else {
|
} else {
|
||||||
$result[$key] = array('array', $this->flattenArgs($value, $level + 1));
|
$result[$key] = array('array', $this->flattenArgs($value, $level + 1, $count));
|
||||||
}
|
}
|
||||||
} elseif (null === $value) {
|
} elseif (null === $value) {
|
||||||
$result[$key] = array('null', null);
|
$result[$key] = array('null', null);
|
||||||
|
@ -186,6 +186,28 @@ class FlattenExceptionTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertContains('*DEEP NESTED ARRAY*', serialize($trace));
|
$this->assertContains('*DEEP NESTED ARRAY*', serialize($trace));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testTooBigArray()
|
||||||
|
{
|
||||||
|
$a = array();
|
||||||
|
for ($i = 0; $i < 20; $i++) {
|
||||||
|
for ($j = 0; $j < 50; $j++) {
|
||||||
|
for ($k = 0; $k < 10; $k++) {
|
||||||
|
$a[$i][$j][$k] = 'value';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$a[20] = 'value';
|
||||||
|
$a[21] = 'value1';
|
||||||
|
$exception = $this->createException($a);
|
||||||
|
|
||||||
|
$flattened = FlattenException::create($exception);
|
||||||
|
$trace = $flattened->getTrace();
|
||||||
|
$serialize_trace = serialize($trace);
|
||||||
|
|
||||||
|
$this->assertContains('*SKIPPED over 10000 entries*', $serialize_trace);
|
||||||
|
$this->assertNotContains('*value1*', $serialize_trace);
|
||||||
|
}
|
||||||
|
|
||||||
private function createException($foo)
|
private function createException($foo)
|
||||||
{
|
{
|
||||||
return new \Exception();
|
return new \Exception();
|
||||||
|
Reference in New Issue
Block a user