From 812b0172f46d391512e2633f86512dd9f9a938cf Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Fri, 24 May 2019 16:42:41 +0200 Subject: [PATCH] [HttpClient] fix handling exceptions thrown before first mock chunk --- src/Symfony/Component/HttpClient/Response/MockResponse.php | 6 ++++-- .../Component/HttpClient/Tests/MockHttpClientTest.php | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Component/HttpClient/Response/MockResponse.php b/src/Symfony/Component/HttpClient/Response/MockResponse.php index df38c7e5bb..04b33a143a 100644 --- a/src/Symfony/Component/HttpClient/Response/MockResponse.php +++ b/src/Symfony/Component/HttpClient/Response/MockResponse.php @@ -25,7 +25,9 @@ use Symfony\Contracts\HttpClient\ResponseInterface; */ class MockResponse implements ResponseInterface { - use ResponseTrait; + use ResponseTrait { + doDestruct as public __destruct; + } private $body; private $requestOptions = []; @@ -162,8 +164,8 @@ class MockResponse implements ResponseInterface $offset = 0; $chunk[1]->getStatusCode(); $response->headers = $chunk[1]->getHeaders(false); - $multi->handlesActivity[$id][] = new FirstChunk(); self::readResponse($response, $chunk[0], $chunk[1], $offset); + $multi->handlesActivity[$id][] = new FirstChunk(); } catch (\Throwable $e) { $multi->handlesActivity[$id][] = null; $multi->handlesActivity[$id][] = $e; diff --git a/src/Symfony/Component/HttpClient/Tests/MockHttpClientTest.php b/src/Symfony/Component/HttpClient/Tests/MockHttpClientTest.php index e719428c81..710d86a258 100644 --- a/src/Symfony/Component/HttpClient/Tests/MockHttpClientTest.php +++ b/src/Symfony/Component/HttpClient/Tests/MockHttpClientTest.php @@ -115,7 +115,7 @@ class MockHttpClientTest extends HttpClientTestCase case 'testResolve': $responses[] = new MockResponse($body, ['response_headers' => $headers]); $responses[] = new MockResponse($body, ['response_headers' => $headers]); - $responses[] = $client->request('GET', 'http://symfony.com:8057/'); + $responses[] = new MockResponse((function () { throw new \Exception('Fake connection timeout'); yield ''; })(), ['response_headers' => $headers]); break; case 'testTimeoutOnStream':