From 985fcedb042447fa5e255e46ebc95ddedb943f32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Munsch?= Date: Thu, 13 Aug 2026 12:18:22 +0200 Subject: [PATCH] test(WebExceptionRenderer): add tests for rendering exceptions Add tests to verify the behavior of WebExceptionRenderer for NotFoundException and unhandled exceptions. --- .../Web/WebExceptionRendererTest.php | 60 +++++++++++++++++++ tests/Pest.php | 4 ++ 2 files changed, 64 insertions(+) create mode 100644 tests/Integration/Presentation/Web/WebExceptionRendererTest.php diff --git a/tests/Integration/Presentation/Web/WebExceptionRendererTest.php b/tests/Integration/Presentation/Web/WebExceptionRendererTest.php new file mode 100644 index 0000000..71a49bf --- /dev/null +++ b/tests/Integration/Presentation/Web/WebExceptionRendererTest.php @@ -0,0 +1,60 @@ +render($exception, $request); + + // THEN + expect($response)->not->toBeNull() + ->and($response?->getStatusCode())->toBe(404); + }); + + it('returns null for API or JSON requests', function (): void { + // GIVEN + $renderer = new WebExceptionRenderer(); + $exception = new NotFoundException('Resource not found'); + $request = Request::create( + '/api/v1/employees', + 'GET', + [], + [], + [], + ['HTTP_ACCEPT' => 'application/json'] + ); + + // WHEN + $response = $renderer->render($exception, $request); + + // THEN + expect($response)->toBeNull(); + }); + + it('returns null for unhandled exceptions', function (): void { + // GIVEN + $renderer = new WebExceptionRenderer(); + $exception = new \InvalidArgumentException('Invalid argument'); + $request = Request::create('/some-web-page', 'GET'); + + // WHEN + $response = $renderer->render($exception, $request); + + // THEN + expect($response)->toBeNull(); + }); +}); diff --git a/tests/Pest.php b/tests/Pest.php index b982987..21a2b46 100644 --- a/tests/Pest.php +++ b/tests/Pest.php @@ -29,6 +29,10 @@ pest() ->use(RefreshDatabase::class) ->in('Integration/WithApp'); +pest() + ->extend(LaravelTestCase::class) + ->in('Integration/Presentation'); + pest() ->extend(BasePHPUnitTestCase::class) ->in('Integration/Standalones');