Skip to content

Commit

Permalink
Fix forward compatibility with upcoming EventLoop releases
Browse files Browse the repository at this point in the history
  • Loading branch information
clue committed Dec 22, 2017
1 parent 4e07a00 commit 279ffd1
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 9 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"license": "MIT",
"require": {
"php": ">=5.3.8",
"react/event-loop": "^1.0 || ^0.5 || ^0.4 || ^0.3",
"react/event-loop": "^1.0 || ^0.5 || ^0.4 || ^0.3.5",
"evenement/evenement": "^3.0 || ^2.0 || ^1.0"
},
"require-dev": {
Expand Down
58 changes: 50 additions & 8 deletions tests/DuplexResourceStreamIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,52 @@
namespace React\Tests\Stream;

use React\Stream\DuplexResourceStream;
use React\EventLoop as rel;
use React\Stream\ReadableResourceStream;
use React\EventLoop\ExtEventLoop;
use React\EventLoop\ExtLibeventLoop;
use React\EventLoop\ExtLibevLoop;
use React\EventLoop\LoopInterface;
use React\EventLoop\LibEventLoop;
use React\EventLoop\LibEvLoop;
use React\EventLoop\StreamSelectLoop;

class DuplexResourceStreamIntegrationTest extends TestCase
{
public function loopProvider()
{
return array(
array(function() { return true; }, function() { return new rel\StreamSelectLoop; }),
array(function() { return function_exists('event_base_new'); }, function() { return new rel\LibEventLoop; }),
array(function() { return class_exists('libev\EventLoop'); }, function() { return new rel\LibEvLoop; }),
array(function() { return class_exists('EventBase'); }, function() { return new rel\ExtEventLoop; })
array(
function() {
return true;
},
function () {
return new StreamSelectLoop();
}
),
array(
function () {
return function_exists('event_base_new');
},
function () {
return class_exists('React\EventLoop\ExtLibeventLoop') ? new ExtLibeventLoop() : LibEventLoop();
}
),
array(
function () {
return class_exists('libev\EventLoop');
},
function () {
return class_exists('React\EventLoop\ExtLibevLoop') ? new ExtLibevLoop() : new LibEvLoop();
}
),
array(
function () {
return class_exists('EventBase') && class_exists('React\EventLoop\ExtEventLoop');
},
function () {
return new ExtEventLoop();
}
)
);
}

Expand Down Expand Up @@ -44,9 +78,9 @@ public function testBufferReadsLargeChunks($condition, $loopFactory)

$streamA->write($testString);

$loop->tick();
$loop->tick();
$loop->tick();
$this->loopTick($loop);
$this->loopTick($loop);
$this->loopTick($loop);

$streamA->close();
$streamB->close();
Expand Down Expand Up @@ -307,4 +341,12 @@ public function testReadsNothingFromProcessPipeWithNoOutput($condition, $loopFac

$loop->run();
}

private function loopTick(LoopInterface $loop)
{
$loop->addTimer(0, function () use ($loop) {
$loop->stop();
});
$loop->run();
}
}

0 comments on commit 279ffd1

Please sign in to comment.