|
9 | 9 | use React\SocketClient\DnsConnector; |
10 | 10 | use Clue\React\Buzz\Message\ResponseException; |
11 | 11 | use Clue\React\Block; |
| 12 | +use React\Stream\ReadableStream; |
12 | 13 |
|
13 | 14 | class FunctionalBrowserTest extends TestCase |
14 | 15 | { |
@@ -130,4 +131,53 @@ public function testErrorStatusCodeRejectsWithResponseException() |
130 | 131 | $this->assertEquals(404, $e->getResponse()->getStatusCode()); |
131 | 132 | } |
132 | 133 | } |
| 134 | + |
| 135 | + public function testPostString() |
| 136 | + { |
| 137 | + $response = Block\await($this->browser->post($this->base . 'post', array(), 'hello world'), $this->loop); |
| 138 | + $data = json_decode((string)$response->getBody(), true); |
| 139 | + |
| 140 | + $this->assertEquals('hello world', $data['data']); |
| 141 | + } |
| 142 | + |
| 143 | + public function testPostStreamChunked() |
| 144 | + { |
| 145 | + $stream = new ReadableStream(); |
| 146 | + |
| 147 | + $this->loop->addTimer(0.001, function () use ($stream) { |
| 148 | + $stream->emit('data', array('hello world')); |
| 149 | + $stream->close(); |
| 150 | + }); |
| 151 | + |
| 152 | + $response = Block\await($this->browser->post($this->base . 'post', array(), $stream), $this->loop); |
| 153 | + $data = json_decode((string)$response->getBody(), true); |
| 154 | + |
| 155 | + $this->assertEquals('hello world', $data['data']); |
| 156 | + } |
| 157 | + |
| 158 | + public function testPostStreamKnownLength() |
| 159 | + { |
| 160 | + $stream = new ReadableStream(); |
| 161 | + |
| 162 | + $this->loop->addTimer(0.001, function () use ($stream) { |
| 163 | + $stream->emit('data', array('hello world')); |
| 164 | + $stream->close(); |
| 165 | + }); |
| 166 | + |
| 167 | + $response = Block\await($this->browser->post($this->base . 'post', array('Content-Length' => 11), $stream), $this->loop); |
| 168 | + $data = json_decode((string)$response->getBody(), true); |
| 169 | + |
| 170 | + $this->assertEquals('hello world', $data['data']); |
| 171 | + } |
| 172 | + |
| 173 | + public function testPostStreamClosed() |
| 174 | + { |
| 175 | + $stream = new ReadableStream(); |
| 176 | + $stream->close(); |
| 177 | + |
| 178 | + $response = Block\await($this->browser->post($this->base . 'post', array(), $stream), $this->loop); |
| 179 | + $data = json_decode((string)$response->getBody(), true); |
| 180 | + |
| 181 | + $this->assertEquals('', $data['data']); |
| 182 | + } |
133 | 183 | } |
0 commit comments