Skip to content

[HttpClient] Fix handling error info in MockResponse #44361

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
Dec 1, 2021

Conversation

fancyweb
Copy link
Contributor

@fancyweb fancyweb commented Nov 30, 2021

Q A
Branch? 4.4
Bug fix? yes
New feature? no
Deprecations? no
Tickets -
License MIT
Doc PR -

Using new MockResponse('', ['error' => 'foobar']) with the MockHttpClient, I expect a TransportException to be thrown if I call getStatusCode(), getHeaders(), getContent() or toArray().

Currently, it does not work for getStatusCode() and getHeaders() because MockResponse only "converts" the passed error to an exception after the full response workflow has been simulated. getStatusCode() and getHeaders() stops at the first chunk so it cannot work. I propose to throw at the beginning of the simulated response reading.


$responses[] = $mock;
$responses[] = $mock;
$responses[] = $mockResponse = new MockResponse('', ['error' => 'DNS error']);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We don't need to mock anymore because getStatusCode() will throw properly.

$mock->expects($this->any())
->method('getContent')
->willReturnCallback(static function (): void {
usleep(100000);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This usleep was useless.

@fancyweb fancyweb force-pushed the http-client/mock-error-init branch from d122b38 to 784edde Compare November 30, 2021 12:44
@fancyweb fancyweb force-pushed the http-client/mock-error-init branch from 784edde to 369d9d7 Compare November 30, 2021 17:02
@nicolas-grekas
Copy link
Member

Thank you @fancyweb.

@nicolas-grekas nicolas-grekas merged commit daba023 into symfony:4.4 Dec 1, 2021
@fancyweb fancyweb deleted the http-client/mock-error-init branch December 1, 2021 13:52
This was referenced Dec 9, 2021
This was referenced Dec 29, 2021
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