|
16 | 16 | use Illuminate\Support\MessageBag;
|
17 | 17 | use Illuminate\Validation\ValidationException;
|
18 | 18 | use Illuminate\Validation\Validator;
|
| 19 | +use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration; |
19 | 20 | use Mockery as m;
|
20 | 21 | use PHPUnit\Framework\TestCase;
|
21 | 22 | use Psr\Log\LoggerInterface;
|
|
28 | 29 |
|
29 | 30 | class FoundationExceptionsHandlerTest extends TestCase
|
30 | 31 | {
|
| 32 | + use MockeryPHPUnitIntegration; |
| 33 | + |
31 | 34 | protected $config;
|
32 | 35 |
|
33 | 36 | protected $container;
|
@@ -60,25 +63,36 @@ protected function setUp(): void
|
60 | 63 |
|
61 | 64 | protected function tearDown(): void
|
62 | 65 | {
|
63 |
| - m::close(); |
64 |
| - |
65 | 66 | Container::setInstance(null);
|
66 | 67 | }
|
67 | 68 |
|
68 | 69 | public function testHandlerReportsExceptionAsContext()
|
69 | 70 | {
|
70 | 71 | $logger = m::mock(LoggerInterface::class);
|
71 | 72 | $this->container->instance(LoggerInterface::class, $logger);
|
72 |
| - $logger->shouldReceive('error')->withArgs(['Exception message', m::hasKey('exception')]); |
| 73 | + $logger->shouldReceive('error')->withArgs(['Exception message', m::hasKey('exception')])->once(); |
73 | 74 |
|
74 | 75 | $this->handler->report(new RuntimeException('Exception message'));
|
75 | 76 | }
|
76 | 77 |
|
| 78 | + public function testHandlerReportsExceptionWhenUnReportable() |
| 79 | + { |
| 80 | + $logger = m::mock(LoggerInterface::class); |
| 81 | + $this->container->instance(LoggerInterface::class, $logger); |
| 82 | + $logger->shouldReceive('error')->withArgs(['Exception message', m::hasKey('exception')])->once(); |
| 83 | + |
| 84 | + $this->handler->report(new UnReportableException('Exception message')); |
| 85 | + } |
| 86 | + |
77 | 87 | public function testHandlerCallsReportMethodWithDependencies()
|
78 | 88 | {
|
79 | 89 | $reporter = m::mock(ReportingService::class);
|
80 | 90 | $this->container->instance(ReportingService::class, $reporter);
|
81 |
| - $reporter->shouldReceive('send')->withArgs(['Exception message']); |
| 91 | + $reporter->shouldReceive('send')->withArgs(['Exception message'])->once(); |
| 92 | + |
| 93 | + $logger = m::mock(LoggerInterface::class); |
| 94 | + $this->container->instance(LoggerInterface::class, $logger); |
| 95 | + $logger->shouldNotReceive('error'); |
82 | 96 |
|
83 | 97 | $this->handler->report(new ReportableException('Exception message'));
|
84 | 98 | }
|
@@ -226,6 +240,14 @@ public function report(ReportingService $reportingService)
|
226 | 240 | }
|
227 | 241 | }
|
228 | 242 |
|
| 243 | +class UnReportableException extends Exception |
| 244 | +{ |
| 245 | + public function report() |
| 246 | + { |
| 247 | + return false; |
| 248 | + } |
| 249 | +} |
| 250 | + |
229 | 251 | interface ReportingService
|
230 | 252 | {
|
231 | 253 | public function send($message);
|
|
0 commit comments