diff --git a/.gitignore b/.gitignore index 188e4c4..3882089 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ vendor composer.lock /tests/Unit/logs +.phpunit.result.cache diff --git a/composer.json b/composer.json index 3cd9a50..7ce33a4 100644 --- a/composer.json +++ b/composer.json @@ -23,7 +23,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", + "spatie/ignition": "^1.15" }, "require-dev": { "phpunit/phpunit": "^9.6.13", diff --git a/src/Exceptions/Handler.php b/src/Exceptions/Handler.php index 045b6f1..d29114a 100644 --- a/src/Exceptions/Handler.php +++ b/src/Exceptions/Handler.php @@ -3,13 +3,12 @@ namespace Rareloop\Lumberjack\Exceptions; use Exception; +use Laminas\Diactoros\Response\HtmlResponse; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use Rareloop\Lumberjack\Application; use Rareloop\Lumberjack\Facades\Config; -use Symfony\Component\Debug\ExceptionHandler as SymfonyExceptionHandler; -use Symfony\Component\Debug\Exception\FlattenException; -use Zend\Diactoros\Response\HtmlResponse; +use Spatie\Ignition\Ignition; class Handler implements HandlerInterface { @@ -36,11 +35,20 @@ public function report(Exception $e) public function render(ServerRequestInterface $request, Exception $e) : ResponseInterface { - $e = FlattenException::create($e); + $isDebug = Config::get('app.debug', false) === true; - $handler = new SymfonyExceptionHandler(Config::get('app.debug', false)); + $ignition = Ignition::make() + ->shouldDisplayException($isDebug) + ->runningInProductionEnvironment(!$isDebug) + ->register(); - return new HtmlResponse($handler->getHtml($e), $e->getStatusCode(), $e->getHeaders()); + ob_start(); + + $ignition->handleException($e); + + $html = ob_get_clean(); + + return new HtmlResponse($html); } protected function shouldNotReport(Exception $e) 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; diff --git a/tests/Unit/PostQueryBuilderTest.php b/tests/Unit/PostQueryBuilderTest.php index 8cb501d..5499996 100644 --- a/tests/Unit/PostQueryBuilderTest.php +++ b/tests/Unit/PostQueryBuilderTest.php @@ -47,19 +47,12 @@ public function can_create_a_builder_from_static_functions() /** * @test - * @runInSeparateProcess */ 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..410c6ec 100644 --- a/tests/Unit/ScopedQueryBuilderTest.php +++ b/tests/Unit/ScopedQueryBuilderTest.php @@ -111,20 +111,13 @@ public function can_pass_params_into_a_query_scope_on_post_object() /** * @test - * @runInSeparateProcess */ public function missing_query_scope_throws_an_error() { - $errorThrown = false; - - try { - $builder = new ScopedQueryBuilder(PostWithQueryScope::class); - $builder->nonExistentScope(); - } catch (Throwable $e) { - $errorThrown = true; - } + $this->expectException(Throwable::class); - $this->assertTrue($errorThrown); + $builder = new ScopedQueryBuilder(PostWithQueryScope::class); + $builder->nonExistentScope(); } /** @test */