44
55use React \ChildProcess \Process ;
66use React \EventLoop \Timer \Timer ;
7+ use SebastianBergmann \Environment \Runtime ;
78
89abstract 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