Skip to content

Replace Symfony Exception Handler with Spatie Ignition #56

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
vendor
composer.lock
/tests/Unit/logs
.phpunit.result.cache
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
20 changes: 14 additions & 6 deletions src/Exceptions/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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)
Expand Down
1 change: 0 additions & 1 deletion tests/Unit/Bootstrappers/RegisterExceptionHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
11 changes: 2 additions & 9 deletions tests/Unit/PostQueryBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
13 changes: 3 additions & 10 deletions tests/Unit/ScopedQueryBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
Loading