8000 [HttpClient] fix handling exceptions thrown before first mock chunk · symfony/symfony@812b017 · GitHub
[go: up one dir, main page]

Skip to content

Commit 812b017

Browse files
[HttpClient] fix handling exceptions thrown before first mock chunk
1 parent ce26936 commit 812b017

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

src/Symfony/Component/HttpClient/Response/MockResponse.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@
2525
*/
2626
class MockResponse implements ResponseInterface
2727
{
28-
use ResponseTrait;
28+
use ResponseTrait {
29+
doDestruct as public __destruct;
30+
}
2931

3032
private $body;
3133
private $requestOptions = [];
@@ -162,8 +164,8 @@ protected static function perform(ClientState $multi, array &$responses): void
162164
$offset = 0;
163165
$chunk[1]->getStatusCode();
164166
$response->headers = $chunk[1]->getHeaders(false);
165-
$multi->handlesActivity[$id][] = new FirstChunk();
166167
self::readResponse($response, $chunk[0], $chunk[1], $offset);
168+
$multi->handlesActivity[$id][] = new FirstChunk();
167169
} catch (\Throwable $e) {
168170
$multi->handlesActivity[$id][] = null;
169171
$multi->handlesActivity[$id][] = $e;

src/Symfony/Component/HttpClient/Tests/MockHttpClientTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ protected function getHttpClient(string $testCase): HttpClientInterface
115115
case 'testResolve':
116116
$responses[] = new MockResponse($body, ['response_headers' => $headers]);
117117
$responses[] = new MockResponse($body, ['response_headers' => $headers]);
118-
$responses[] = $client->request('GET', 'http://symfony.com:8057/');
118+
$responses[] = new MockResponse((function () { throw new \Exception('Fake connection timeout'); yield ''; })(), ['response_headers' => $headers]);
119119
break;
120120

121121
case 'testTimeoutOnStream':

0 commit comments

Comments
 (0)
0