From 7a16376d5fbee27857cca90f7fe604add943a9dd Mon Sep 17 00:00:00 2001 From: Anthony Date: Wed, 7 Mar 2018 21:06:33 +0100 Subject: [PATCH] Allow flatten throwable --- .../Component/Debug/Exception/FlattenException.php | 4 ++-- .../Debug/Tests/Exception/FlattenExceptionTest.php | 12 +++++++++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Component/Debug/Exception/FlattenException.php b/src/Symfony/Component/Debug/Exception/FlattenException.php index aa6e47333b01c..99fe17754a7d1 100644 --- a/src/Symfony/Component/Debug/Exception/FlattenException.php +++ b/src/Symfony/Component/Debug/Exception/FlattenException.php @@ -33,7 +33,7 @@ class FlattenException private $file; private $line; - public static function create(\Exception $exception, $statusCode = null, array $headers = array()) + public static function create(\Throwable $exception, $statusCode = null, array $headers = array()) { $e = new static(); $e->setMessage($exception->getMessage()); @@ -178,7 +178,7 @@ public function getTrace() return $this->trace; } - public function setTraceFromException(\Exception $exception) + public function setTraceFromException(\Throwable $exception) { $this->setTrace($exception->getTrace(), $exception->getFile(), $exception->getLine()); } diff --git a/src/Symfony/Component/Debug/Tests/Exception/FlattenExceptionTest.php b/src/Symfony/Component/Debug/Tests/Exception/FlattenExceptionTest.php index 6c9b7f21386b6..a264024a37806 100644 --- a/src/Symfony/Component/Debug/Tests/Exception/FlattenExceptionTest.php +++ b/src/Symfony/Component/Debug/Tests/Exception/FlattenExceptionTest.php @@ -126,7 +126,7 @@ public function testFlattenHttpException(\Exception $exception) public function testThrowable() { - $exception = new FatalThrowableError(new \DivisionByZeroError('Ouch', 42)); + $exception = new \DivisionByZeroError('Ouch', 42); $flattened = FlattenException::create($exception); $this->assertSame('Ouch', $flattened->getMessage(), 'The message is copied from the original error.'); @@ -134,6 +134,16 @@ public function testThrowable() $this->assertSame('DivisionByZeroError', $flattened->getClass(), 'The class is set to the class of the original error'); } + public function testFatalThrowableError() + { + $exception = new FatalThrowableError(new \DivisionByZeroError('Ouch', 11)); + $flattened = FlattenException::create($exception); + + $this->assertSame('Ouch', $flattened->getMessage(), 'The message is copied from the original error.'); + $this->assertSame(11, $flattened->getCode(), 'The code is copied from the original error.'); + $this->assertSame('DivisionByZeroError', $flattened->getClass(), 'The class is set to the class of the original error'); + } + /** * @dataProvider flattenDataProvider */