Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DV-8391] Fixed VerboseErrorResponse::stream returns Chunk instead of a ResponseStream. #8

Merged
merged 1 commit into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
atehvg marked this conversation as resolved.
Show resolved Hide resolved
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
Loading