Skip to content

[11.x] Http Client: fake connection exception#53485

Merged
taylorotwell merged 4 commits intolaravel:11.xfrom
gdebrauwer:http-client-fake-failed-connection
Nov 12, 2024
Merged

[11.x] Http Client: fake connection exception#53485
taylorotwell merged 4 commits intolaravel:11.xfrom
gdebrauwer:http-client-fake-failed-connection

Conversation

@gdebrauwer
Copy link
Contributor

Currently it is possible to fake every possible response when faking the http client in a test, but it is currently not possible to fake a connection exception. This PR makes that possible.

try {
    Http::get('https://laravel.com')
} catch (ConnectionException) {
    // Some special handling that you want to test.
}

I made this possible by providing an easy way to create failed connection similar to creating a fake response:

Http::fake(['https://laravel.com' => Http::failedConnection()]);

// Similar syntax to:
Http::fake(['https://laravel.com' => Http::response()]);

I ensured faking a connection exception works in all different ways you can currently create fake responses (e.g. closure, response sequence) and I added a test for each one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants