diff --git a/src/Symfony/Component/HttpClient/Tests/TraceableHttpClientTest.php b/src/Symfony/Component/HttpClient/Tests/TraceableHttpClientTest.php index 181cc84a36c0..66097d013baf 100755 --- a/src/Symfony/Component/HttpClient/Tests/TraceableHttpClientTest.php +++ b/src/Symfony/Component/HttpClient/Tests/TraceableHttpClientTest.php @@ -13,9 +13,11 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\HttpClient\MockHttpClient; +use Symfony\Component\HttpClient\NativeHttpClient; use Symfony\Component\HttpClient\Response\MockResponse; use Symfony\Component\HttpClient\TraceableHttpClient; use Symfony\Contracts\HttpClient\HttpClientInterface; +use Symfony\Contracts\HttpClient\Test\TestHttpServer; class TraceableHttpClientTest extends TestCase { @@ -80,4 +82,18 @@ public function testItResetsTraces() $sut->reset(); $this->assertCount(0, $sut->getTracedRequests()); } + + public function testStream() + { + TestHttpServer::start(); + + $sut = new TraceableHttpClient(new NativeHttpClient()); + $chunked = $sut->request('GET', 'http://localhost:8057/chunked'); + $chunks = []; + foreach ($sut->stream($chunked) as $response) { + $chunks[] = $response->getContent(); + } + $this->assertGreaterThan(1, \count($chunks)); + $this->assertSame('Symfony is awesome!', implode('', $chunks)); + } } diff --git a/src/Symfony/Component/HttpClient/TraceableHttpClient.php b/src/Symfony/Component/HttpClient/TraceableHttpClient.php index 34fa33e64397..f7fbfafc3b0c 100644 --- a/src/Symfony/Component/HttpClient/TraceableHttpClient.php +++ b/src/Symfony/Component/HttpClient/TraceableHttpClient.php @@ -67,18 +67,18 @@ public function stream($responses, float $timeout = null): ResponseStreamInterfa if ($responses instanceof TraceableResponse) { $responses = [$responses]; } elseif (!is_iterable($responses)) { - throw new \TypeError(sprintf('%s() expects parameter 1 to be an iterable of TraceableResponse objects, "%s" given.', __METHOD__, get_debug_type($responses))); + throw new \TypeError(sprintf('"%s()" expects parameter 1 to be an iterable of TraceableResponse objects, "%s" given.', __METHOD__, get_debug_type($responses))); } return $this->client->stream(\Closure::bind(static function () use ($responses) { foreach ($responses as $k => $r) { if (!$r instanceof TraceableResponse) { - throw new \TypeError(sprintf('%s() expects parameter 1 to be an iterable of TraceableResponse objects, "%s" given.', __METHOD__, get_debug_type($r))); + throw new \TypeError(sprintf('"%s()" expects parameter 1 to be an iterable of TraceableResponse objects, "%s" given.', __METHOD__, get_debug_type($r))); } yield $k => $r->response; } - }, null, TraceableResponse::class), $timeout); + }, null, TraceableResponse::class)(), $timeout); } public function getTracedRequests(): array