Skip to content

Commit 8bbced8

Browse files
authored
Merge pull request #128 from clue-labs/loop
Fix test suite forward compatibility with upcoming EventLoop releases
2 parents 4e07a00 + 279ffd1 commit 8bbced8

File tree

2 files changed

+51
-9
lines changed

2 files changed

+51
-9
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"license": "MIT",
66
"require": {
77
"php": ">=5.3.8",
8-
"react/event-loop": "^1.0 || ^0.5 || ^0.4 || ^0.3",
8+
"react/event-loop": "^1.0 || ^0.5 || ^0.4 || ^0.3.5",
99
"evenement/evenement": "^3.0 || ^2.0 || ^1.0"
1010
},
1111
"require-dev": {

tests/DuplexResourceStreamIntegrationTest.php

Lines changed: 50 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,52 @@
33
namespace React\Tests\Stream;
44

55
use React\Stream\DuplexResourceStream;
6-
use React\EventLoop as rel;
76
use React\Stream\ReadableResourceStream;
7+
use React\EventLoop\ExtEventLoop;
8+
use React\EventLoop\ExtLibeventLoop;
9+
use React\EventLoop\ExtLibevLoop;
10+
use React\EventLoop\LoopInterface;
11+
use React\EventLoop\LibEventLoop;
12+
use React\EventLoop\LibEvLoop;
13+
use React\EventLoop\StreamSelectLoop;
814

915
class DuplexResourceStreamIntegrationTest extends TestCase
1016
{
1117
public function loopProvider()
1218
{
1319
return array(
14-
array(function() { return true; }, function() { return new rel\StreamSelectLoop; }),
15-
array(function() { return function_exists('event_base_new'); }, function() { return new rel\LibEventLoop; }),
16-
array(function() { return class_exists('libev\EventLoop'); }, function() { return new rel\LibEvLoop; }),
17-
array(function() { return class_exists('EventBase'); }, function() { return new rel\ExtEventLoop; })
20+
array(
21+
function() {
22+
return true;
23+
},
24+
function () {
25+
return new StreamSelectLoop();
26+
}
27+
),
28+
array(
29+
function () {
30+
return function_exists('event_base_new');
31+
},
32+
function () {
33+
return class_exists('React\EventLoop\ExtLibeventLoop') ? new ExtLibeventLoop() : LibEventLoop();
34+
}
35+
),
36+
array(
37+
function () {
38+
return class_exists('libev\EventLoop');
39+
},
40+
function () {
41+
return class_exists('React\EventLoop\ExtLibevLoop') ? new ExtLibevLoop() : new LibEvLoop();
42+
}
43+
),
44+
array(
45+
function () {
46+
return class_exists('EventBase') && class_exists('React\EventLoop\ExtEventLoop');
47+
},
48+
function () {
49+
return new ExtEventLoop();
50+
}
51+
)
1852
);
1953
}
2054

@@ -44,9 +78,9 @@ public function testBufferReadsLargeChunks($condition, $loopFactory)
4478

4579
$streamA->write($testString);
4680

47-
$loop->tick();
48-
$loop->tick();
49-
$loop->tick();
81+
$this->loopTick($loop);
82+
$this->loopTick($loop);
83+
$this->loopTick($loop);
5084

5185
$streamA->close();
5286
$streamB->close();
@@ -307,4 +341,12 @@ public function testReadsNothingFromProcessPipeWithNoOutput($condition, $loopFac
307341

308342
$loop->run();
309343
}
344+
345+
private function loopTick(LoopInterface $loop)
346+
{
347+
$loop->addTimer(0, function () use ($loop) {
348+
$loop->stop();
349+
});
350+
$loop->run();
351+
}
310352
}

0 commit comments

Comments
 (0)