Fake Timeout Exceptions in Laravel

In case you needed to test timeout exceptions in your Laravel app, then it is very easy to do it using Laravel HTTP client.

You can use the Http::fake() method in your test to make it throw ConnectionException with any message you want:

use Illuminate\Http\Client\ConnectionException;
use Illuminate\Support\Facades\Http;

Http::fake(fn() => throw new ConnectionException('Connection timed out'));