|
11 | 11 | * @see https://github.com/guanguans/laravel-exception-notify |
12 | 12 | */ |
13 | 13 |
|
| 14 | +use Guanguans\LaravelExceptionNotify\Contracts\Channel; |
14 | 15 | use Guanguans\LaravelExceptionNotify\ExceptionNotifyManager; |
15 | 16 | use Illuminate\Contracts\Foundation\Application; |
16 | 17 | use Illuminate\Support\Str; |
|
32 | 33 |
|
33 | 34 | it('can report if', function (): void { |
34 | 35 | expect(app(ExceptionNotifyManager::class)) |
35 | | - ->reportIf(true, new \Guanguans\LaravelExceptionNotify\Exceptions\Exception)->toBeNull(); |
| 36 | + ->reportIf(true, new \Guanguans\LaravelExceptionNotify\Exceptions\RuntimeException)->toBeNull(); |
36 | 37 | })->group(__DIR__, __FILE__); |
37 | 38 |
|
38 | 39 | it('can report', function (): void { |
39 | 40 | config()->set('exception-notify.enabled', false); |
40 | 41 | expect(app(ExceptionNotifyManager::class)) |
41 | | - ->report(new \Guanguans\LaravelExceptionNotify\Exceptions\Exception)->toBeNull(); |
| 42 | + ->report(new \Guanguans\LaravelExceptionNotify\Exceptions\RuntimeException)->toBeNull(); |
42 | 43 |
|
43 | 44 | config()->set('exception-notify.enabled', true); |
44 | 45 | $mockApplication = Mockery::spy(Illuminate\Foundation\Application::class); |
|
47 | 48 |
|
48 | 49 | /** @noinspection PhpVoidFunctionResultUsedInspection */ |
49 | 50 | expect(new ExceptionNotifyManager($mockApplication)) |
50 | | - ->report(new \Guanguans\LaravelExceptionNotify\Exceptions\Exception)->toBeNull(); |
| 51 | + ->report(new \Guanguans\LaravelExceptionNotify\Exceptions\RuntimeException)->toBeNull(); |
51 | 52 |
|
52 | 53 | config()->set('exception-notify.enabled', true); |
53 | 54 | $mockApplication = Mockery::mock(Application::class); |
|
56 | 57 |
|
57 | 58 | /** @noinspection PhpVoidFunctionResultUsedInspection */ |
58 | 59 | expect(new ExceptionNotifyManager($mockApplication)) |
59 | | - ->report(new \Guanguans\LaravelExceptionNotify\Exceptions\Exception)->toBeNull(); |
| 60 | + ->report(new \Guanguans\LaravelExceptionNotify\Exceptions\RuntimeException)->toBeNull(); |
60 | 61 | })->group(__DIR__, __FILE__); |
61 | 62 |
|
62 | 63 | it('should not report', function (): void { |
63 | 64 | config()->set('exception-notify.enabled', false); |
64 | | - expect(app(ExceptionNotifyManager::class))->shouldReport(new \Guanguans\LaravelExceptionNotify\Exceptions\Exception)->toBeFalse(); |
| 65 | + expect(app(ExceptionNotifyManager::class))->shouldReport(new \Guanguans\LaravelExceptionNotify\Exceptions\RuntimeException)->toBeFalse(); |
65 | 66 |
|
66 | 67 | config()->set('exception-notify.enabled', true); |
67 | 68 | config()->set('exception-notify.env', ['production', 'local']); |
68 | | - expect(app(ExceptionNotifyManager::class))->shouldReport(new \Guanguans\LaravelExceptionNotify\Exceptions\Exception)->toBeFalse(); |
| 69 | + expect(app(ExceptionNotifyManager::class))->shouldReport(new \Guanguans\LaravelExceptionNotify\Exceptions\RuntimeException)->toBeFalse(); |
69 | 70 |
|
70 | 71 | config()->set('exception-notify.enabled', true); |
71 | 72 | config()->set('exception-notify.env', '*'); |
72 | 73 | config()->set('exception-notify.except', [Exception::class]); |
73 | | - expect(app(ExceptionNotifyManager::class))->shouldReport(new \Guanguans\LaravelExceptionNotify\Exceptions\Exception)->toBeFalse(); |
| 74 | + expect(app(ExceptionNotifyManager::class))->shouldReport(new \Guanguans\LaravelExceptionNotify\Exceptions\RuntimeException)->toBeFalse(); |
74 | 75 |
|
75 | 76 | config()->set('exception-notify.enabled', true); |
76 | 77 | config()->set('exception-notify.env', '*'); |
77 | 78 | config()->set('exception-notify.except', []); |
78 | | - expect(app(ExceptionNotifyManager::class))->shouldReport(new \Guanguans\LaravelExceptionNotify\Exceptions\Exception)->toBeTrue(); |
| 79 | + expect(app(ExceptionNotifyManager::class))->shouldReport(new \Guanguans\LaravelExceptionNotify\Exceptions\RuntimeException)->toBeTrue(); |
79 | 80 | })->group(__DIR__, __FILE__); |
80 | 81 |
|
81 | 82 | it('can get default driver', function (): void { |
|
92 | 93 | ->call(app(ExceptionNotifyManager::class))->toBeTrue() |
93 | 94 | ->call(app(ExceptionNotifyManager::class))->toBeFalse(); |
94 | 95 | })->group(__DIR__, __FILE__); |
| 96 | + |
| 97 | +it('will throw `InvalidArgumentException`', function (): void { |
| 98 | + app(ExceptionNotifyManager::class)->driver('foo'); |
| 99 | +})->group(__DIR__, __FILE__)->throws(\Guanguans\LaravelExceptionNotify\Exceptions\InvalidArgumentException::class); |
| 100 | + |
| 101 | +it('can create custom driver', function (): void { |
| 102 | + app(ExceptionNotifyManager::class)->extend('foo', function () { |
| 103 | + return new class implements Channel { |
| 104 | + public function report(string $report): void {} |
| 105 | + }; |
| 106 | + }); |
| 107 | + |
| 108 | + expect(app(ExceptionNotifyManager::class))->driver('foo')->toBeInstanceOf(Channel::class); |
| 109 | +})->group(__DIR__, __FILE__); |
0 commit comments