Skip to content

Commit 28b5337

Browse files
cluejmikola
authored andcommitted
Support React v0.3 and PHP 5.3
1 parent 6e2578c commit 28b5337

4 files changed

Lines changed: 27 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: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
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|~2.0",
9+
"react/event-loop": "0.3.*|0.4.*",
10+
"react/stream": "0.3.*|0.4.*"
1111
},
1212
"autoload": {
1313
"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: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public function testGetTermSignalWhenRunning($process)
6767

6868
public function testProcessWithDefaultCwdAndEnv()
6969
{
70-
$cmd = PHP_BINARY . ' -r ' . escapeshellarg('echo getcwd(), PHP_EOL, count($_SERVER), PHP_EOL;');
70+
$cmd = $this->cmd('echo getcwd(), PHP_EOL, count($_SERVER), PHP_EOL;');
7171

7272
$loop = $this->createLoop();
7373
$process = new Process($cmd);
@@ -95,7 +95,7 @@ public function testProcessWithDefaultCwdAndEnv()
9595

9696
public function testProcessWithCwd()
9797
{
98-
$cmd = PHP_BINARY . ' -r ' . escapeshellarg('echo getcwd(), PHP_EOL;');
98+
$cmd = $this->cmd('echo getcwd(), PHP_EOL;');
9999

100100
$loop = $this->createLoop();
101101
$process = new Process($cmd, '/');
@@ -120,7 +120,7 @@ public function testProcessWithEnv()
120120
$this->markTestSkipped('Cannot execute PHP processes with custom environments on Travis CI.');
121121
}
122122

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

125125
$loop = $this->createLoop();
126126
$process = new Process($cmd, null, array('foo' => 'bar'));
@@ -267,21 +267,22 @@ public function testTerminateWithStopAndContinueSignalsUsingEventLoop()
267267
$termSignal = func_get_arg(1);
268268
});
269269

270-
$loop->addTimer(0.001, function(Timer $timer) use ($process) {
270+
$that = $this;
271+
$loop->addTimer(0.001, function(Timer $timer) use ($process, $that) {
271272
$process->start($timer->getLoop());
272273
$process->terminate(SIGSTOP);
273274

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

280281
$process->terminate(SIGCONT);
281282

282-
$this->assertSoon(function() use ($process) {
283-
$this->assertFalse($process->isStopped());
284-
$this->assertEquals(SIGSTOP, $process->getStopSignal());
283+
$that->assertSoon(function() use ($process, $that) {
284+
$that->assertFalse($process->isStopped());
285+
$that->assertEquals(SIGSTOP, $process->getStopSignal());
285286
});
286287
});
287288

@@ -325,4 +326,9 @@ public function assertSoon(\Closure $callback, $timeout = 20000, $interval = 200
325326
usleep($interval);
326327
}
327328
}
329+
330+
private function cmd($code)
331+
{
332+
return (defined('PHP_BINARY') ? PHP_BINARY : 'php') . ' -r ' . escapeshellarg($code);
333+
}
328334
}

0 commit comments

Comments
 (0)