|
1 | 1 | <?php
|
2 | 2 | namespace Http\Client\Curl\Tests;
|
3 | 3 |
|
| 4 | +use GuzzleHttp\Psr7\Stream; |
4 | 5 | use Http\Client\Curl\Client;
|
5 | 6 | use Zend\Diactoros\Request;
|
6 | 7 |
|
@@ -31,6 +32,46 @@ public function testExpectHeader()
|
31 | 32 | static::assertContains('Expect:', $headers);
|
32 | 33 | }
|
33 | 34 |
|
| 35 | + |
| 36 | + |
| 37 | + public function testRewindStream() |
| 38 | + { |
| 39 | + $client = $this->getMockBuilder(Client::class)->disableOriginalConstructor() |
| 40 | + ->setMethods(['__none__'])->getMock(); |
| 41 | + |
| 42 | + $bodyOptions = new \ReflectionMethod(Client::class, 'addRequestBodyOptions'); |
| 43 | + $bodyOptions->setAccessible(true); |
| 44 | + |
| 45 | + $body = \GuzzleHttp\Psr7\stream_for('abcdef'); |
| 46 | + $body->seek(3); |
| 47 | + $request = new Request('http://foo.com', 'POST', $body); |
| 48 | + $options = $bodyOptions->invoke($client, $request, []); |
| 49 | + |
| 50 | + static::assertEquals('abcdef', $options[CURLOPT_POSTFIELDS]); |
| 51 | + } |
| 52 | + |
| 53 | + public function testRewindLargeStream() |
| 54 | + { |
| 55 | + $client = $this->getMockBuilder(Client::class)->disableOriginalConstructor() |
| 56 | + ->setMethods(['__none__'])->getMock(); |
| 57 | + |
| 58 | + $bodyOptions = new \ReflectionMethod(Client::class, 'addRequestBodyOptions'); |
| 59 | + $bodyOptions->setAccessible(true); |
| 60 | + |
| 61 | + $content = 'abcdef'; |
| 62 | + while (strlen($content) < 1024*1024+100) { |
| 63 | + $content .= '123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890'; |
| 64 | + } |
| 65 | + |
| 66 | + $length = strlen($content); |
| 67 | + $body = \GuzzleHttp\Psr7\stream_for($content); |
| 68 | + $body->seek(40); |
| 69 | + $request = new Request('http://foo.com', 'POST', $body); |
| 70 | + $options = $bodyOptions->invoke($client, $request, []); |
| 71 | + |
| 72 | + static::assertTrue(false !== strstr($options[CURLOPT_READFUNCTION](null, null, $length), 'abcdef'), 'Steam was not rewinded'); |
| 73 | + } |
| 74 | + |
34 | 75 | /**
|
35 | 76 | * Discovery should be used if no factory given.
|
36 | 77 | */
|
|
0 commit comments