Skip to content

[HttpClient] Expand MockResponse example with HTTP status codes #13387

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

Merged
merged 1 commit into from
Jan 8, 2021

Conversation

gbirke
Copy link
Contributor

@gbirke gbirke commented Mar 21, 2020

No description provided.

@javiereguiluz
Copy link
Member

@nicolas-grekas could you please check if this contribution is correct?

If it is, maybe we should update HttpClient component ... because this doesn't look very "ergonomic" when testing failures. Thanks!

use Symfony\Component\HttpClient\Response\MockResponse;

$client = new MockHttpClient([
new MockResponse('...', ['response_headers' => ['HTTP/1.1 500 Internal Server Error']]),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is a better way, which is to define the http_code info instead of response_headers

@carsonbot carsonbot changed the title Expand MockResponse example with HTTP status codes [HttpClient] Expand MockResponse example with HTTP status codes Jan 8, 2021
@javiereguiluz javiereguiluz added this to the 4.4 milestone Jan 8, 2021
Show how to create MockResponses with status codes different than "200 OK"
@javiereguiluz
Copy link
Member

We merged this (in 4.4 branch and up) and we included Nico's simplified solution to mock response errors. Thanks!

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

Successfully merging this pull request may close these issues.

4 participants