Skip to content

Commit

Permalink
Register DiscardClasses middleware by default
Browse files Browse the repository at this point in the history
  • Loading branch information
imjoehaines committed Feb 3, 2021
1 parent f6b2017 commit a6e1681
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));

Expand Down
26 changes: 26 additions & 0 deletions tests/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Exception;
use GuzzleHttp\Client as Guzzle;
use GuzzleHttp\Psr7\Uri;
use LogicException;
use PHPUnit\Framework\MockObject\MockObject;

/**
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit a6e1681

Please sign in to comment.