From a6e1681b2ab9f73526f8da4d9afa89cbd50afec7 Mon Sep 17 00:00:00 2001 From: Joe Haines Date: Wed, 3 Feb 2021 13:45:57 +0000 Subject: [PATCH] Register DiscardClasses middleware by default --- src/Client.php | 2 ++ tests/ClientTest.php | 26 ++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/src/Client.php b/src/Client.php index feb8e99e..7800230e 100644 --- a/src/Client.php +++ b/src/Client.php @@ -12,6 +12,7 @@ use Bugsnag\Internal\GuzzleCompat; use Bugsnag\Middleware\BreadcrumbData; use Bugsnag\Middleware\CallbackBridge; +use Bugsnag\Middleware\DiscardClasses; use Bugsnag\Middleware\NotificationSkipper; use Bugsnag\Middleware\SessionData; use Bugsnag\Request\BasicResolver; @@ -137,6 +138,7 @@ public function __construct( $this->sessionTracker = new SessionTracker($config, $this->http); $this->registerMiddleware(new NotificationSkipper($config)); + $this->registerMiddleware(new DiscardClasses($config)); $this->registerMiddleware(new BreadcrumbData($this->recorder)); $this->registerMiddleware(new SessionData($this)); diff --git a/tests/ClientTest.php b/tests/ClientTest.php index 26fd3baa..059c5593 100644 --- a/tests/ClientTest.php +++ b/tests/ClientTest.php @@ -10,6 +10,7 @@ use Exception; use GuzzleHttp\Client as Guzzle; use GuzzleHttp\Psr7\Uri; +use LogicException; use PHPUnit\Framework\MockObject\MockObject; /** @@ -461,6 +462,31 @@ function (Report $report) use (&$pipelineCompleted) { $this->assertTrue($pipelineCompleted); } + public function testItAddsDiscardClassesMiddlewareByDefault() + { + $client = Client::make('foo'); + $client->setDiscardClasses([Exception::class]); + + $report = Report::fromPHPThrowable( + $client->getConfig(), + new Exception('oh no') + ); + + $pipeline = $client->getPipeline(); + $pipelineCompleted = false; + + $pipeline->execute( + $report, + function () use (&$pipelineCompleted) { + $pipelineCompleted = true; + + throw new LogicException('This should never be reached!'); + } + ); + + $this->assertFalse($pipelineCompleted); + } + public function testBreadcrumbsWorks() { $this->client = new Client($this->config = new Configuration('example-api-key'), null, $this->guzzle);