diff --git a/.travis.yml b/.travis.yml index d2fb756..3fd6699 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,7 @@ language: php php: + - 5.3 - 5.4 - 5.5 - 5.6 diff --git a/composer.json b/composer.json index 50f166e..9a79023 100644 --- a/composer.json +++ b/composer.json @@ -4,10 +4,13 @@ "keywords": ["process"], "license": "MIT", "require": { - "php": ">=5.4.0", - "evenement/evenement": "~2.0", - "react/event-loop": "0.4.*", - "react/stream": "0.4.*" + "php": ">=5.3.0", + "evenement/evenement": "~1.0", + "react/event-loop": "0.3.*", + "react/stream": "0.3.*" + }, + "require-dev": { + "sebastian/environment": "~1.0" }, "autoload": { "psr-4": { "React\\ChildProcess\\": "src" } diff --git a/src/Process.php b/src/Process.php index b6cb8d9..a4405e8 100644 --- a/src/Process.php +++ b/src/Process.php @@ -110,11 +110,12 @@ public function start(LoopInterface $loop, $interval = 0.1) stream_set_blocking($pipe, 0); } - $loop->addPeriodicTimer($interval, function (Timer $timer) { - if (!$this->isRunning()) { - $this->close(); + $that = $this; + $loop->addPeriodicTimer($interval, function (Timer $timer) use ($that) { + if (!$that->isRunning()) { + $that->close(); $timer->cancel(); - $this->emit('exit', array($this->getExitCode(), $this->getTermSignal())); + $that->emit('exit', array($that->getExitCode(), $that->getTermSignal())); } }); } diff --git a/tests/AbstractProcessTest.php b/tests/AbstractProcessTest.php index 5948209..579e4ea 100644 --- a/tests/AbstractProcessTest.php +++ b/tests/AbstractProcessTest.php @@ -4,6 +4,7 @@ use React\ChildProcess\Process; use React\EventLoop\Timer\Timer; +use SebastianBergmann\Environment\Runtime; abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase { @@ -67,7 +68,7 @@ public function testGetTermSignalWhenRunning($process) public function testProcessWithDefaultCwdAndEnv() { - $cmd = PHP_BINARY . ' -r ' . escapeshellarg('echo getcwd(), PHP_EOL, count($_SERVER), PHP_EOL;'); + $cmd = $this->getPhpBinary() . ' -r ' . escapeshellarg('echo getcwd(), PHP_EOL, count($_SERVER), PHP_EOL;'); $loop = $this->createLoop(); $process = new Process($cmd); @@ -95,7 +96,7 @@ public function testProcessWithDefaultCwdAndEnv() public function testProcessWithCwd() { - $cmd = PHP_BINARY . ' -r ' . escapeshellarg('echo getcwd(), PHP_EOL;'); + $cmd = $this->getPhpBinary() . ' -r ' . escapeshellarg('echo getcwd(), PHP_EOL;'); $loop = $this->createLoop(); $process = new Process($cmd, '/'); @@ -120,7 +121,7 @@ public function testProcessWithEnv() $this->markTestSkipped('Cannot execute PHP processes with custom environments on Travis CI.'); } - $cmd = PHP_BINARY . ' -r ' . escapeshellarg('echo getenv("foo"), PHP_EOL;'); + $cmd = $this->getPhpBinary() . ' -r ' . escapeshellarg('echo getenv("foo"), PHP_EOL;'); $loop = $this->createLoop(); $process = new Process($cmd, null, array('foo' => 'bar')); @@ -267,21 +268,22 @@ public function testTerminateWithStopAndContinueSignalsUsingEventLoop() $termSignal = func_get_arg(1); }); - $loop->addTimer(0.001, function(Timer $timer) use ($process) { + $that = $this; + $loop->addTimer(0.001, function(Timer $timer) use ($process, $that) { $process->start($timer->getLoop()); $process->terminate(SIGSTOP); - $this->assertSoon(function() use ($process) { - $this->assertTrue($process->isStopped()); - $this->assertTrue($process->isRunning()); - $this->assertEquals(SIGSTOP, $process->getStopSignal()); + $that->assertSoon(function() use ($process, $that) { + $that->assertTrue($process->isStopped()); + $that->assertTrue($process->isRunning()); + $that->assertEquals(SIGSTOP, $process->getStopSignal()); }); $process->terminate(SIGCONT); - $this->assertSoon(function() use ($process) { - $this->assertFalse($process->isStopped()); - $this->assertEquals(SIGSTOP, $process->getStopSignal()); + $that->assertSoon(function() use ($process, $that) { + $that->assertFalse($process->isStopped()); + $that->assertEquals(SIGSTOP, $process->getStopSignal()); }); }); @@ -325,4 +327,11 @@ public function assertSoon(\Closure $callback, $timeout = 20000, $interval = 200 usleep($interval); } } + + private function getPhpBinary() + { + $runtime = new Runtime(); + + return $runtime->getBinary(); + } }