59 lines
1.4 KiB
PHP
59 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature;
|
|
|
|
use Symfony\Component\HttpKernel\Exception\HttpException;
|
|
use Tests\TestCase;
|
|
|
|
class SentryReportingTest extends TestCase
|
|
{
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
|
|
config(['sentry.dsn' => 'https://example@sentry.test/1']);
|
|
}
|
|
|
|
public function test_reports_server_errors_to_sentry(): void
|
|
{
|
|
$fake = new class
|
|
{
|
|
public int $captured = 0;
|
|
|
|
public function captureException(mixed $exception = null): void
|
|
{
|
|
$this->captured++;
|
|
}
|
|
};
|
|
|
|
$this->app->instance('sentry', $fake);
|
|
|
|
$handler = $this->app->make(\App\Exceptions\Handler::class);
|
|
|
|
$handler->report(new \RuntimeException('boom'));
|
|
|
|
$this->assertSame(1, $fake->captured, 'Sentry should receive server errors');
|
|
}
|
|
|
|
public function test_ignores_client_errors_for_sentry(): void
|
|
{
|
|
$fake = new class
|
|
{
|
|
public int $captured = 0;
|
|
|
|
public function captureException(mixed $exception = null): void
|
|
{
|
|
$this->captured++;
|
|
}
|
|
};
|
|
|
|
$this->app->instance('sentry', $fake);
|
|
|
|
$handler = $this->app->make(\App\Exceptions\Handler::class);
|
|
|
|
$handler->report(new HttpException(404));
|
|
|
|
$this->assertSame(0, $fake->captured, 'Sentry should ignore 4xx errors');
|
|
}
|
|
}
|