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:
Fabien Potencier 2014-12-17 22:36:26 +01:00
commit ba9266f3f2
2 changed files with 27 additions and 2 deletions

View File

@ -239,17 +239,20 @@ class FlattenException
}
}
private function flattenArgs($args, $level = 0)
private function flattenArgs($args, $level = 0, &$count = 0)
{
$result = array();
foreach ($args as $key => $value) {
if (++$count > 1e4) {
return array('array', '*SKIPPED over 10000 entries*');
}
if (is_object($value)) {
$result[$key] = array('object', get_class($value));
} elseif (is_array($value)) {
if ($level > 10) {
$result[$key] = array('array', '*DEEP NESTED ARRAY*');
} else {
$result[$key] = array('array', $this->flattenArgs($value, $level + 1));
$result[$key] = array('array', $this->flattenArgs($value, $level + 1, $count));
}
} elseif (null === $value) {
$result[$key] = array('null', null);

View File

@ -186,6 +186,28 @@ class FlattenExceptionTest extends \PHPUnit_Framework_TestCase
$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)
{
return new \Exception();