diff --git a/src/Symfony/Component/ErrorHandler/Exception/FlattenException.php b/src/Symfony/Component/ErrorHandler/Exception/FlattenException.php index 07c3d49db05d..900cbaad0a29 100644 --- a/src/Symfony/Component/ErrorHandler/Exception/FlattenException.php +++ b/src/Symfony/Component/ErrorHandler/Exception/FlattenException.php @@ -206,7 +206,7 @@ public function setMessage($message): self return $this; } - public function getCode(): int + public function getCode() { return $this->code; } diff --git a/src/Symfony/Component/ErrorHandler/Tests/Exception/FlattenExceptionTest.php b/src/Symfony/Component/ErrorHandler/Tests/Exception/FlattenExceptionTest.php index 66212a81ad84..437d211f7159 100644 --- a/src/Symfony/Component/ErrorHandler/Tests/Exception/FlattenExceptionTest.php +++ b/src/Symfony/Component/ErrorHandler/Tests/Exception/FlattenExceptionTest.php @@ -14,6 +14,7 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\Debug\Exception\FatalThrowableError; use Symfony\Component\ErrorHandler\Exception\FlattenException; +use Symfony\Component\ErrorHandler\Tests\Fixtures\StringErrorCodeException; use Symfony\Component\HttpFoundation\Exception\SuspiciousOperationException; use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; @@ -197,6 +198,15 @@ public function testFile(\Throwable $exception) $this->assertSame($exception->getFile(), $flattened->getFile()); } + /** + * @dataProvider stringAndIntDataProvider + */ + public function testCode(\Throwable $exception) + { + $flattened = FlattenException::createFromThrowable($exception); + $this->assertSame($exception->getCode(), $flattened->getCode()); + } + /** * @dataProvider flattenDataProvider */ @@ -238,6 +248,14 @@ public function flattenDataProvider(): array ]; } + public function stringAndIntDataProvider(): array + { + return [ + [new \Exception('test1', 123)], + [new StringErrorCodeException('test2', '42S02')], + ]; + } + public function testArguments() { if (\PHP_VERSION_ID >= 70400) { diff --git a/src/Symfony/Component/ErrorHandler/Tests/Fixtures/StringErrorCodeException.php b/src/Symfony/Component/ErrorHandler/Tests/Fixtures/StringErrorCodeException.php new file mode 100644 index 000000000000..d4cbc02abe9b --- /dev/null +++ b/src/Symfony/Component/ErrorHandler/Tests/Fixtures/StringErrorCodeException.php @@ -0,0 +1,13 @@ +code = $code; + } + +}