From ab903d259e207f0990cb71cde3fb4949a67774ae Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Tue, 4 Jun 2024 15:42:24 +0800 Subject: [PATCH 1/2] [11.x] Avoid using Laravel new renderer if `app.debug` changes to `true` at runtime Signed-off-by: Mior Muhammad Zaki --- .../Foundation/Exceptions/Handler.php | 8 ++-- .../Foundation/Exceptions/RendererTest.php | 39 +++++++++++++++++++ 2 files changed, 44 insertions(+), 3 deletions(-) create mode 100644 tests/Integration/Foundation/Exceptions/RendererTest.php 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..7bef5ae55ce7 --- /dev/null +++ b/tests/Integration/Foundation/Exceptions/RendererTest.php @@ -0,0 +1,39 @@ +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!'); + } + + public function testItCanRenderExceptionPageUsingSymfonyIfRendererIsNotDefined() + { + config(['app.debug' => true]); + + $this->assertFalse($this->app->bound(Renderer::class)); + + $this->get('/failed') + ->assertInternalServerError() + ->assertSee('RuntimeException') + ->assertSee('Bad route!'); + } +} From fcf1531484a6de6f524f6749116a70444a4893c4 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Tue, 4 Jun 2024 15:48:20 +0800 Subject: [PATCH 2/2] wip Signed-off-by: Mior Muhammad Zaki --- tests/Integration/Foundation/Exceptions/RendererTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/Integration/Foundation/Exceptions/RendererTest.php b/tests/Integration/Foundation/Exceptions/RendererTest.php index 7bef5ae55ce7..0b63869eb83f 100644 --- a/tests/Integration/Foundation/Exceptions/RendererTest.php +++ b/tests/Integration/Foundation/Exceptions/RendererTest.php @@ -25,6 +25,7 @@ public function testItCanRenderExceptionPage() ->assertSee('Bad route!'); } + #[WithConfig('app.debug', false)] public function testItCanRenderExceptionPageUsingSymfonyIfRendererIsNotDefined() { config(['app.debug' => true]);