diff --git a/src/Illuminate/Foundation/Exceptions/Handler.php b/src/Illuminate/Foundation/Exceptions/Handler.php index bd2521a26e4f..2518365b92b1 100644 --- a/src/Illuminate/Foundation/Exceptions/Handler.php +++ b/src/Illuminate/Foundation/Exceptions/Handler.php @@ -103,9 +103,9 @@ public function report(Throwable $e) } if (is_callable($reportCallable = [$e, 'report'])) { - $this->container->call($reportCallable); - - return; + if ($this->container->call($reportCallable) !== false) { + return; + } } try { diff --git a/tests/Foundation/FoundationExceptionsHandlerTest.php b/tests/Foundation/FoundationExceptionsHandlerTest.php index 777a9fc3346f..e021ee3c1289 100644 --- a/tests/Foundation/FoundationExceptionsHandlerTest.php +++ b/tests/Foundation/FoundationExceptionsHandlerTest.php @@ -17,6 +17,7 @@ use Illuminate\Validation\ValidationException; use Illuminate\Validation\Validator; use Mockery as m; +use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration; use PHPUnit\Framework\TestCase; use Psr\Log\LoggerInterface; use RuntimeException; @@ -28,6 +29,8 @@ class FoundationExceptionsHandlerTest extends TestCase { + use MockeryPHPUnitIntegration; + protected $config; protected $container; @@ -60,8 +63,6 @@ protected function setUp(): void protected function tearDown(): void { - m::close(); - Container::setInstance(null); } @@ -69,16 +70,29 @@ public function testHandlerReportsExceptionAsContext() { $logger = m::mock(LoggerInterface::class); $this->container->instance(LoggerInterface::class, $logger); - $logger->shouldReceive('error')->withArgs(['Exception message', m::hasKey('exception')]); + $logger->shouldReceive('error')->withArgs(['Exception message', m::hasKey('exception')])->once(); $this->handler->report(new RuntimeException('Exception message')); } + public function testHandlerReportsExceptionWhenUnReportable() + { + $logger = m::mock(LoggerInterface::class); + $this->container->instance(LoggerInterface::class, $logger); + $logger->shouldReceive('error')->withArgs(['Exception message', m::hasKey('exception')])->once(); + + $this->handler->report(new UnReportableException('Exception message')); + } + public function testHandlerCallsReportMethodWithDependencies() { $reporter = m::mock(ReportingService::class); $this->container->instance(ReportingService::class, $reporter); - $reporter->shouldReceive('send')->withArgs(['Exception message']); + $reporter->shouldReceive('send')->withArgs(['Exception message'])->once(); + + $logger = m::mock(LoggerInterface::class); + $this->container->instance(LoggerInterface::class, $logger); + $logger->shouldNotReceive('error'); $this->handler->report(new ReportableException('Exception message')); } @@ -226,6 +240,14 @@ public function report(ReportingService $reportingService) } } +class UnReportableException extends Exception +{ + public function report() + { + return false; + } +} + interface ReportingService { public function send($message);