Skip to content

Commit 82e0919

Browse files
authored
Merge pull request #2 from WyriHaximus-labs/forward-compatibility
Forward compatibility with stream 1.0, 0.7, 0.6, and 0.5
2 parents 48ee7c9 + a60eba9 commit 82e0919

7 files changed

Lines changed: 55 additions & 58 deletions

File tree

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
},
1717
"require": {
1818
"php": ">=5.3",
19-
"react/stream": "^0.4 || ^0.3",
19+
"react/stream": "^1.0 || ^0.7 || ^0.6 || ^0.5 || ^0.4 || ^0.3",
2020
"react/promise": "^2.1 || ^1.2"
2121
},
2222
"require-dev": {
23-
"react/event-loop": "^0.4 || ^0.3",
23+
"react/event-loop": "^1.0 || ^0.5 || ^0.4 || ^0.3",
2424
"react/promise-timer": "^1.0",
2525
"clue/block-react": "^1.0",
2626
"phpunit/phpunit": "^4.8"

src/functions.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* Creates a `Promise` which resolves with the stream data buffer
1313
*
1414
* @param ReadableStreamInterface $stream
15-
* @return CancellablePromiseInterface Promise<string, Exception>
15+
* @return Promise\CancellablePromiseInterface Promise<string, Exception>
1616
*/
1717
function buffer(ReadableStreamInterface $stream)
1818
{
@@ -53,7 +53,7 @@ function buffer(ReadableStreamInterface $stream)
5353
*
5454
* @param ReadableStreamInterface|WritableStreamInterface $stream
5555
* @param string $event
56-
* @return CancellablePromiseInterface Promise<mixed, Exception>
56+
* @return Promise\CancellablePromiseInterface Promise<mixed, Exception>
5757
*/
5858
function first(EventEmitterInterface $stream, $event = 'data')
5959
{
@@ -71,7 +71,7 @@ function first(EventEmitterInterface $stream, $event = 'data')
7171
}
7272

7373
return new Promise\Promise(function ($resolve, $reject) use ($stream, $event, &$listener) {
74-
$listener = function ($data) use ($stream, $event, &$listener, $resolve) {
74+
$listener = function ($data = null) use ($stream, $event, &$listener, $resolve) {
7575
$stream->removeListener($event, $listener);
7676
$resolve($data);
7777
};
@@ -92,7 +92,7 @@ function first(EventEmitterInterface $stream, $event = 'data')
9292
*
9393
* @param ReadableStreamInterface|WritableStreamInterface $stream
9494
* @param string $event
95-
* @return CancellablePromiseInterface Promise<string, Exception>
95+
* @return Promise\CancellablePromiseInterface Promise<string, Exception>
9696
*/
9797
function all(EventEmitterInterface $stream, $event = 'data')
9898
{

tests/AllTest.php

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
<?php
22

33
use React\Promise\Stream;
4-
use React\Stream\ReadableStream;
5-
use React\Stream\WritableStream;
4+
use React\Stream\ThroughStream;
65

76
class AllTest extends TestCase
87
{
98
public function testClosedStreamResolvesWithEmptyBuffer()
109
{
11-
$stream = new ReadableStream();
10+
$stream = new ThroughStream();
1211
$stream->close();
1312

1413
$promise = Stream\all($stream);
@@ -18,7 +17,7 @@ public function testClosedStreamResolvesWithEmptyBuffer()
1817

1918
public function testClosedWritableStreamResolvesWithEmptyBuffer()
2019
{
21-
$stream = new WritableStream();
20+
$stream = new ThroughStream();
2221
$stream->close();
2322

2423
$promise = Stream\all($stream);
@@ -28,7 +27,7 @@ public function testClosedWritableStreamResolvesWithEmptyBuffer()
2827

2928
public function testPendingStreamWillNotResolve()
3029
{
31-
$stream = new ReadableStream();
30+
$stream = new ThroughStream();
3231

3332
$promise = Stream\all($stream);
3433

@@ -37,7 +36,7 @@ public function testPendingStreamWillNotResolve()
3736

3837
public function testClosingStreamResolvesWithEmptyBuffer()
3938
{
40-
$stream = new ReadableStream();
39+
$stream = new ThroughStream();
4140
$promise = Stream\all($stream);
4241

4342
$stream->close();
@@ -47,7 +46,7 @@ public function testClosingStreamResolvesWithEmptyBuffer()
4746

4847
public function testClosingWritableStreamResolvesWithEmptyBuffer()
4948
{
50-
$stream = new WritableStream();
49+
$stream = new ThroughStream();
5150
$promise = Stream\all($stream);
5251

5352
$stream->close();
@@ -57,7 +56,7 @@ public function testClosingWritableStreamResolvesWithEmptyBuffer()
5756

5857
public function testEmittingDataOnStreamResolvesWithArrayOfData()
5958
{
60-
$stream = new ReadableStream();
59+
$stream = new ThroughStream();
6160
$promise = Stream\all($stream);
6261

6362
$stream->emit('data', array('hello', $stream));
@@ -69,7 +68,7 @@ public function testEmittingDataOnStreamResolvesWithArrayOfData()
6968

7069
public function testEmittingErrorOnStreamRejects()
7170
{
72-
$stream = new ReadableStream();
71+
$stream = new ThroughStream();
7372
$promise = Stream\all($stream);
7473

7574
$stream->emit('error', array(new \RuntimeException('test')));
@@ -79,7 +78,7 @@ public function testEmittingErrorOnStreamRejects()
7978

8079
public function testEmittingErrorAfterEmittingDataOnStreamRejects()
8180
{
82-
$stream = new ReadableStream();
81+
$stream = new ThroughStream();
8382
$promise = Stream\all($stream);
8483

8584
$stream->emit('data', array('hello', $stream));
@@ -90,7 +89,7 @@ public function testEmittingErrorAfterEmittingDataOnStreamRejects()
9089

9190
public function testCancelPendingStreamWillReject()
9291
{
93-
$stream = new ReadableStream();
92+
$stream = new ThroughStream();
9493

9594
$promise = Stream\all($stream);
9695

tests/BufferTest.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<?php
22

33
use React\Promise\Stream;
4-
use React\Stream\ReadableStream;
4+
use React\Stream\ThroughStream;
55

66
class BufferTest extends TestCase
77
{
88
public function testClosedStreamResolvesWithEmptyBuffer()
99
{
10-
$stream = new ReadableStream();
10+
$stream = new ThroughStream();
1111
$stream->close();
1212

1313
$promise = Stream\buffer($stream);
@@ -17,7 +17,7 @@ public function testClosedStreamResolvesWithEmptyBuffer()
1717

1818
public function testPendingStreamWillNotResolve()
1919
{
20-
$stream = new ReadableStream();
20+
$stream = new ThroughStream();
2121

2222
$promise = Stream\buffer($stream);
2323

@@ -26,7 +26,7 @@ public function testPendingStreamWillNotResolve()
2626

2727
public function testClosingStreamResolvesWithEmptyBuffer()
2828
{
29-
$stream = new ReadableStream();
29+
$stream = new ThroughStream();
3030
$promise = Stream\buffer($stream);
3131

3232
$stream->close();
@@ -36,7 +36,7 @@ public function testClosingStreamResolvesWithEmptyBuffer()
3636

3737
public function testEmittingDataOnStreamResolvesWithConcatenatedData()
3838
{
39-
$stream = new ReadableStream();
39+
$stream = new ThroughStream();
4040
$promise = Stream\buffer($stream);
4141

4242
$stream->emit('data', array('hello', $stream));
@@ -48,7 +48,7 @@ public function testEmittingDataOnStreamResolvesWithConcatenatedData()
4848

4949
public function testEmittingErrorOnStreamRejects()
5050
{
51-
$stream = new ReadableStream();
51+
$stream = new ThroughStream();
5252
$promise = Stream\buffer($stream);
5353

5454
$stream->emit('error', array(new \RuntimeException('test')));
@@ -58,7 +58,7 @@ public function testEmittingErrorOnStreamRejects()
5858

5959
public function testEmittingErrorAfterEmittingDataOnStreamRejects()
6060
{
61-
$stream = new ReadableStream();
61+
$stream = new ThroughStream();
6262
$promise = Stream\buffer($stream);
6363

6464
$stream->emit('data', array('hello', $stream));
@@ -69,7 +69,7 @@ public function testEmittingErrorAfterEmittingDataOnStreamRejects()
6969

7070
public function testCancelPendingStreamWillReject()
7171
{
72-
$stream = new ReadableStream();
72+
$stream = new ThroughStream();
7373

7474
$promise = Stream\buffer($stream);
7575

tests/FirstTest.php

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
<?php
22

33
use React\Promise\Stream;
4-
use React\Stream\ReadableStream;
5-
use React\Stream\WritableStream;
4+
use React\Stream\ThroughStream;
65

76
class FirstTest extends TestCase
87
{
98
public function testClosedReadableStreamRejects()
109
{
11-
$stream = new ReadableStream();
10+
$stream = new ThroughStream();
1211
$stream->close();
1312

1413
$promise = Stream\first($stream);
@@ -18,7 +17,7 @@ public function testClosedReadableStreamRejects()
1817

1918
public function testClosedWritableStreamRejects()
2019
{
21-
$stream = new WritableStream();
20+
$stream = new ThroughStream();
2221
$stream->close();
2322

2423
$promise = Stream\first($stream);
@@ -28,7 +27,7 @@ public function testClosedWritableStreamRejects()
2827

2928
public function testPendingStreamWillNotResolve()
3029
{
31-
$stream = new ReadableStream();
30+
$stream = new ThroughStream();
3231

3332
$promise = Stream\first($stream);
3433

@@ -37,7 +36,7 @@ public function testPendingStreamWillNotResolve()
3736

3837
public function testClosingStreamRejects()
3938
{
40-
$stream = new ReadableStream();
39+
$stream = new ThroughStream();
4140
$promise = Stream\first($stream);
4241

4342
$stream->close();
@@ -47,7 +46,7 @@ public function testClosingStreamRejects()
4746

4847
public function testClosingWritableStreamRejects()
4948
{
50-
$stream = new WritableStream();
49+
$stream = new ThroughStream();
5150
$promise = Stream\first($stream);
5251

5352
$stream->close();
@@ -57,7 +56,7 @@ public function testClosingWritableStreamRejects()
5756

5857
public function testClosingStreamResolvesWhenWaitingForCloseEvent()
5958
{
60-
$stream = new ReadableStream();
59+
$stream = new ThroughStream();
6160
$promise = Stream\first($stream, 'close');
6261

6362
$stream->close();
@@ -67,7 +66,7 @@ public function testClosingStreamResolvesWhenWaitingForCloseEvent()
6766

6867
public function testEmittingDataOnStreamResolvesWithFirstEvent()
6968
{
70-
$stream = new ReadableStream();
69+
$stream = new ThroughStream();
7170
$promise = Stream\first($stream);
7271

7372
$stream->emit('data', array('hello', $stream));
@@ -79,7 +78,7 @@ public function testEmittingDataOnStreamResolvesWithFirstEvent()
7978

8079
public function testEmittingErrorOnStreamDoesNothing()
8180
{
82-
$stream = new ReadableStream();
81+
$stream = new ThroughStream();
8382
$promise = Stream\first($stream);
8483

8584
$stream->emit('error', array(new \RuntimeException('test')));
@@ -89,7 +88,7 @@ public function testEmittingErrorOnStreamDoesNothing()
8988

9089
public function testEmittingErrorResolvesWhenWaitingForErrorEvent()
9190
{
92-
$stream = new ReadableStream();
91+
$stream = new ThroughStream();
9392
$promise = Stream\first($stream, 'error');
9493

9594
$stream->emit('error', array(new \RuntimeException('test')));
@@ -99,7 +98,7 @@ public function testEmittingErrorResolvesWhenWaitingForErrorEvent()
9998

10099
public function testCancelPendingStreamWillReject()
101100
{
102-
$stream = new ReadableStream();
101+
$stream = new ThroughStream();
103102

104103
$promise = Stream\first($stream);
105104

0 commit comments

Comments
 (0)