Skip to content

Commit 70ec9fc

Browse files
[12.x] Allow retrieving all reported exceptions from ExceptionHandlerFake (#55972)
* Update ExceptionHandlerFake.php * Update ExceptionsFacadeTest.php * Update ExceptionsFacadeTest.php * Update ExceptionHandlerFake.php --------- Co-authored-by: Taylor Otwell <taylor@laravel.com>
1 parent 141c46c commit 70ec9fc

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/Illuminate/Support/Testing/Fakes/ExceptionHandlerFake.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,16 @@ public function throwFirstReported()
248248
return $this;
249249
}
250250

251+
/**
252+
* Get the exceptions that have been reported.
253+
*
254+
* @return list<\Throwable>
255+
*/
256+
public function reported()
257+
{
258+
return $this->reported;
259+
}
260+
251261
/**
252262
* Set the "original" handler that should be used by the fake.
253263
*

tests/Integration/Support/ExceptionsFacadeTest.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,17 @@ public function testFakeAssertReported()
2323
{
2424
Exceptions::fake();
2525

26-
Exceptions::report(new RuntimeException('test 1'));
26+
Exceptions::report($thrownException = new RuntimeException('test 1'));
2727
report(new RuntimeException('test 2'));
2828

2929
Exceptions::assertReported(RuntimeException::class);
3030
Exceptions::assertReported(fn (RuntimeException $e) => $e->getMessage() === 'test 1');
3131
Exceptions::assertReported(fn (RuntimeException $e) => $e->getMessage() === 'test 2');
3232
Exceptions::assertReportedCount(2);
33+
34+
$reported = Exceptions::reported();
35+
$this->assertCount(2, $reported);
36+
$this->assertSame($thrownException, $reported[0]);
3337
}
3438

3539
public function testFakeAssertReportedCount()

0 commit comments

Comments
 (0)