shlogg · Early preview
Paul Redmond @paulredmond

Laravel's New Exceptions Facade Simplifies Exception Testing

Laravel 11.4 introduces Exceptions facade for asserting exceptions in tests. Simplify code with `Exceptions::fake()` and assert exceptions with `Exceptions::assertReported()`.

Laravel's recent release of Laravel 11.4 introduced the Exceptions facade, which adds conveniences around asserting exceptions in Laravel's exception handler. Before this release, I would typically use the $this->withoutExceptionHandling() to assert that a specific exception happened during an HTTP test:
use App\Exceptions\WelcomeException; $this->withoutExceptionHandling(); try {    $this->get('/');} catch (WelcomeException $e) {    $this->assertEquals('Woops, there was an issue with your request!', $e->getMessage());     return;} $this->fail(sprintf('The expected "%s" exception was not throw...