Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged

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