8000 bug #31610 [HttpClient] fix handling exceptions thrown before first m… · symfony/symfony@6aacfea · GitHub
[go: up one dir, main page]

Skip to content

Commit 6aacfea

Browse files
committed
bug #31610 [HttpClient] fix handling exceptions thrown before first mock chunk (nicolas-grekas)
This PR was merged into the 4.3 branch. Discussion ---------- [HttpClient] fix handling exceptions thrown before first mock chunk | Q | A | ------------- | --- | Branch? | 4.3 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - Discovered while fixing a 60s timeout on a test case, which this fixes too. Commits ------- 812b017 [HttpClient] fix handling exceptions thrown before first mock chunk
2 parents 5ecf80a + 812b017 commit 6aacfea

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