Skip to content

Commit eaea47a

Browse files
authored
[6.x] Backport #33323 to 6.x (#37235)
* Backport #33323 to 6.x * StyleCI fix
1 parent cee4dae commit eaea47a

File tree

2 files changed

+29
-5
lines changed

2 files changed

+29
-5
lines changed

src/Illuminate/Foundation/Exceptions/Handler.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,9 @@ public function report(Exception $e)
105105
}
106106

107107
if (Reflector::isCallable($reportCallable = [$e, 'report'])) {
108-
return $this->container->call($reportCallable);
108+
if (($response = $this->container->call($reportCallable)) !== false) {
109+
return $response;
110+
}
109111
}
110112

111113
try {

tests/Foundation/FoundationExceptionsHandlerTest.php

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Illuminate\Support\MessageBag;
1717
use Illuminate\Validation\ValidationException;
1818
use Illuminate\Validation\Validator;
19+
use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration;
1920
use Mockery as m;
2021
use PHPUnit\Framework\TestCase;
2122
use Psr\Log\LoggerInterface;
@@ -28,6 +29,8 @@
2829

2930
class FoundationExceptionsHandlerTest extends TestCase
3031
{
32+
use MockeryPHPUnitIntegration;
33+
3134
protected $config;
3235

3336
protected $container;
@@ -60,25 +63,36 @@ protected function setUp(): void
6063

6164
protected function tearDown(): void
6265
{
63-
m::close();
64-
6566
Container::setInstance(null);
6667
}
6768

6869
public function testHandlerReportsExceptionAsContext()
6970
{
7071
$logger = m::mock(LoggerInterface::class);
7172
$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();
7374

7475
$this->handler->report(new RuntimeException('Exception message'));
7576
}
7677

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+
7787
public function testHandlerCallsReportMethodWithDependencies()
7888
{
7989
$reporter = m::mock(ReportingService::class);
8090
$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');
8296

8397
$this->handler->report(new ReportableException('Exception message'));
8498
}
@@ -226,6 +240,14 @@ public function report(ReportingService $reportingService)
226240
}
227241
}
228242

243+
class UnReportableException extends Exception
244+
{
245+
public function report()
246+
{
247+
return false;
248+
}
249+
}
250+
229251
interface ReportingService
230252
{
231253
public function send($message);

0 commit comments

Comments
 (0)