|
12 | 12 | namespace Symfony\Component\HttpClient\Tests;
|
13 | 13 |
|
14 | 14 | use Symfony\Component\HttpClient\Exception\ClientException;
|
| 15 | +use Symfony\Component\HttpClient\Response\StreamWrapper; |
15 | 16 | use Symfony\Contracts\HttpClient\Test\HttpClientTestCase as BaseHttpClientTestCase;
|
16 | 17 |
|
17 | 18 | abstract class HttpClientTestCase extends BaseHttpClientTestCase
|
@@ -91,4 +92,40 @@ public function testNonBlockingStream()
|
91 | 92 | $this->assertSame('', fread($stream, 8192));
|
92 | 93 | $this->assertTrue(feof($stream));
|
93 | 94 | }
|
| 95 | + |
| 96 | + public function testResponseStreamRewind() |
| 97 | + { |
| 98 | + $client = $this->getHttpClient(__FUNCTION__); |
| 99 | + $response = $client->request('GET', 'http://localhost:8057/103'); |
| 100 | + |
| 101 | + $stream = $response->toStream(); |
| 102 | + |
| 103 | + $this->assertSame('Here the body', stream_get_contents($stream)); |
| 104 | + rewind($stream); |
| 105 | + $this->assertSame('Here the body', stream_get_contents($stream)); |
| 106 | + } |
| 107 | + |
| 108 | + public function testStreamWrapperStreamRewind() |
| 109 | + { |
| 110 | + $client = $this->getHttpClient(__FUNCTION__); |
| 111 | + $response = $client->request('GET', 'http://localhost:8057/103'); |
| 112 | + |
| 113 | + $stream = StreamWrapper::createResource($response); |
| 114 | + |
| 115 | + $this->assertSame('Here the body', stream_get_contents($stream)); |
| 116 | + rewind($stream); |
| 117 | + $this->assertSame('Here the body', stream_get_contents($stream)); |
| 118 | + } |
| 119 | + |
| 120 | + public function testStreamWrapperWithClientStreamRewind() |
| 121 | + { |
| 122 | + $client = $this->getHttpClient(__FUNCTION__); |
| 123 | + $response = $client->request('GET', 'http://localhost:8057/103'); |
| 124 | + |
| 125 | + $stream = StreamWrapper::createResource($response, $client); |
| 126 | + |
| 127 | + $this->assertSame('Here the body', stream_get_contents($stream)); |
| 128 | + rewind($stream); |
| 129 | + $this->assertSame('Here the body', stream_get_contents($stream)); |
| 130 | + } |
94 | 131 | }
|
0 commit comments