Skip to content

Commit

Permalink
[11.x] Avoid using Laravel new error page if app.debug changes to `…
Browse files Browse the repository at this point in the history
…true` at runtime (#51705)

* [11.x] Avoid using Laravel new renderer if `app.debug` changes to `true`
at runtime

Signed-off-by: Mior Muhammad Zaki <[email protected]>

* wip

Signed-off-by: Mior Muhammad Zaki <[email protected]>

---------

Signed-off-by: Mior Muhammad Zaki <[email protected]>
  • Loading branch information
crynobone authored Jun 4, 2024
1 parent a84c4f4 commit 6adf982
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/Illuminate/Foundation/Exceptions/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down
40 changes: 40 additions & 0 deletions tests/Integration/Foundation/Exceptions/RendererTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace Illuminate\Tests\Integration\Foundation\Exceptions;

use Illuminate\Foundation\Exceptions\Renderer\Renderer;
use Orchestra\Testbench\Attributes\WithConfig;
use Orchestra\Testbench\TestCase;
use RuntimeException;

class RendererTest extends TestCase
{
protected function defineRoutes($router)
{
$router->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!');
}
}

0 comments on commit 6adf982

Please sign in to comment.