Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Fix forward compatibility with upcoming EventLoop releases
  • Loading branch information
clue committed Dec 22, 2017
commit 662d4db3bdf58f6adddbb9a9d4181a6f96577201
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"require": {
"php": ">=5.3.0",
"evenement/evenement": "^3.0 || ^2.0 || ^1.0",
"react/event-loop": "^1.0 || ^0.5 || ^0.4 || ^0.3",
"react/event-loop": "^1.0 || ^0.5 || ^0.4 || ^0.3.5",
"react/stream": "^1.0 || ^0.7.6"
},
"require-dev": {
Expand Down
3 changes: 1 addition & 2 deletions src/Process.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Evenement\EventEmitter;
use React\EventLoop\LoopInterface;
use React\EventLoop\Timer\TimerInterface;
use React\Stream\ReadableResourceStream;
use React\Stream\WritableResourceStream;

Expand Down Expand Up @@ -116,7 +115,7 @@ public function start(LoopInterface $loop, $interval = 0.1)
return;
}

$loop->addPeriodicTimer($interval, function (TimerInterface $timer) use ($that, $loop) {
$loop->addPeriodicTimer($interval, function ($timer) use ($that, $loop) {
if (!$that->isRunning()) {
$that->close();
$loop->cancelTimer($timer);
Expand Down
42 changes: 23 additions & 19 deletions tests/AbstractProcessTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@

namespace React\Tests\ChildProcess;

use React\ChildProcess\Process;
use React\EventLoop\Timer\Timer;
use PHPUnit\Framework\ExpectationFailedException;
use PHPUnit\Framework\TestCase;
use React\ChildProcess\Process;
use SebastianBergmann\Environment\Runtime;

abstract class AbstractProcessTest extends TestCase
Expand Down Expand Up @@ -156,8 +155,8 @@ public function testProcessWithDefaultCwdAndEnv()

$output = '';

$loop->addTimer(0.001, function(Timer $timer) use ($process, &$output) {
$process->start($timer->getLoop());
$loop->addTimer(0.001, function () use ($process, $loop, &$output) {
$process->start($loop);
$process->stdout->on('data', function () use (&$output) {
$output .= func_get_arg(0);
});
Expand All @@ -184,8 +183,8 @@ public function testProcessWithCwd()

$output = '';

$loop->addTimer(0.001, function(Timer $timer) use ($process, &$output) {
$process->start($timer->getLoop());
$loop->addTimer(0.001, function () use ($process, $loop, &$output) {
$process->start($loop);
$process->stdout->on('data', function () use (&$output) {
$output .= func_get_arg(0);
});
Expand All @@ -209,8 +208,8 @@ public function testProcessWithEnv()

$output = '';

$loop->addTimer(0.001, function(Timer $timer) use ($process, &$output) {
$process->start($timer->getLoop());
$loop->addTimer(0.001, function () use ($process, $loop, &$output) {
$process->start($loop);
$process->stdout->on('data', function () use (&$output) {
$output .= func_get_arg(0);
});
Expand All @@ -236,8 +235,8 @@ public function testStartAndAllowProcessToExitSuccessfullyUsingEventLoop()
$termSignal = func_get_arg(1);
});

$loop->addTimer(0.001, function(Timer $timer) use ($process) {
$process->start($timer->getLoop());
$loop->addTimer(0.001, function () use ($process, $loop) {
$process->start($loop);
});

$loop->run();
Expand All @@ -261,8 +260,8 @@ public function testStartInvalidProcess()

$output = '';

$loop->addTimer(0.001, function(Timer $timer) use ($process, &$output) {
$process->start($timer->getLoop());
$loop->addTimer(0.001, function () use ($process, $loop, &$output) {
$process->start($loop);
$process->stderr->on('data', function () use (&$output) {
$output .= func_get_arg(0);
});
Expand Down Expand Up @@ -338,8 +337,8 @@ public function testTerminateWithDefaultTermSignalUsingEventLoop()
$termSignal = func_get_arg(1);
});

$loop->addTimer(0.001, function(Timer $timer) use ($process) {
$process->start($timer->getLoop());
$loop->addTimer(0.001, function () use ($process, $loop) {
$process->start($loop);
$process->terminate();
});

Expand Down Expand Up @@ -379,19 +378,19 @@ public function testTerminateWithStopAndContinueSignalsUsingEventLoop()
});

$that = $this;
$loop->addTimer(0.001, function(Timer $timer) use ($process, $that) {
$process->start($timer->getLoop());
$loop->addTimer(0.001, function () use ($process, $loop, $that) {
$process->start($loop);
$process->terminate(SIGSTOP);

$that->assertSoon(function() use ($process, $that) {
$that->assertSoon(function () use ($process, $that) {
$that->assertTrue($process->isStopped());
$that->assertTrue($process->isRunning());
$that->assertEquals(SIGSTOP, $process->getStopSignal());
});

$process->terminate(SIGCONT);

$that->assertSoon(function() use ($process, $that) {
$that->assertSoon(function () use ($process, $that) {
$that->assertFalse($process->isStopped());
$that->assertEquals(SIGSTOP, $process->getStopSignal());
});
Expand Down Expand Up @@ -444,7 +443,12 @@ function ($output) use (&$stdErr) {
}
);

$loop->tick();
// tick loop once
$loop->addTimer(0, function () use ($loop) {
$loop->stop();
});
$loop->run();

sleep(1); // comment this line out and it works fine

$loop->run();
Expand Down
18 changes: 18 additions & 0 deletions tests/ExtLibevLoopProcessTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace React\Tests\ChildProcess;

use React\EventLoop\ExtLibevLoop;
use React\EventLoop\LibEvLoop;

class ExtLibevLoopProcessTest extends AbstractProcessTest
{
public function createLoop()
{
if (!class_exists('libev\EventLoop')) {
$this->markTestSkipped('ext-libev is not installed.');
}

return class_exists('React\EventLoop\ExtLibevLoop') ? new ExtLibevLoop() : new LibEvLoop();
}
}
18 changes: 18 additions & 0 deletions tests/ExtLibeventLoopProcessTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace React\Tests\ChildProcess;

use React\EventLoop\ExtLibeventLoop;
use React\EventLoop\LibEventLoop;

class ExtLibeventLoopProcessTest extends AbstractProcessTest
{
public function createLoop()
{
if (!function_exists('event_base_new')) {
$this->markTestSkipped('ext-libevent is not installed.');
}

return class_exists('React\EventLoop\ExtLibeventLoop') ? new ExtLibeventLoop() : new LibEventLoop();
}
}
17 changes: 0 additions & 17 deletions tests/LibEvLoopProcessTest.php

This file was deleted.

17 changes: 0 additions & 17 deletions tests/LibEventLoopProcessTest.php

This file was deleted.