|
7 | 7 | use GuzzleHttp\Psr7\PumpStream; |
8 | 8 | use GuzzleHttp\Psr7\Response; |
9 | 9 | use PHPUnit\Framework\TestCase; |
| 10 | +use Psr\Http\Message\StreamInterface; |
10 | 11 | use Swis\JsonApi\Client\CollectionDocument; |
11 | 12 | use Swis\JsonApi\Client\Document; |
12 | 13 | use Swis\JsonApi\Client\InvalidResponseDocument; |
@@ -119,6 +120,36 @@ public function it_parses_a_response_with_a_body_and_unknown_size() |
119 | 120 | $this->assertSame($response, $document->getResponse()); |
120 | 121 | } |
121 | 122 |
|
| 123 | + /** |
| 124 | + * @test |
| 125 | + */ |
| 126 | + public function it_parses_a_response_with_a_seekable_stream_and_unknown_size() |
| 127 | + { |
| 128 | + $stream = $this->createMock(StreamInterface::class); |
| 129 | + $stream->method('getSize')->willReturn(-1); |
| 130 | + $stream->method('isSeekable')->willReturn(true); |
| 131 | + $stream->method('tell')->willReturn(0); |
| 132 | + $stream->expects($this->once())->method('read')->with(1)->willReturn('x'); |
| 133 | + $stream->expects($this->once())->method('seek')->with(0); |
| 134 | + |
| 135 | + $parsedDocument = new Document(); |
| 136 | + |
| 137 | + $documentParser = $this->createMock(DocumentParser::class); |
| 138 | + $documentParser |
| 139 | + ->expects($this->once()) |
| 140 | + ->method('parse') |
| 141 | + ->with($this->isType('string')) |
| 142 | + ->willReturn($parsedDocument); |
| 143 | + |
| 144 | + $parser = new ResponseParser($documentParser); |
| 145 | + $response = new Response(200, [], $stream); |
| 146 | + |
| 147 | + $document = $parser->parse($response); |
| 148 | + |
| 149 | + $this->assertSame($parsedDocument, $document); |
| 150 | + $this->assertSame($response, $document->getResponse()); |
| 151 | + } |
| 152 | + |
122 | 153 | /** |
123 | 154 | * @test |
124 | 155 | */ |
|
0 commit comments