|
2 | 2 |
|
3 | 3 | namespace Facade\FlareClient\Tests; |
4 | 4 |
|
| 5 | +use Error; |
| 6 | +use ErrorException; |
5 | 7 | use Facade\FlareClient\Api; |
6 | 8 | use Facade\FlareClient\Enums\MessageLevels; |
7 | 9 | use Facade\FlareClient\Flare; |
8 | 10 | use Facade\FlareClient\Tests\Concerns\MatchesReportSnapshots; |
9 | 11 | use Facade\FlareClient\Tests\Mocks\FakeClient; |
10 | 12 | use Facade\FlareClient\Tests\TestClasses\ExceptionWithContext; |
11 | 13 | use PHPUnit\Framework\Exception; |
| 14 | +use Throwable; |
12 | 15 |
|
13 | 16 | class FlareTest extends TestCase |
14 | 17 | { |
@@ -43,6 +46,14 @@ protected function reportException() |
43 | 46 | $this->flare->report($throwable); |
44 | 47 | } |
45 | 48 |
|
| 49 | + protected function reportError(int $code) |
| 50 | + { |
| 51 | + $throwable = new Error('This is a test', $code); |
| 52 | + |
| 53 | + $this->flare->report($throwable); |
| 54 | + } |
| 55 | + |
| 56 | + |
46 | 57 | /** @test */ |
47 | 58 | public function it_can_report_an_exception() |
48 | 59 | { |
@@ -304,4 +315,60 @@ public function it_will_add_the_version_to_the_report() |
304 | 315 |
|
305 | 316 | $this->assertEquals('123', $payload['application_version']); |
306 | 317 | } |
| 318 | + |
| 319 | + /** @test */ |
| 320 | + public function it_can_filter_exceptions_being_reported() |
| 321 | + { |
| 322 | + $this->reportException(); |
| 323 | + |
| 324 | + $this->fakeClient->assertRequestsSent(1); |
| 325 | + |
| 326 | + $this->flare->filterExceptionsUsing(function (Throwable $exception) { |
| 327 | + return false; |
| 328 | + }); |
| 329 | + |
| 330 | + $this->reportException(); |
| 331 | + |
| 332 | + $this->fakeClient->assertRequestsSent(1); |
| 333 | + |
| 334 | + $this->flare->filterExceptionsUsing(function (Throwable $exception) { |
| 335 | + return true; |
| 336 | + }); |
| 337 | + |
| 338 | + $this->reportException(); |
| 339 | + |
| 340 | + $this->fakeClient->assertRequestsSent(2); |
| 341 | + } |
| 342 | + |
| 343 | + /** @test */ |
| 344 | + public function it_can_filter_errors_based_on_their_level() |
| 345 | + { |
| 346 | + $this->reportError(E_NOTICE); |
| 347 | + $this->reportError(E_WARNING); |
| 348 | + |
| 349 | + $this->fakeClient->assertRequestsSent(2); |
| 350 | + |
| 351 | + $this->flare->reportErrorLevels(E_ALL & ~E_NOTICE); |
| 352 | + |
| 353 | + $this->reportError(E_NOTICE); |
| 354 | + $this->reportError(E_WARNING); |
| 355 | + |
| 356 | + $this->fakeClient->assertRequestsSent(3); |
| 357 | + } |
| 358 | + |
| 359 | + /** @test */ |
| 360 | + public function it_can_filter_error_exceptions_based_on_their_severity() |
| 361 | + { |
| 362 | + $this->flare->report(new ErrorException('test', 0, E_NOTICE)); |
| 363 | + $this->flare->report(new ErrorException('test', 0, E_WARNING)); |
| 364 | + |
| 365 | + $this->fakeClient->assertRequestsSent(2); |
| 366 | + |
| 367 | + $this->flare->reportErrorLevels(E_ALL & ~E_NOTICE); |
| 368 | + |
| 369 | + $this->flare->report(new ErrorException('test', 0, E_NOTICE)); |
| 370 | + $this->flare->report(new ErrorException('test', 0, E_WARNING)); |
| 371 | + |
| 372 | + $this->fakeClient->assertRequestsSent(3); |
| 373 | + } |
307 | 374 | } |
0 commit comments