Skip to content

Commit

Permalink
[DV-8391] Fixed VerboseErrorResponse::stream returns Chunk instead of…
Browse files Browse the repository at this point in the history
… a ResponseStream.
  • Loading branch information
kkevindev committed Apr 23, 2024
1 parent c399665 commit 1e0e9c6
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/HttpClient/Response/VerboseErrorResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -85,12 +85,14 @@ public function cancel(): void
*
* @param iterable<VerboseErrorResponse> $responses
*
* @return Generator<VerboseErrorResponse, ResponseStreamInterface>
* @return Generator<ResponseInterface, ChunkInterface>
*/
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;
}
}
}
}
20 changes: 20 additions & 0 deletions tests/Response/VerboseErrorResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 1e0e9c6

Please sign in to comment.