deprecated FlattenException::create()
This commit is contained in:
parent
7dd9dbf28d
commit
f511bc5ff6
@ -35,7 +35,7 @@ class PreviewErrorController
|
|||||||
|
|
||||||
public function previewErrorPageAction(Request $request, $code)
|
public function previewErrorPageAction(Request $request, $code)
|
||||||
{
|
{
|
||||||
$exception = FlattenException::create(new \Exception('Something has intentionally gone wrong.'), $code);
|
$exception = FlattenException::createFromThrowable(new \Exception('Something has intentionally gone wrong.'), $code);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This Request mimics the parameters set by
|
* This Request mimics the parameters set by
|
||||||
|
@ -26,7 +26,7 @@ class ExceptionControllerTest extends TestCase
|
|||||||
|
|
||||||
$request = $this->createRequest('html');
|
$request = $this->createRequest('html');
|
||||||
$request->attributes->set('showException', false);
|
$request->attributes->set('showException', false);
|
||||||
$exception = FlattenException::create(new \Exception(), 404);
|
$exception = FlattenException::createFromThrowable(new \Exception(), 404);
|
||||||
$controller = new ExceptionController($twig, /* "showException" defaults to --> */ true);
|
$controller = new ExceptionController($twig, /* "showException" defaults to --> */ true);
|
||||||
|
|
||||||
$response = $controller->showAction($request, $exception, null);
|
$response = $controller->showAction($request, $exception, null);
|
||||||
@ -40,7 +40,7 @@ class ExceptionControllerTest extends TestCase
|
|||||||
$twig = $this->createTwigEnv(['@Twig/Exception/error.html.twig' => '<html></html>']);
|
$twig = $this->createTwigEnv(['@Twig/Exception/error.html.twig' => '<html></html>']);
|
||||||
|
|
||||||
$request = $this->createRequest('txt');
|
$request = $this->createRequest('txt');
|
||||||
$exception = FlattenException::create(new \Exception());
|
$exception = FlattenException::createFromThrowable(new \Exception());
|
||||||
$controller = new ExceptionController($twig, false);
|
$controller = new ExceptionController($twig, false);
|
||||||
|
|
||||||
$controller->showAction($request, $exception);
|
$controller->showAction($request, $exception);
|
||||||
@ -54,7 +54,7 @@ class ExceptionControllerTest extends TestCase
|
|||||||
|
|
||||||
$request = $this->createRequest('txt');
|
$request = $this->createRequest('txt');
|
||||||
$request->attributes->set('showException', true);
|
$request->attributes->set('showException', true);
|
||||||
$exception = FlattenException::create(new \Exception());
|
$exception = FlattenException::createFromThrowable(new \Exception());
|
||||||
$controller = new ExceptionController($twig, false);
|
$controller = new ExceptionController($twig, false);
|
||||||
|
|
||||||
$controller->showAction($request, $exception);
|
$controller->showAction($request, $exception);
|
||||||
@ -67,7 +67,7 @@ class ExceptionControllerTest extends TestCase
|
|||||||
$twig = $this->createTwigEnv(['@Twig/Exception/error.json.twig' => '{}']);
|
$twig = $this->createTwigEnv(['@Twig/Exception/error.json.twig' => '{}']);
|
||||||
|
|
||||||
$request = $this->createRequest('json');
|
$request = $this->createRequest('json');
|
||||||
$exception = FlattenException::create(new \Exception());
|
$exception = FlattenException::createFromThrowable(new \Exception());
|
||||||
$controller = new ExceptionController($twig, false);
|
$controller = new ExceptionController($twig, false);
|
||||||
|
|
||||||
$response = $controller->showAction($request, $exception);
|
$response = $controller->showAction($request, $exception);
|
||||||
|
@ -20,4 +20,13 @@ use Symfony\Component\ErrorCatcher\Exception\FlattenException as BaseFlattenExce
|
|||||||
*/
|
*/
|
||||||
class FlattenException extends BaseFlattenException
|
class FlattenException extends BaseFlattenException
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @deprecated since Symfony 4.4, use Symfony\Component\ErrorHandler\Exception::createFromThrowable() instead.
|
||||||
|
*/
|
||||||
|
public static function create(\Exception $exception, $statusCode = null, array $headers = []): self
|
||||||
|
{
|
||||||
|
@trigger_error(sprintf('The "%s()" method is deprecated since Symfony 4.4, use Symfony\Component\ErrorHandler\Exception::createFromThrowable() instead.', __METHOD__), E_USER_DEPRECATED);
|
||||||
|
|
||||||
|
return parent::createFromThrowable($exception, $statusCode, $headers);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -49,7 +49,7 @@ class ErrorRenderer
|
|||||||
/**
|
/**
|
||||||
* Renders an Exception and returns the Response content.
|
* Renders an Exception and returns the Response content.
|
||||||
*
|
*
|
||||||
* @param \Exception|FlattenException $exception An \Exception or FlattenException instance
|
* @param \Throwable|FlattenException $exception A \Throwable or FlattenException instance
|
||||||
* @param string $format The request format (html, json, xml, etc.)
|
* @param string $format The request format (html, json, xml, etc.)
|
||||||
*
|
*
|
||||||
* @return string The Response content as a string
|
* @return string The Response content as a string
|
||||||
@ -62,8 +62,8 @@ class ErrorRenderer
|
|||||||
throw new ErrorRendererNotFoundException(sprintf('No error renderer found for format "%s".', $format));
|
throw new ErrorRendererNotFoundException(sprintf('No error renderer found for format "%s".', $format));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($exception instanceof \Exception) {
|
if ($exception instanceof \Throwable) {
|
||||||
$exception = FlattenException::create($exception);
|
$exception = FlattenException::createFromThrowable($exception);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->renderers[$format]->render($exception);
|
return $this->renderers[$format]->render($exception);
|
||||||
|
@ -150,7 +150,7 @@ EOF
|
|||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
// something nasty happened and we cannot throw an exception anymore
|
// something nasty happened and we cannot throw an exception anymore
|
||||||
if ($this->debug) {
|
if ($this->debug) {
|
||||||
$e = FlattenException::create($e);
|
$e = FlattenException::createFromThrowable($e);
|
||||||
$exceptionMessage = sprintf('Exception thrown when handling an exception (%s: %s)', $e->getClass(), $this->escapeHtml($e->getMessage()));
|
$exceptionMessage = sprintf('Exception thrown when handling an exception (%s: %s)', $e->getClass(), $this->escapeHtml($e->getMessage()));
|
||||||
} else {
|
} else {
|
||||||
$exceptionMessage = 'Whoops, looks like something went wrong.';
|
$exceptionMessage = 'Whoops, looks like something went wrong.';
|
||||||
|
@ -36,11 +36,6 @@ class FlattenException
|
|||||||
private $file;
|
private $file;
|
||||||
private $line;
|
private $line;
|
||||||
|
|
||||||
public static function create(\Exception $exception, $statusCode = null, array $headers = [])
|
|
||||||
{
|
|
||||||
return static::createFromThrowable($exception, $statusCode, $headers);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function createFromThrowable(\Throwable $exception, ?int $statusCode = null, array $headers = []): self
|
public static function createFromThrowable(\Throwable $exception, ?int $statusCode = null, array $headers = []): self
|
||||||
{
|
{
|
||||||
$e = new static();
|
$e = new static();
|
||||||
|
@ -156,12 +156,12 @@ class ExceptionHandler
|
|||||||
* This method uses plain PHP functions like header() and echo to output
|
* This method uses plain PHP functions like header() and echo to output
|
||||||
* the response.
|
* the response.
|
||||||
*
|
*
|
||||||
* @param \Exception|FlattenException $exception An \Exception or FlattenException instance
|
* @param \Throwable|FlattenException $exception A \Throwable or FlattenException instance
|
||||||
*/
|
*/
|
||||||
public function sendPhpResponse($exception)
|
public function sendPhpResponse($exception)
|
||||||
{
|
{
|
||||||
if ($exception instanceof \Exception) {
|
if ($exception instanceof \Throwable) {
|
||||||
$exception = FlattenException::create($exception);
|
$exception = FlattenException::createFromThrowable($exception);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!headers_sent()) {
|
if (!headers_sent()) {
|
||||||
|
@ -27,7 +27,7 @@ class ErrorRendererTest extends TestCase
|
|||||||
$container = $this->getMockBuilder('Psr\Container\ContainerInterface')->getMock();
|
$container = $this->getMockBuilder('Psr\Container\ContainerInterface')->getMock();
|
||||||
$container->expects($this->once())->method('has')->with('foo')->willReturn(false);
|
$container->expects($this->once())->method('has')->with('foo')->willReturn(false);
|
||||||
|
|
||||||
$exception = FlattenException::create(new \Exception('Foo'));
|
$exception = FlattenException::createFromThrowable(new \Exception('Foo'));
|
||||||
(new ErrorRenderer($container))->render($exception, 'foo');
|
(new ErrorRenderer($container))->render($exception, 'foo');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -48,7 +48,7 @@ class ErrorRendererTest extends TestCase
|
|||||||
|
|
||||||
$errorRenderer = new ErrorRenderer($container);
|
$errorRenderer = new ErrorRenderer($container);
|
||||||
|
|
||||||
$exception = FlattenException::create(new \RuntimeException('Foo'));
|
$exception = FlattenException::createFromThrowable(new \RuntimeException('Foo'));
|
||||||
$this->assertSame('Foo', $errorRenderer->render($exception, 'foo'));
|
$this->assertSame('Foo', $errorRenderer->render($exception, 'foo'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,7 @@ class ErrorRendererTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testErrorRendererNotFound()
|
public function testErrorRendererNotFound()
|
||||||
{
|
{
|
||||||
$exception = FlattenException::create(new \Exception('foo'));
|
$exception = FlattenException::createFromThrowable(new \Exception('foo'));
|
||||||
(new ErrorRenderer([]))->render($exception, 'foo');
|
(new ErrorRenderer([]))->render($exception, 'foo');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -34,7 +34,7 @@ class ErrorRendererTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testInvalidErrorRenderer()
|
public function testInvalidErrorRenderer()
|
||||||
{
|
{
|
||||||
$exception = FlattenException::create(new \Exception('foo'));
|
$exception = FlattenException::createFromThrowable(new \Exception('foo'));
|
||||||
(new ErrorRenderer([new \stdClass()]))->render($exception, 'foo');
|
(new ErrorRenderer([new \stdClass()]))->render($exception, 'foo');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -43,7 +43,7 @@ class ErrorRendererTest extends TestCase
|
|||||||
$renderers = [new FooErrorRenderer()];
|
$renderers = [new FooErrorRenderer()];
|
||||||
$errorRenderer = new ErrorRenderer($renderers);
|
$errorRenderer = new ErrorRenderer($renderers);
|
||||||
|
|
||||||
$exception = FlattenException::create(new \RuntimeException('Foo'));
|
$exception = FlattenException::createFromThrowable(new \RuntimeException('Foo'));
|
||||||
$this->assertSame('Foo', $errorRenderer->render($exception, 'foo'));
|
$this->assertSame('Foo', $errorRenderer->render($exception, 'foo'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@ class HtmlErrorRendererTest extends TestCase
|
|||||||
{
|
{
|
||||||
public function testRender()
|
public function testRender()
|
||||||
{
|
{
|
||||||
$exception = FlattenException::create(new \RuntimeException('Foo'));
|
$exception = FlattenException::createFromThrowable(new \RuntimeException('Foo'));
|
||||||
$expected = '<!DOCTYPE html>%A<html>%A<head>%A<title>Internal Server Error</title>%A<h1 class="break-long-words exception-message">Foo</h1>%A<abbr title="RuntimeException">RuntimeException</abbr>%A';
|
$expected = '<!DOCTYPE html>%A<html>%A<head>%A<title>Internal Server Error</title>%A<h1 class="break-long-words exception-message">Foo</h1>%A<abbr title="RuntimeException">RuntimeException</abbr>%A';
|
||||||
|
|
||||||
$this->assertStringMatchesFormat($expected, (new HtmlErrorRenderer())->render($exception));
|
$this->assertStringMatchesFormat($expected, (new HtmlErrorRenderer())->render($exception));
|
||||||
|
@ -19,7 +19,7 @@ class JsonErrorRendererTest extends TestCase
|
|||||||
{
|
{
|
||||||
public function testRender()
|
public function testRender()
|
||||||
{
|
{
|
||||||
$exception = FlattenException::create(new \RuntimeException('Foo'));
|
$exception = FlattenException::createFromThrowable(new \RuntimeException('Foo'));
|
||||||
$expected = '{"title":"Internal Server Error","status":500,"detail":"Foo","exceptions":[{"message":"Foo","class":"RuntimeException","trace":';
|
$expected = '{"title":"Internal Server Error","status":500,"detail":"Foo","exceptions":[{"message":"Foo","class":"RuntimeException","trace":';
|
||||||
|
|
||||||
$this->assertStringStartsWith($expected, (new JsonErrorRenderer())->render($exception));
|
$this->assertStringStartsWith($expected, (new JsonErrorRenderer())->render($exception));
|
||||||
|
@ -19,7 +19,7 @@ class TxtErrorRendererTest extends TestCase
|
|||||||
{
|
{
|
||||||
public function testRender()
|
public function testRender()
|
||||||
{
|
{
|
||||||
$exception = FlattenException::create(new \RuntimeException('Foo'));
|
$exception = FlattenException::createFromThrowable(new \RuntimeException('Foo'));
|
||||||
$expected = '[title] Internal Server Error%A[status] 500%A[detail] Foo%A[1] RuntimeException: Foo%A';
|
$expected = '[title] Internal Server Error%A[status] 500%A[detail] Foo%A[1] RuntimeException: Foo%A';
|
||||||
|
|
||||||
$this->assertStringMatchesFormat($expected, (new TxtErrorRenderer())->render($exception));
|
$this->assertStringMatchesFormat($expected, (new TxtErrorRenderer())->render($exception));
|
||||||
|
@ -19,7 +19,7 @@ class XmlErrorRendererTest extends TestCase
|
|||||||
{
|
{
|
||||||
public function testRender()
|
public function testRender()
|
||||||
{
|
{
|
||||||
$exception = FlattenException::create(new \RuntimeException('Foo'));
|
$exception = FlattenException::createFromThrowable(new \RuntimeException('Foo'));
|
||||||
$expected = '<?xml version="1.0" encoding="UTF-8" ?>%A<problem xmlns="urn:ietf:rfc:7807">%A<title>Internal Server Error</title>%A<status>500</status>%A<detail>Foo</detail>%A';
|
$expected = '<?xml version="1.0" encoding="UTF-8" ?>%A<problem xmlns="urn:ietf:rfc:7807">%A<title>Internal Server Error</title>%A<status>500</status>%A<detail>Foo</detail>%A';
|
||||||
|
|
||||||
$this->assertStringMatchesFormat($expected, (new XmlErrorRenderer())->render($exception));
|
$this->assertStringMatchesFormat($expected, (new XmlErrorRenderer())->render($exception));
|
||||||
|
@ -34,10 +34,10 @@ class FlattenExceptionTest extends TestCase
|
|||||||
{
|
{
|
||||||
public function testStatusCode()
|
public function testStatusCode()
|
||||||
{
|
{
|
||||||
$flattened = FlattenException::create(new \RuntimeException(), 403);
|
$flattened = FlattenException::createFromThrowable(new \RuntimeException(), 403);
|
||||||
$this->assertEquals('403', $flattened->getStatusCode());
|
$this->assertEquals('403', $flattened->getStatusCode());
|
||||||
|
|
||||||
$flattened = FlattenException::create(new \RuntimeException());
|
$flattened = FlattenException::createFromThrowable(new \RuntimeException());
|
||||||
$this->assertEquals('500', $flattened->getStatusCode());
|
$this->assertEquals('500', $flattened->getStatusCode());
|
||||||
|
|
||||||
$flattened = FlattenException::createFromThrowable(new \DivisionByZeroError(), 403);
|
$flattened = FlattenException::createFromThrowable(new \DivisionByZeroError(), 403);
|
||||||
@ -46,72 +46,72 @@ class FlattenExceptionTest extends TestCase
|
|||||||
$flattened = FlattenException::createFromThrowable(new \DivisionByZeroError());
|
$flattened = FlattenException::createFromThrowable(new \DivisionByZeroError());
|
||||||
$this->assertEquals('500', $flattened->getStatusCode());
|
$this->assertEquals('500', $flattened->getStatusCode());
|
||||||
|
|
||||||
$flattened = FlattenException::create(new NotFoundHttpException());
|
$flattened = FlattenException::createFromThrowable(new NotFoundHttpException());
|
||||||
$this->assertEquals('404', $flattened->getStatusCode());
|
$this->assertEquals('404', $flattened->getStatusCode());
|
||||||
|
|
||||||
$flattened = FlattenException::create(new UnauthorizedHttpException('Basic realm="My Realm"'));
|
$flattened = FlattenException::createFromThrowable(new UnauthorizedHttpException('Basic realm="My Realm"'));
|
||||||
$this->assertEquals('401', $flattened->getStatusCode());
|
$this->assertEquals('401', $flattened->getStatusCode());
|
||||||
|
|
||||||
$flattened = FlattenException::create(new BadRequestHttpException());
|
$flattened = FlattenException::createFromThrowable(new BadRequestHttpException());
|
||||||
$this->assertEquals('400', $flattened->getStatusCode());
|
$this->assertEquals('400', $flattened->getStatusCode());
|
||||||
|
|
||||||
$flattened = FlattenException::create(new NotAcceptableHttpException());
|
$flattened = FlattenException::createFromThrowable(new NotAcceptableHttpException());
|
||||||
$this->assertEquals('406', $flattened->getStatusCode());
|
$this->assertEquals('406', $flattened->getStatusCode());
|
||||||
|
|
||||||
$flattened = FlattenException::create(new ConflictHttpException());
|
$flattened = FlattenException::createFromThrowable(new ConflictHttpException());
|
||||||
$this->assertEquals('409', $flattened->getStatusCode());
|
$this->assertEquals('409', $flattened->getStatusCode());
|
||||||
|
|
||||||
$flattened = FlattenException::create(new MethodNotAllowedHttpException(['POST']));
|
$flattened = FlattenException::createFromThrowable(new MethodNotAllowedHttpException(['POST']));
|
||||||
$this->assertEquals('405', $flattened->getStatusCode());
|
$this->assertEquals('405', $flattened->getStatusCode());
|
||||||
|
|
||||||
$flattened = FlattenException::create(new AccessDeniedHttpException());
|
$flattened = FlattenException::createFromThrowable(new AccessDeniedHttpException());
|
||||||
$this->assertEquals('403', $flattened->getStatusCode());
|
$this->assertEquals('403', $flattened->getStatusCode());
|
||||||
|
|
||||||
$flattened = FlattenException::create(new GoneHttpException());
|
$flattened = FlattenException::createFromThrowable(new GoneHttpException());
|
||||||
$this->assertEquals('410', $flattened->getStatusCode());
|
$this->assertEquals('410', $flattened->getStatusCode());
|
||||||
|
|
||||||
$flattened = FlattenException::create(new LengthRequiredHttpException());
|
$flattened = FlattenException::createFromThrowable(new LengthRequiredHttpException());
|
||||||
$this->assertEquals('411', $flattened->getStatusCode());
|
$this->assertEquals('411', $flattened->getStatusCode());
|
||||||
|
|
||||||
$flattened = FlattenException::create(new PreconditionFailedHttpException());
|
$flattened = FlattenException::createFromThrowable(new PreconditionFailedHttpException());
|
||||||
$this->assertEquals('412', $flattened->getStatusCode());
|
$this->assertEquals('412', $flattened->getStatusCode());
|
||||||
|
|
||||||
$flattened = FlattenException::create(new PreconditionRequiredHttpException());
|
$flattened = FlattenException::createFromThrowable(new PreconditionRequiredHttpException());
|
||||||
$this->assertEquals('428', $flattened->getStatusCode());
|
$this->assertEquals('428', $flattened->getStatusCode());
|
||||||
|
|
||||||
$flattened = FlattenException::create(new ServiceUnavailableHttpException());
|
$flattened = FlattenException::createFromThrowable(new ServiceUnavailableHttpException());
|
||||||
$this->assertEquals('503', $flattened->getStatusCode());
|
$this->assertEquals('503', $flattened->getStatusCode());
|
||||||
|
|
||||||
$flattened = FlattenException::create(new TooManyRequestsHttpException());
|
$flattened = FlattenException::createFromThrowable(new TooManyRequestsHttpException());
|
||||||
$this->assertEquals('429', $flattened->getStatusCode());
|
$this->assertEquals('429', $flattened->getStatusCode());
|
||||||
|
|
||||||
$flattened = FlattenException::create(new UnsupportedMediaTypeHttpException());
|
$flattened = FlattenException::createFromThrowable(new UnsupportedMediaTypeHttpException());
|
||||||
$this->assertEquals('415', $flattened->getStatusCode());
|
$this->assertEquals('415', $flattened->getStatusCode());
|
||||||
|
|
||||||
if (class_exists(SuspiciousOperationException::class)) {
|
if (class_exists(SuspiciousOperationException::class)) {
|
||||||
$flattened = FlattenException::create(new SuspiciousOperationException());
|
$flattened = FlattenException::createFromThrowable(new SuspiciousOperationException());
|
||||||
$this->assertEquals('400', $flattened->getStatusCode());
|
$this->assertEquals('400', $flattened->getStatusCode());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testHeadersForHttpException()
|
public function testHeadersForHttpException()
|
||||||
{
|
{
|
||||||
$flattened = FlattenException::create(new MethodNotAllowedHttpException(['POST']));
|
$flattened = FlattenException::createFromThrowable(new MethodNotAllowedHttpException(['POST']));
|
||||||
$this->assertEquals(['Allow' => 'POST'], $flattened->getHeaders());
|
$this->assertEquals(['Allow' => 'POST'], $flattened->getHeaders());
|
||||||
|
|
||||||
$flattened = FlattenException::create(new UnauthorizedHttpException('Basic realm="My Realm"'));
|
$flattened = FlattenException::createFromThrowable(new UnauthorizedHttpException('Basic realm="My Realm"'));
|
||||||
$this->assertEquals(['WWW-Authenticate' => 'Basic realm="My Realm"'], $flattened->getHeaders());
|
$this->assertEquals(['WWW-Authenticate' => 'Basic realm="My Realm"'], $flattened->getHeaders());
|
||||||
|
|
||||||
$flattened = FlattenException::create(new ServiceUnavailableHttpException('Fri, 31 Dec 1999 23:59:59 GMT'));
|
$flattened = FlattenException::createFromThrowable(new ServiceUnavailableHttpException('Fri, 31 Dec 1999 23:59:59 GMT'));
|
||||||
$this->assertEquals(['Retry-After' => 'Fri, 31 Dec 1999 23:59:59 GMT'], $flattened->getHeaders());
|
$this->assertEquals(['Retry-After' => 'Fri, 31 Dec 1999 23:59:59 GMT'], $flattened->getHeaders());
|
||||||
|
|
||||||
$flattened = FlattenException::create(new ServiceUnavailableHttpException(120));
|
$flattened = FlattenException::createFromThrowable(new ServiceUnavailableHttpException(120));
|
||||||
$this->assertEquals(['Retry-After' => 120], $flattened->getHeaders());
|
$this->assertEquals(['Retry-After' => 120], $flattened->getHeaders());
|
||||||
|
|
||||||
$flattened = FlattenException::create(new TooManyRequestsHttpException('Fri, 31 Dec 1999 23:59:59 GMT'));
|
$flattened = FlattenException::createFromThrowable(new TooManyRequestsHttpException('Fri, 31 Dec 1999 23:59:59 GMT'));
|
||||||
$this->assertEquals(['Retry-After' => 'Fri, 31 Dec 1999 23:59:59 GMT'], $flattened->getHeaders());
|
$this->assertEquals(['Retry-After' => 'Fri, 31 Dec 1999 23:59:59 GMT'], $flattened->getHeaders());
|
||||||
|
|
||||||
$flattened = FlattenException::create(new TooManyRequestsHttpException(120));
|
$flattened = FlattenException::createFromThrowable(new TooManyRequestsHttpException(120));
|
||||||
$this->assertEquals(['Retry-After' => 120], $flattened->getHeaders());
|
$this->assertEquals(['Retry-After' => 120], $flattened->getHeaders());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -133,7 +133,7 @@ class FlattenExceptionTest extends TestCase
|
|||||||
public function testWrappedThrowable()
|
public function testWrappedThrowable()
|
||||||
{
|
{
|
||||||
$exception = new FatalThrowableError(new \DivisionByZeroError('Ouch', 42));
|
$exception = new FatalThrowableError(new \DivisionByZeroError('Ouch', 42));
|
||||||
$flattened = FlattenException::create($exception);
|
$flattened = FlattenException::createFromThrowable($exception);
|
||||||
|
|
||||||
$this->assertSame('Ouch', $flattened->getMessage(), 'The message is copied from the original error.');
|
$this->assertSame('Ouch', $flattened->getMessage(), 'The message is copied from the original error.');
|
||||||
$this->assertSame(42, $flattened->getCode(), 'The code is copied from the original error.');
|
$this->assertSame(42, $flattened->getCode(), 'The code is copied from the original error.');
|
||||||
@ -169,7 +169,7 @@ class FlattenExceptionTest extends TestCase
|
|||||||
{
|
{
|
||||||
$exception = new \Exception('test', 123, new \ParseError('Oh noes!', 42));
|
$exception = new \Exception('test', 123, new \ParseError('Oh noes!', 42));
|
||||||
|
|
||||||
$flattened = FlattenException::create($exception)->getPrevious();
|
$flattened = FlattenException::createFromThrowable($exception)->getPrevious();
|
||||||
|
|
||||||
$this->assertEquals($flattened->getMessage(), 'Oh noes!', 'The message is copied from the original exception.');
|
$this->assertEquals($flattened->getMessage(), 'Oh noes!', 'The message is copied from the original exception.');
|
||||||
$this->assertEquals($flattened->getCode(), 42, 'The code is copied from the original exception.');
|
$this->assertEquals($flattened->getCode(), 42, 'The code is copied from the original exception.');
|
||||||
@ -223,7 +223,7 @@ class FlattenExceptionTest extends TestCase
|
|||||||
|
|
||||||
$this->assertSame(
|
$this->assertSame(
|
||||||
FlattenException::createFromThrowable($exception)->toArray(),
|
FlattenException::createFromThrowable($exception)->toArray(),
|
||||||
FlattenException::create($exception)->toArray()
|
FlattenException::createFromThrowable($exception)->toArray()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -262,7 +262,7 @@ class FlattenExceptionTest extends TestCase
|
|||||||
NAN,
|
NAN,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$flattened = FlattenException::create($exception);
|
$flattened = FlattenException::createFromThrowable($exception);
|
||||||
$trace = $flattened->getTrace();
|
$trace = $flattened->getTrace();
|
||||||
$args = $trace[1]['args'];
|
$args = $trace[1]['args'];
|
||||||
$array = $args[0][1];
|
$array = $args[0][1];
|
||||||
@ -303,7 +303,7 @@ class FlattenExceptionTest extends TestCase
|
|||||||
$a = ['foo', [2, &$a]];
|
$a = ['foo', [2, &$a]];
|
||||||
$exception = $this->createException($a);
|
$exception = $this->createException($a);
|
||||||
|
|
||||||
$flattened = FlattenException::create($exception);
|
$flattened = FlattenException::createFromThrowable($exception);
|
||||||
$trace = $flattened->getTrace();
|
$trace = $flattened->getTrace();
|
||||||
$this->assertContains('*DEEP NESTED ARRAY*', serialize($trace));
|
$this->assertContains('*DEEP NESTED ARRAY*', serialize($trace));
|
||||||
}
|
}
|
||||||
@ -322,7 +322,7 @@ class FlattenExceptionTest extends TestCase
|
|||||||
$a[21] = 'value1';
|
$a[21] = 'value1';
|
||||||
$exception = $this->createException($a);
|
$exception = $this->createException($a);
|
||||||
|
|
||||||
$flattened = FlattenException::create($exception);
|
$flattened = FlattenException::createFromThrowable($exception);
|
||||||
$trace = $flattened->getTrace();
|
$trace = $flattened->getTrace();
|
||||||
|
|
||||||
$this->assertSame($trace[1]['args'][0], ['array', ['array', '*SKIPPED over 10000 entries*']]);
|
$this->assertSame($trace[1]['args'][0], ['array', ['array', '*SKIPPED over 10000 entries*']]);
|
||||||
@ -335,12 +335,12 @@ class FlattenExceptionTest extends TestCase
|
|||||||
|
|
||||||
public function testAnonymousClass()
|
public function testAnonymousClass()
|
||||||
{
|
{
|
||||||
$flattened = FlattenException::create(new class() extends \RuntimeException {
|
$flattened = FlattenException::createFromThrowable(new class() extends \RuntimeException {
|
||||||
});
|
});
|
||||||
|
|
||||||
$this->assertSame('RuntimeException@anonymous', $flattened->getClass());
|
$this->assertSame('RuntimeException@anonymous', $flattened->getClass());
|
||||||
|
|
||||||
$flattened = FlattenException::create(new \Exception(sprintf('Class "%s" blah.', \get_class(new class() extends \RuntimeException {
|
$flattened = FlattenException::createFromThrowable(new \Exception(sprintf('Class "%s" blah.', \get_class(new class() extends \RuntimeException {
|
||||||
}))));
|
}))));
|
||||||
|
|
||||||
$this->assertSame('Class "RuntimeException@anonymous" blah.', $flattened->getMessage());
|
$this->assertSame('Class "RuntimeException@anonymous" blah.', $flattened->getMessage());
|
||||||
@ -350,7 +350,7 @@ class FlattenExceptionTest extends TestCase
|
|||||||
{
|
{
|
||||||
$exception = new \RuntimeException();
|
$exception = new \RuntimeException();
|
||||||
|
|
||||||
$flattened = FlattenException::create($exception);
|
$flattened = FlattenException::createFromThrowable($exception);
|
||||||
|
|
||||||
$this->assertSame($exception->getTraceAsString(), $flattened->getTraceAsString());
|
$this->assertSame($exception->getTraceAsString(), $flattened->getTraceAsString());
|
||||||
$this->assertSame($exception->__toString(), $flattened->getAsString());
|
$this->assertSame($exception->__toString(), $flattened->getAsString());
|
||||||
@ -364,7 +364,7 @@ class FlattenExceptionTest extends TestCase
|
|||||||
|
|
||||||
$exception = $test('foo123', 1, null, 1.5);
|
$exception = $test('foo123', 1, null, 1.5);
|
||||||
|
|
||||||
$flattened = FlattenException::create($exception);
|
$flattened = FlattenException::createFromThrowable($exception);
|
||||||
|
|
||||||
$this->assertSame($exception->getTraceAsString(), $flattened->getTraceAsString());
|
$this->assertSame($exception->getTraceAsString(), $flattened->getTraceAsString());
|
||||||
$this->assertSame($exception->__toString(), $flattened->getAsString());
|
$this->assertSame($exception->__toString(), $flattened->getAsString());
|
||||||
@ -375,7 +375,7 @@ class FlattenExceptionTest extends TestCase
|
|||||||
$exception = new \LogicException('This is message 1');
|
$exception = new \LogicException('This is message 1');
|
||||||
$exception = new \RuntimeException('This is messsage 2', 500, $exception);
|
$exception = new \RuntimeException('This is messsage 2', 500, $exception);
|
||||||
|
|
||||||
$flattened = FlattenException::create($exception);
|
$flattened = FlattenException::createFromThrowable($exception);
|
||||||
|
|
||||||
$this->assertSame($exception->getTraceAsString(), $flattened->getTraceAsString());
|
$this->assertSame($exception->getTraceAsString(), $flattened->getTraceAsString());
|
||||||
$this->assertSame($exception->__toString(), $flattened->getAsString());
|
$this->assertSame($exception->__toString(), $flattened->getAsString());
|
||||||
|
@ -29,7 +29,7 @@ class ExceptionDataCollector extends DataCollector
|
|||||||
{
|
{
|
||||||
if (null !== $exception) {
|
if (null !== $exception) {
|
||||||
$this->data = [
|
$this->data = [
|
||||||
'exception' => FlattenException::create($exception),
|
'exception' => FlattenException::createFromThrowable($exception),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -42,7 +42,7 @@ class ExceptionListener implements EventSubscriberInterface
|
|||||||
|
|
||||||
public function logKernelException(GetResponseForExceptionEvent $event)
|
public function logKernelException(GetResponseForExceptionEvent $event)
|
||||||
{
|
{
|
||||||
$e = FlattenException::create($event->getException());
|
$e = FlattenException::createFromThrowable($event->getException());
|
||||||
|
|
||||||
$this->logException($event->getException(), sprintf('Uncaught PHP Exception %s: "%s" at %s line %s', $e->getClass(), $e->getMessage(), $e->getFile(), $e->getLine()));
|
$this->logException($event->getException(), sprintf('Uncaught PHP Exception %s: "%s" at %s line %s', $e->getClass(), $e->getMessage(), $e->getFile(), $e->getLine()));
|
||||||
}
|
}
|
||||||
@ -64,7 +64,7 @@ class ExceptionListener implements EventSubscriberInterface
|
|||||||
try {
|
try {
|
||||||
$response = $event->getKernel()->handle($request, HttpKernelInterface::SUB_REQUEST, false);
|
$response = $event->getKernel()->handle($request, HttpKernelInterface::SUB_REQUEST, false);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
$f = FlattenException::create($e);
|
$f = FlattenException::createFromThrowable($e);
|
||||||
|
|
||||||
$this->logException($e, sprintf('Exception thrown when handling an exception (%s: %s at %s line %s)', $f->getClass(), $f->getMessage(), $e->getFile(), $e->getLine()));
|
$this->logException($e, sprintf('Exception thrown when handling an exception (%s: %s at %s line %s)', $f->getClass(), $f->getMessage(), $e->getFile(), $e->getLine()));
|
||||||
|
|
||||||
@ -132,7 +132,7 @@ class ExceptionListener implements EventSubscriberInterface
|
|||||||
{
|
{
|
||||||
$attributes = [
|
$attributes = [
|
||||||
'_controller' => $this->controller,
|
'_controller' => $this->controller,
|
||||||
'exception' => FlattenException::create($exception),
|
'exception' => FlattenException::createFromThrowable($exception),
|
||||||
'logger' => $this->logger instanceof DebugLoggerInterface ? $this->logger : null,
|
'logger' => $this->logger instanceof DebugLoggerInterface ? $this->logger : null,
|
||||||
];
|
];
|
||||||
$request = $request->duplicate(null, null, $attributes);
|
$request = $request->duplicate(null, null, $attributes);
|
||||||
|
@ -23,7 +23,7 @@ class ExceptionDataCollectorTest extends TestCase
|
|||||||
{
|
{
|
||||||
$e = new \Exception('foo', 500);
|
$e = new \Exception('foo', 500);
|
||||||
$c = new ExceptionDataCollector();
|
$c = new ExceptionDataCollector();
|
||||||
$flattened = FlattenException::create($e);
|
$flattened = FlattenException::createFromThrowable($e);
|
||||||
$trace = $flattened->getTrace();
|
$trace = $flattened->getTrace();
|
||||||
|
|
||||||
$this->assertFalse($c->hasException());
|
$this->assertFalse($c->hasException());
|
||||||
|
Reference in New Issue
Block a user