Skip to content

Commit 36f4b29

Browse files
committed
Merge pull request #4
2 parents 6e2578c + cbb0ead commit 36f4b29

4 files changed

Lines changed: 33 additions & 19 deletions

File tree

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
language: php
22

33
php:
4+
- 5.3
45
- 5.4
56
- 5.5
67
- 5.6

composer.json

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@
44
"keywords": ["process"],
55
"license": "MIT",
66
"require": {
7-
"php": ">=5.4.0",
8-
"evenement/evenement": "~2.0",
9-
"react/event-loop": "0.4.*",
10-
"react/stream": "0.4.*"
7+
"php": ">=5.3.0",
8+
"evenement/evenement": "~1.0",
9+
"react/event-loop": "0.3.*",
10+
"react/stream": "0.3.*"
11+
},
12+
"require-dev": {
13+
"sebastian/environment": "~1.0"
1114
},
1215
"autoload": {
1316
"psr-4": { "React\\ChildProcess\\": "src" }

src/Process.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,12 @@ public function start(LoopInterface $loop, $interval = 0.1)
110110
stream_set_blocking($pipe, 0);
111111
}
112112

113-
$loop->addPeriodicTimer($interval, function (Timer $timer) {
114-
if (!$this->isRunning()) {
115-
$this->close();
113+
$that = $this;
114+
$loop->addPeriodicTimer($interval, function (Timer $timer) use ($that) {
115+
if (!$that->isRunning()) {
116+
$that->close();
116117
$timer->cancel();
117-
$this->emit('exit', array($this->getExitCode(), $this->getTermSignal()));
118+
$that->emit('exit', array($that->getExitCode(), $that->getTermSignal()));
118119
}
119120
});
120121
}

tests/AbstractProcessTest.php

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use React\ChildProcess\Process;
66
use React\EventLoop\Timer\Timer;
7+
use SebastianBergmann\Environment\Runtime;
78

89
abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase
910
{
@@ -67,7 +68,7 @@ public function testGetTermSignalWhenRunning($process)
6768

6869
public function testProcessWithDefaultCwdAndEnv()
6970
{
70-
$cmd = PHP_BINARY . ' -r ' . escapeshellarg('echo getcwd(), PHP_EOL, count($_SERVER), PHP_EOL;');
71+
$cmd = $this->getPhpBinary() . ' -r ' . escapeshellarg('echo getcwd(), PHP_EOL, count($_SERVER), PHP_EOL;');
7172

7273
$loop = $this->createLoop();
7374
$process = new Process($cmd);
@@ -95,7 +96,7 @@ public function testProcessWithDefaultCwdAndEnv()
9596

9697
public function testProcessWithCwd()
9798
{
98-
$cmd = PHP_BINARY . ' -r ' . escapeshellarg('echo getcwd(), PHP_EOL;');
99+
$cmd = $this->getPhpBinary() . ' -r ' . escapeshellarg('echo getcwd(), PHP_EOL;');
99100

100101
$loop = $this->createLoop();
101102
$process = new Process($cmd, '/');
@@ -120,7 +121,7 @@ public function testProcessWithEnv()
120121
$this->markTestSkipped('Cannot execute PHP processes with custom environments on Travis CI.');
121122
}
122123

123-
$cmd = PHP_BINARY . ' -r ' . escapeshellarg('echo getenv("foo"), PHP_EOL;');
124+
$cmd = $this->getPhpBinary() . ' -r ' . escapeshellarg('echo getenv("foo"), PHP_EOL;');
124125

125126
$loop = $this->createLoop();
126127
$process = new Process($cmd, null, array('foo' => 'bar'));
@@ -267,21 +268,22 @@ public function testTerminateWithStopAndContinueSignalsUsingEventLoop()
267268
$termSignal = func_get_arg(1);
268269
});
269270

270-
$loop->addTimer(0.001, function(Timer $timer) use ($process) {
271+
$that = $this;
272+
$loop->addTimer(0.001, function(Timer $timer) use ($process, $that) {
271273
$process->start($timer->getLoop());
272274
$process->terminate(SIGSTOP);
273275

274-
$this->assertSoon(function() use ($process) {
275-
$this->assertTrue($process->isStopped());
276-
$this->assertTrue($process->isRunning());
277-
$this->assertEquals(SIGSTOP, $process->getStopSignal());
276+
$that->assertSoon(function() use ($process, $that) {
277+
$that->assertTrue($process->isStopped());
278+
$that->assertTrue($process->isRunning());
279+
$that->assertEquals(SIGSTOP, $process->getStopSignal());
278280
});
279281

280282
$process->terminate(SIGCONT);
281283

282-
$this->assertSoon(function() use ($process) {
283-
$this->assertFalse($process->isStopped());
284-
$this->assertEquals(SIGSTOP, $process->getStopSignal());
284+
$that->assertSoon(function() use ($process, $that) {
285+
$that->assertFalse($process->isStopped());
286+
$that->assertEquals(SIGSTOP, $process->getStopSignal());
285287
});
286288
});
287289

@@ -325,4 +327,11 @@ public function assertSoon(\Closure $callback, $timeout = 20000, $interval = 200
325327
usleep($interval);
326328
}
327329
}
330+
331+
private function getPhpBinary()
332+
{
333+
$runtime = new Runtime();
334+
335+
return $runtime->getBinary();
336+
}
328337
}

0 commit comments

Comments
 (0)