diff --git a/src/HttpClient/Response/VerboseErrorResponse.php b/src/HttpClient/Response/VerboseErrorResponse.php index e05d0e8..3776ee3 100755 --- a/src/HttpClient/Response/VerboseErrorResponse.php +++ b/src/HttpClient/Response/VerboseErrorResponse.php @@ -8,12 +8,12 @@ use Superbrave\VerboseErrorHttpClientBundle\HttpClient\Exception\ClientException; use Superbrave\VerboseErrorHttpClientBundle\HttpClient\Exception\RedirectionException; use Superbrave\VerboseErrorHttpClientBundle\HttpClient\Exception\ServerException; +use Symfony\Contracts\HttpClient\ChunkInterface; use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface; use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface; use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface; use Symfony\Contracts\HttpClient\HttpClientInterface; use Symfony\Contracts\HttpClient\ResponseInterface; -use Symfony\Contracts\HttpClient\ResponseStreamInterface; /** * Wraps a response to be able to decorate the thrown exceptions. @@ -85,12 +85,14 @@ public function cancel(): void * * @param iterable $responses * - * @return Generator + * @return Generator */ public static function stream(HttpClientInterface $client, iterable $responses, ?float $timeout): Generator { foreach ($responses as $response) { - yield $response => $client->stream($response->response, $timeout); + foreach ($client->stream($response->response, $timeout) as $innerResponse => $chunk) { + yield $innerResponse => $chunk; + } } } } diff --git a/tests/Response/VerboseErrorResponseTest.php b/tests/Response/VerboseErrorResponseTest.php index 6632341..29910c6 100755 --- a/tests/Response/VerboseErrorResponseTest.php +++ b/tests/Response/VerboseErrorResponseTest.php @@ -15,6 +15,7 @@ use Symfony\Component\HttpClient\Exception\ServerException as SymfonyServerException; use Symfony\Component\HttpClient\Response\MockResponse; use Symfony\Contracts\HttpClient\Exception\HttpExceptionInterface; +use Symfony\Contracts\HttpClient\HttpClientInterface; use Symfony\Contracts\HttpClient\ResponseInterface; final class VerboseErrorResponseTest extends TestCase @@ -205,6 +206,25 @@ public function testCancel(): void $this->response->cancel(); } + public function testStreamCallsInnerHttpClientStreamWithInnerResponse(): void + { + // Arrange + $timeout = 50.5; + $innerHttpClientMock = $this->createMock(HttpClientInterface::class); + + $innerResponseMock = $this->createMock(ResponseInterface::class); + $verboseErrorResponse = new VerboseErrorResponse($innerResponseMock); + + // Assert + $innerHttpClientMock->expects(self::once()) + ->method('stream') + ->with($innerResponseMock, $timeout); + + // Act + $stream = VerboseErrorResponse::stream($innerHttpClientMock, [$verboseErrorResponse], $timeout); + $stream->next(); + } + public static function provideExceptionTestCases(): array { $response = new MockResponse(