public function testCollect() { $e = new \Exception('foo', 500); $c = new ExceptionDataCollector(); $flattened = FlattenException::create($e); $trace = $flattened->getTrace(); $this->assertFalse($c->hasException()); $c->collect(new Request(), new Response(), $e); $this->assertTrue($c->hasException()); $this->assertEquals($flattened, $c->getException()); $this->assertSame('foo', $c->getMessage()); $this->assertSame(500, $c->getCode()); $this->assertSame('exception', $c->getName()); $this->assertSame($trace, $c->getTrace()); }
private function getExceptionData(ExceptionDataCollector $collector) { $exception = $collector->getException(); if (!$exception instanceof FlattenException) { $exception = FlattenException::create($exception); } $data = $exception->toArray(); foreach ($data as $nb => $exData) { // skip non-public exceptions $class = new \ReflectionClass($exData['class']); if ($class->isUserDefined() && !$this->isNamespaceWhitelisted($exData['class'])) { unset($data[$nb]); continue; } // skip built-in exceptions that are thrown from a non-public class if (!$class->isUserDefined() && (!isset($exData['trace'][1]) || !$this->isNamespaceWhitelisted($exData['trace'][1]['class']))) { unset($data[$nb]); continue; } foreach ($exData['trace'] as $key => $trace) { unset($data[$nb]['trace'][$key]['namespace'], $data[$nb]['trace'][$key]['short_class']); if ('' === $trace['class']) { $public = isset($exData['trace'][$key + 1]) && $this->isNamespaceWhitelisted($exData['trace'][$key + 1]['class']); } else { $public = $this->isNamespaceWhitelisted($trace['class']); } if (!$public) { foreach ($trace as $k => $v) { if (is_array($v)) { $data[$nb]['trace'][$key][$k] = array(); } else { if (is_string($v)) { if ('' !== $v) { $data[$nb]['trace'][$key][$k] = 'XXX'; } } else { $data[$nb]['trace'][$key][$k] = 'XXX'; } } } continue; } // additional heuristics for config data handling if ('Symfony\\Component\\DependencyInjection\\Loader\\YamlFileLoader' === $trace['class'] && 'parseImports' === $trace['function']) { $trace['args'] = array(array('array', array()), array('string', basename($trace['args'][1][1]))); } if ('Symfony\\Component\\Yaml\\Parser' === $trace['class'] && 'parse' === $trace['function']) { $trace['args'] = array(array('string', 'XXX')); } $data[$nb]['trace'][$key]['file'] = basename($trace['file']); $data[$nb]['trace'][$key]['args'] = $this->purgeArgsRecursive($trace['args']); } } return array_values($data); }