From 948675b0a8b3f28421856301a06bf523de127c72 Mon Sep 17 00:00:00 2001 From: Alice Williams <25745335+AliceKLWilliams@users.noreply.github.com> Date: Wed, 20 Mar 2024 11:01:29 +0000 Subject: [PATCH 01/10] Replace deprecated Symfony error handler --- src/Exceptions/Handler.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Exceptions/Handler.php b/src/Exceptions/Handler.php index 045b6f1..24c9420 100644 --- a/src/Exceptions/Handler.php +++ b/src/Exceptions/Handler.php @@ -7,7 +7,7 @@ use Psr\Http\Message\ServerRequestInterface; use Rareloop\Lumberjack\Application; use Rareloop\Lumberjack\Facades\Config; -use Symfony\Component\Debug\ExceptionHandler as SymfonyExceptionHandler; +use Symfony\Component\ErrorHandler\ErrorHandler as SymfonyExceptionHandler; use Symfony\Component\Debug\Exception\FlattenException; use Zend\Diactoros\Response\HtmlResponse; From 7392ef002d95da3c07c1052a54a9fcc0b8f5fba3 Mon Sep 17 00:00:00 2001 From: Alice Williams <25745335+AliceKLWilliams@users.noreply.github.com> Date: Wed, 20 Mar 2024 11:26:36 +0000 Subject: [PATCH 02/10] Replace symfony/debug with symfony/error-handler --- composer.json | 4 ++-- src/Bootstrappers/RegisterExceptionHandler.php | 10 ++++------ src/Exceptions/Handler.php | 4 ++-- .../Bootstrappers/RegisterExceptionHandlerTest.php | 1 - 4 files changed, 8 insertions(+), 11 deletions(-) diff --git a/composer.json b/composer.json index dddbdb5..7ae75ec 100644 --- a/composer.json +++ b/composer.json @@ -13,7 +13,6 @@ "timber/timber": "^1.24.0", "monolog/monolog": "^2.9.1", "http-interop/response-sender": "^1.0", - "symfony/debug": "^4.4.44", "illuminate/collections": "^8.53.1||^9.52.16", "statamic/stringy": "^3.1.3", "laminas/laminas-diactoros": "^2.25.2", @@ -23,7 +22,8 @@ "mindplay/middleman": "^3.1.0", "psr/log": "^1.1.4", "laminas/laminas-zendframework-bridge": "^1.7", - "symfony/var-dumper": "^5.0||^6.3.6" + "symfony/var-dumper": "^5.0||^6.3.6", + "symfony/error-handler": "^7.0" }, "require-dev": { "phpunit/phpunit": "^9.6.13", diff --git a/src/Bootstrappers/RegisterExceptionHandler.php b/src/Bootstrappers/RegisterExceptionHandler.php index b4ff838..a5d1f53 100644 --- a/src/Bootstrappers/RegisterExceptionHandler.php +++ b/src/Bootstrappers/RegisterExceptionHandler.php @@ -9,7 +9,7 @@ use Rareloop\Lumberjack\Application; use Rareloop\Lumberjack\Exceptions\HandlerInterface; use Rareloop\Router\Responsable; -use Symfony\Component\Debug\Exception\FatalErrorException; +use Symfony\Component\ErrorHandler\Error\FatalError; use Zend\Diactoros\ServerRequestFactory; use function Http\Response\send; @@ -122,16 +122,14 @@ public function handleShutdown() * * @param array $error * @param int|null $traceOffset - * @return \Symfony\Component\Debug\Exception\FatalErrorException + * @return \Symfony\Component\ErrorHandler\Error\FatalError */ protected function fatalExceptionFromError(array $error, $traceOffset = null) { - return new FatalErrorException( + return new FatalError( $error['message'], $error['type'], - 0, - $error['file'], - $error['line'], + $error, $traceOffset ); } diff --git a/src/Exceptions/Handler.php b/src/Exceptions/Handler.php index 24c9420..7a18ccd 100644 --- a/src/Exceptions/Handler.php +++ b/src/Exceptions/Handler.php @@ -8,7 +8,7 @@ use Rareloop\Lumberjack\Application; use Rareloop\Lumberjack\Facades\Config; use Symfony\Component\ErrorHandler\ErrorHandler as SymfonyExceptionHandler; -use Symfony\Component\Debug\Exception\FlattenException; +use Symfony\Component\ErrorHandler\Exception\FlattenException; use Zend\Diactoros\Response\HtmlResponse; class Handler implements HandlerInterface @@ -38,7 +38,7 @@ public function render(ServerRequestInterface $request, Exception $e) : Response { $e = FlattenException::create($e); - $handler = new SymfonyExceptionHandler(Config::get('app.debug', false)); + $handler = new SymfonyExceptionHandler(null, Config::get('app.debug', false)); return new HtmlResponse($handler->getHtml($e), $e->getStatusCode(), $e->getHeaders()); } diff --git a/tests/Unit/Bootstrappers/RegisterExceptionHandlerTest.php b/tests/Unit/Bootstrappers/RegisterExceptionHandlerTest.php index c19f006..ceac8b8 100644 --- a/tests/Unit/Bootstrappers/RegisterExceptionHandlerTest.php +++ b/tests/Unit/Bootstrappers/RegisterExceptionHandlerTest.php @@ -14,7 +14,6 @@ use Rareloop\Lumberjack\Exceptions\HandlerInterface; use Rareloop\Lumberjack\Test\Unit\BrainMonkeyPHPUnitIntegration; use Rareloop\Router\Responsable; -use Symfony\Component\Debug\Exception\FatalErrorException; use Zend\Diactoros\Response; use Zend\Diactoros\Response\TextResponse; use Zend\Diactoros\ServerRequest; From cc991aac7eb3059f18998418d7c6ab99e1a97482 Mon Sep 17 00:00:00 2001 From: Alice Williams <25745335+AliceKLWilliams@users.noreply.github.com> Date: Wed, 20 Mar 2024 11:55:17 +0000 Subject: [PATCH 03/10] Fix Error Handler version for 8.0 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 7ae75ec..225ff61 100644 --- a/composer.json +++ b/composer.json @@ -23,7 +23,7 @@ "psr/log": "^1.1.4", "laminas/laminas-zendframework-bridge": "^1.7", "symfony/var-dumper": "^5.0||^6.3.6", - "symfony/error-handler": "^7.0" + "symfony/error-handler": "^6.0" }, "require-dev": { "phpunit/phpunit": "^9.6.13", From 27681e337a8767740aa985112580d55de07517a4 Mon Sep 17 00:00:00 2001 From: Alice Williams <25745335+AliceKLWilliams@users.noreply.github.com> Date: Wed, 20 Mar 2024 12:03:38 +0000 Subject: [PATCH 04/10] Use HtmlErrorRenderer --- src/Exceptions/Handler.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Exceptions/Handler.php b/src/Exceptions/Handler.php index 7a18ccd..2f5d827 100644 --- a/src/Exceptions/Handler.php +++ b/src/Exceptions/Handler.php @@ -7,7 +7,7 @@ use Psr\Http\Message\ServerRequestInterface; use Rareloop\Lumberjack\Application; use Rareloop\Lumberjack\Facades\Config; -use Symfony\Component\ErrorHandler\ErrorHandler as SymfonyExceptionHandler; +use Symfony\Component\ErrorHandler\ErrorRenderer\HtmlErrorRenderer; use Symfony\Component\ErrorHandler\Exception\FlattenException; use Zend\Diactoros\Response\HtmlResponse; @@ -38,9 +38,9 @@ public function render(ServerRequestInterface $request, Exception $e) : Response { $e = FlattenException::create($e); - $handler = new SymfonyExceptionHandler(null, Config::get('app.debug', false)); + $htmlRenderer = new HtmlErrorRenderer(Config::get('app.debug', false)); - return new HtmlResponse($handler->getHtml($e), $e->getStatusCode(), $e->getHeaders()); + return new HtmlResponse($htmlRenderer->getBody($e), $e->getStatusCode(), $e->getHeaders()); } protected function shouldNotReport(Exception $e) From adf9efffbce2768aaf966de46d6cc27c9b6d34fa Mon Sep 17 00:00:00 2001 From: Alice Williams <25745335+AliceKLWilliams@users.noreply.github.com> Date: Wed, 20 Mar 2024 13:51:18 +0000 Subject: [PATCH 05/10] Use expect exception --- tests/Unit/PostQueryBuilderTest.php | 10 ++-------- tests/Unit/ScopedQueryBuilderTest.php | 12 +++--------- 2 files changed, 5 insertions(+), 17 deletions(-) diff --git a/tests/Unit/PostQueryBuilderTest.php b/tests/Unit/PostQueryBuilderTest.php index 8cb501d..46e2d68 100644 --- a/tests/Unit/PostQueryBuilderTest.php +++ b/tests/Unit/PostQueryBuilderTest.php @@ -51,15 +51,9 @@ public function can_create_a_builder_from_static_functions() */ public function throw_error_on_missing_static_function() { - $errorThrown = false; + $this->expectException(Throwable::class); - try { - Post::missingStaticFunction(); - } catch (Throwable $e) { - $errorThrown = true; - } - - $this->assertTrue($errorThrown); + Post::missingStaticFunction(); } private function assertQueryBuilder($function, $params, $postType) diff --git a/tests/Unit/ScopedQueryBuilderTest.php b/tests/Unit/ScopedQueryBuilderTest.php index 655231f..012ce62 100644 --- a/tests/Unit/ScopedQueryBuilderTest.php +++ b/tests/Unit/ScopedQueryBuilderTest.php @@ -115,16 +115,10 @@ public function can_pass_params_into_a_query_scope_on_post_object() */ public function missing_query_scope_throws_an_error() { - $errorThrown = false; + $this->expectException(Throwable::class); - try { - $builder = new ScopedQueryBuilder(PostWithQueryScope::class); - $builder->nonExistentScope(); - } catch (Throwable $e) { - $errorThrown = true; - } - - $this->assertTrue($errorThrown); + $builder = new ScopedQueryBuilder(PostWithQueryScope::class); + $builder->nonExistentScope(); } /** @test */ From 50fe7b0ed8392157b2489a571cdc6dbf7af2e386 Mon Sep 17 00:00:00 2001 From: Alice Williams <25745335+AliceKLWilliams@users.noreply.github.com> Date: Wed, 20 Mar 2024 16:25:45 +0000 Subject: [PATCH 06/10] Fix tests --- tests/Unit/PostQueryBuilderTest.php | 12 ++++++++---- tests/Unit/ScopedQueryBuilderTest.php | 15 ++++++++++----- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/tests/Unit/PostQueryBuilderTest.php b/tests/Unit/PostQueryBuilderTest.php index 46e2d68..c6e82f0 100644 --- a/tests/Unit/PostQueryBuilderTest.php +++ b/tests/Unit/PostQueryBuilderTest.php @@ -47,13 +47,17 @@ public function can_create_a_builder_from_static_functions() /** * @test - * @runInSeparateProcess */ public function throw_error_on_missing_static_function() { - $this->expectException(Throwable::class); - - Post::missingStaticFunction(); + $errorThrown = false; + try { + Post::missingStaticFunction(); + } catch (Throwable $th) { + $errorThrown = true; + } + + $this->assertTrue($errorThrown); } private function assertQueryBuilder($function, $params, $postType) diff --git a/tests/Unit/ScopedQueryBuilderTest.php b/tests/Unit/ScopedQueryBuilderTest.php index 012ce62..8103f65 100644 --- a/tests/Unit/ScopedQueryBuilderTest.php +++ b/tests/Unit/ScopedQueryBuilderTest.php @@ -4,6 +4,7 @@ use Illuminate\Support\Collection; use Mockery; +use PHPUnit\Framework\Exception; use PHPUnit\Framework\TestCase; use Rareloop\Lumberjack\Application; use Rareloop\Lumberjack\Contracts\QueryBuilder as QueryBuilderContract; @@ -111,14 +112,18 @@ public function can_pass_params_into_a_query_scope_on_post_object() /** * @test - * @runInSeparateProcess */ public function missing_query_scope_throws_an_error() { - $this->expectException(Throwable::class); - - $builder = new ScopedQueryBuilder(PostWithQueryScope::class); - $builder->nonExistentScope(); + $errorThrown = false; + try { + $builder = new ScopedQueryBuilder(PostWithQueryScope::class); + $builder->nonExistentScope(); + } catch (Throwable $th) { + $errorThrown = true; + } + + $this->assertTrue($errorThrown); } /** @test */ From 80a2b2e05e03dd59f94729ba408202f588c8d50b Mon Sep 17 00:00:00 2001 From: Alice Williams <25745335+AliceKLWilliams@users.noreply.github.com> Date: Wed, 20 Mar 2024 16:26:35 +0000 Subject: [PATCH 07/10] Undo variable name change --- tests/Unit/PostQueryBuilderTest.php | 2 +- tests/Unit/ScopedQueryBuilderTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Unit/PostQueryBuilderTest.php b/tests/Unit/PostQueryBuilderTest.php index c6e82f0..6775f00 100644 --- a/tests/Unit/PostQueryBuilderTest.php +++ b/tests/Unit/PostQueryBuilderTest.php @@ -53,7 +53,7 @@ public function throw_error_on_missing_static_function() $errorThrown = false; try { Post::missingStaticFunction(); - } catch (Throwable $th) { + } catch (Throwable $e) { $errorThrown = true; } diff --git a/tests/Unit/ScopedQueryBuilderTest.php b/tests/Unit/ScopedQueryBuilderTest.php index 8103f65..4101bcc 100644 --- a/tests/Unit/ScopedQueryBuilderTest.php +++ b/tests/Unit/ScopedQueryBuilderTest.php @@ -119,7 +119,7 @@ public function missing_query_scope_throws_an_error() try { $builder = new ScopedQueryBuilder(PostWithQueryScope::class); $builder->nonExistentScope(); - } catch (Throwable $th) { + } catch (Throwable $e) { $errorThrown = true; } From b61a5202a5035cff3524d8eea1ed2f7201de226e Mon Sep 17 00:00:00 2001 From: Alice Williams <25745335+AliceKLWilliams@users.noreply.github.com> Date: Wed, 20 Mar 2024 16:27:02 +0000 Subject: [PATCH 08/10] Remove unused class --- tests/Unit/ScopedQueryBuilderTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/Unit/ScopedQueryBuilderTest.php b/tests/Unit/ScopedQueryBuilderTest.php index 4101bcc..ea6be20 100644 --- a/tests/Unit/ScopedQueryBuilderTest.php +++ b/tests/Unit/ScopedQueryBuilderTest.php @@ -4,7 +4,6 @@ use Illuminate\Support\Collection; use Mockery; -use PHPUnit\Framework\Exception; use PHPUnit\Framework\TestCase; use Rareloop\Lumberjack\Application; use Rareloop\Lumberjack\Contracts\QueryBuilder as QueryBuilderContract; From 1ab0d6ef44713c9d15e0fa8fcb8f344687dfdc4a Mon Sep 17 00:00:00 2001 From: Alice Williams <25745335+AliceKLWilliams@users.noreply.github.com> Date: Thu, 21 Mar 2024 09:51:00 +0000 Subject: [PATCH 09/10] Use render function so the HTML contains the CSS --- src/Exceptions/Handler.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Exceptions/Handler.php b/src/Exceptions/Handler.php index 2f5d827..c93ebc0 100644 --- a/src/Exceptions/Handler.php +++ b/src/Exceptions/Handler.php @@ -36,11 +36,11 @@ public function report(Exception $e) public function render(ServerRequestInterface $request, Exception $e) : ResponseInterface { - $e = FlattenException::create($e); - $htmlRenderer = new HtmlErrorRenderer(Config::get('app.debug', false)); - return new HtmlResponse($htmlRenderer->getBody($e), $e->getStatusCode(), $e->getHeaders()); + $exception = $htmlRenderer->render($e); + + return new HtmlResponse($exception->getAsString(), $exception->getStatusCode(), $exception->getHeaders()); } protected function shouldNotReport(Exception $e) From ceacb4c653e0af8d1f6ad16dbd271283c7b60ab3 Mon Sep 17 00:00:00 2001 From: Alice Williams <25745335+AliceKLWilliams@users.noreply.github.com> Date: Thu, 21 Mar 2024 09:53:02 +0000 Subject: [PATCH 10/10] Remove unused import --- src/Exceptions/Handler.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Exceptions/Handler.php b/src/Exceptions/Handler.php index c93ebc0..cfb085f 100644 --- a/src/Exceptions/Handler.php +++ b/src/Exceptions/Handler.php @@ -8,7 +8,6 @@ use Rareloop\Lumberjack\Application; use Rareloop\Lumberjack\Facades\Config; use Symfony\Component\ErrorHandler\ErrorRenderer\HtmlErrorRenderer; -use Symfony\Component\ErrorHandler\Exception\FlattenException; use Zend\Diactoros\Response\HtmlResponse; class Handler implements HandlerInterface