|
5 | 5 | use Clue\React\Block; |
6 | 6 | use React\EventLoop\Factory; |
7 | 7 | use React\Promise; |
| 8 | +use React\Promise\Deferred; |
8 | 9 | use React\Promise\Stream; |
9 | 10 | use React\Promise\Timer; |
10 | 11 | use React\Stream\ThroughStream; |
@@ -149,11 +150,30 @@ public function testForwardsDataImmediatelyIfPromiseIsAlreadyResolved() |
149 | 150 | $stream->write('hello'); |
150 | 151 | } |
151 | 152 |
|
152 | | - public function testForwardsDataInOneGoOncePromiseResolves() |
| 153 | + public function testForwardsOriginalDataOncePromiseResolves() |
153 | 154 | { |
| 155 | + $data = new \stdClass(); |
| 156 | + |
154 | 157 | $input = $this->getMockBuilder('React\Stream\WritableStreamInterface')->getMock(); |
155 | 158 | $input->expects($this->once())->method('isWritable')->willReturn(true); |
156 | | - $input->expects($this->once())->method('write')->with('helloworld'); |
| 159 | + $input->expects($this->once())->method('write')->with($data); |
| 160 | + $input->expects($this->never())->method('end'); |
| 161 | + |
| 162 | + $promise = Timer\resolve(0.001, $this->loop)->then(function () use ($input) { |
| 163 | + return $input; |
| 164 | + }); |
| 165 | + $stream = Stream\unwrapWritable($promise); |
| 166 | + |
| 167 | + $stream->write($data); |
| 168 | + |
| 169 | + $this->loop->run(); |
| 170 | + } |
| 171 | + |
| 172 | + public function testForwardsDataInOriginalChunksOncePromiseResolves() |
| 173 | + { |
| 174 | + $input = $this->getMockBuilder('React\Stream\WritableStreamInterface')->getMock(); |
| 175 | + $input->expects($this->once())->method('isWritable')->willReturn(true); |
| 176 | + $input->expects($this->exactly(2))->method('write')->withConsecutive(array('hello'), array('world')); |
157 | 177 | $input->expects($this->never())->method('end'); |
158 | 178 |
|
159 | 179 | $promise = Timer\resolve(0.001, $this->loop)->then(function () use ($input) { |
@@ -185,7 +205,7 @@ public function testForwardsDataAndEndOncePromiseResolves() |
185 | 205 | { |
186 | 206 | $input = $this->getMockBuilder('React\Stream\WritableStreamInterface')->getMock(); |
187 | 207 | $input->expects($this->once())->method('isWritable')->willReturn(true); |
188 | | - $input->expects($this->once())->method('write')->with('helloworld!'); |
| 208 | + $input->expects($this->exactly(3))->method('write')->withConsecutive(array('hello'), array('world'), array('!')); |
189 | 209 | $input->expects($this->once())->method('end'); |
190 | 210 |
|
191 | 211 | $promise = Timer\resolve(0.001, $this->loop)->then(function () use ($input) { |
@@ -247,6 +267,20 @@ public function testEmitsErrorAndClosesWhenInputEmitsError() |
247 | 267 | $this->assertFalse($stream->isWritable()); |
248 | 268 | } |
249 | 269 |
|
| 270 | + public function testDoesNotEmitDrainWhenStreamBufferExceededAfterForwardingData() |
| 271 | + { |
| 272 | + $input = $this->getMockBuilder('React\Stream\WritableStreamInterface')->getMock(); |
| 273 | + $input->expects($this->once())->method('isWritable')->willReturn(true); |
| 274 | + $input->expects($this->once())->method('write')->with('hello')->willReturn(false); |
| 275 | + |
| 276 | + $deferred = new Deferred(); |
| 277 | + $stream = Stream\unwrapWritable($deferred->promise()); |
| 278 | + $stream->write('hello'); |
| 279 | + |
| 280 | + $stream->on('drain', $this->expectCallableNever()); |
| 281 | + $deferred->resolve($input); |
| 282 | + } |
| 283 | + |
250 | 284 | public function testEmitsDrainWhenInputEmitsDrain() |
251 | 285 | { |
252 | 286 | $input = new ThroughStream(); |
|
0 commit comments