diff --git a/src/Illuminate/Foundation/Exceptions/Handler.php b/src/Illuminate/Foundation/Exceptions/Handler.php index 0dd49e7f9e1e..057d7af429d6 100644 --- a/src/Illuminate/Foundation/Exceptions/Handler.php +++ b/src/Illuminate/Foundation/Exceptions/Handler.php @@ -833,9 +833,11 @@ protected function renderExceptionContent(Throwable $e) { try { if (config('app.debug')) { - return app()->has(ExceptionRenderer::class) - ? $this->renderExceptionWithCustomRenderer($e) - : $this->container->make(Renderer::class)->render(request(), $e); + if (app()->has(ExceptionRenderer::class)) { + return $this->renderExceptionWithCustomRenderer($e); + } elseif ($this->container->bound(Renderer::class)) { + return $this->container->make(Renderer::class)->render(request(), $e); + } } return $this->renderExceptionWithSymfony($e, config('app.debug')); diff --git a/tests/Integration/Foundation/Exceptions/RendererTest.php b/tests/Integration/Foundation/Exceptions/RendererTest.php new file mode 100644 index 000000000000..0b63869eb83f --- /dev/null +++ b/tests/Integration/Foundation/Exceptions/RendererTest.php @@ -0,0 +1,40 @@ +get('failed', fn () => throw new RuntimeException('Bad route!')); + } + + #[WithConfig('app.debug', true)] + public function testItCanRenderExceptionPage() + { + $this->assertTrue($this->app->bound(Renderer::class)); + + $this->get('/failed') + ->assertInternalServerError() + ->assertSee('RuntimeException') + ->assertSee('Bad route!'); + } + + #[WithConfig('app.debug', false)] + public function testItCanRenderExceptionPageUsingSymfonyIfRendererIsNotDefined() + { + config(['app.debug' => true]); + + $this->assertFalse($this->app->bound(Renderer::class)); + + $this->get('/failed') + ->assertInternalServerError() + ->assertSee('RuntimeException') + ->assertSee('Bad route!'); + } +}