diff --git a/src/Application.php b/src/Application.php index 6444aebd..1af00bc6 100644 --- a/src/Application.php +++ b/src/Application.php @@ -130,6 +130,8 @@ public function __construct( * If $out is not provided, uses the result of `getFinalHandler()`. * * @todo Remove logic for creating final handler for version 2.0. + * @todo Remove error handler for deprecation notice due to triggering + * error middleware for version 2.0.0. * @param ServerRequestInterface $request * @param ResponseInterface $response * @param callable|null $out @@ -137,6 +139,10 @@ public function __construct( */ public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $out = null) { + set_error_handler(function ($errno, $errstr) { + return false !== strstr($errstr, 'error middleware is deprecated'); + }, E_USER_DEPRECATED); + if (! $out && (null === ($out = $this->getFinalHandler($response)))) { $response = $response instanceof StratigilityResponse ? $response @@ -144,7 +150,11 @@ public function __invoke(ServerRequestInterface $request, ResponseInterface $res $out = new FinalHandler([], $response); } - return parent::__invoke($request, $response, $out); + $result = parent::__invoke($request, $response, $out); + + restore_error_handler(); + + return $result; } /** diff --git a/test/Container/ApplicationFactoryIntegrationTest.php b/test/Container/ApplicationFactoryIntegrationTest.php index 293031a7..fd05fc60 100644 --- a/test/Container/ApplicationFactoryIntegrationTest.php +++ b/test/Container/ApplicationFactoryIntegrationTest.php @@ -128,14 +128,8 @@ public function testConfiguredErrorMiddlewarePipeIsExecutedWhenMiddlewareCallsNe $request = new ServerRequest([], [], 'http://example.com/needs/authentication', 'GET'); $response = new Response(); - set_error_handler(function ($errno, $errstr) { - return false !== strstr($errstr, 'error middleware is deprecated'); - }, E_USER_DEPRECATED); - $response = $app($request, $response); - restore_error_handler(); - $this->assertInstanceOf(ResponseInterface::class, $response); $this->assertEquals(401, $response->getStatusCode(), 'Unexpected response'); $this->assertTrue($response->hasHeader('X-Always')); @@ -222,14 +216,8 @@ public function testConfiguredErrorMiddlewareIsExecutedWhenMiddlewareCallsNextWi $request = new ServerRequest([], [], 'http://example.com/needs/authentication', 'GET'); $response = new Response(); - set_error_handler(function ($errno, $errstr) { - return false !== strstr($errstr, 'error middleware is deprecated'); - }, E_USER_DEPRECATED); - $response = $app($request, $response); - restore_error_handler(); - $this->assertInstanceOf(ResponseInterface::class, $response); $this->assertEquals(401, $response->getStatusCode(), 'Unexpected response'); $this->assertTrue($response->hasHeader('X-Always'));