diff --git a/src/Application/Application.php b/src/Application/Application.php index dc7c4154d..1d535c25b 100644 --- a/src/Application/Application.php +++ b/src/Application/Application.php @@ -182,7 +182,7 @@ public function processException(\Throwable $e): void $this->httpResponse->setCode($e instanceof BadRequestException ? ($e->getHttpCode() ?: 404) : 500); } - $args = ['exception' => $e, 'request' => Arrays::last($this->requests) ?: null]; + $args = ['exception' => $e, 'previousPresenter' => $this->presenter, 'request' => Arrays::last($this->requests) ?: null]; if ($this->presenter instanceof UI\Presenter) { try { $this->presenter->forward(":$this->errorPresenter:", $args); diff --git a/tests/Application/Application.run.phpt b/tests/Application/Application.run.phpt index 3b7c84382..db09a24ec 100644 --- a/tests/Application/Application.run.phpt +++ b/tests/Application/Application.run.phpt @@ -127,6 +127,7 @@ test('no route with error presenter', function () use ($httpRequest, $httpRespon Assert::equal($requests[0], $errorPresenter->request); Assert::null($errorPresenter->request->getParameter('request')); + Assert::null($errorPresenter->request->getParameter('previousPresenter')); Assert::type(BadRequestException::class, $errorPresenter->request->getParameter('exception')); }); @@ -154,6 +155,7 @@ test('route to error presenter', function () use ($httpRequest, $httpResponse) { Assert::equal($requests[1], $errorPresenter->request); Assert::equal($requests[0], $errorPresenter->request->getParameter('request')); + Assert::null($errorPresenter->request->getParameter('previousPresenter')); Assert::type(BadRequestException::class, $errorPresenter->request->getParameter('exception')); }); @@ -195,6 +197,7 @@ test('missing presenter with error presenter', function () use ($httpRequest, $h Assert::equal($requests[1], $errorPresenter->request); Assert::equal($requests[0], $errorPresenter->request->getParameter('request')); + Assert::null($errorPresenter->request->getParameter('previousPresenter')); Assert::type(BadRequestException::class, $errorPresenter->request->getParameter('exception')); }); @@ -213,10 +216,11 @@ Assert::exception(function () use ($httpRequest, $httpResponse) { test('presenter error with error presenter', function () use ($httpRequest, $httpResponse) { + $badPresenter = new BadPresenter; $errorPresenter = new ErrorPresenter; $presenterFactory = Mockery::mock(IPresenterFactory::class); - $presenterFactory->shouldReceive('createPresenter')->with('Bad')->andReturn(new BadPresenter); + $presenterFactory->shouldReceive('createPresenter')->with('Bad')->andReturn($badPresenter); $presenterFactory->shouldReceive('createPresenter')->with('Error')->andReturn($errorPresenter); $router = Mockery::mock(Router::class); @@ -236,6 +240,7 @@ test('presenter error with error presenter', function () use ($httpRequest, $htt Assert::equal($requests[1], $errorPresenter->request); Assert::equal($requests[0], $errorPresenter->request->getParameter('request')); + Assert::equal($badPresenter, $errorPresenter->request->getParameter('previousPresenter')); Assert::type(BadException::class, $errorPresenter->request->getParameter('exception')); });