Skip to content

Commit 662d4db

Browse files
committed
Fix forward compatibility with upcoming EventLoop releases
1 parent 7d1f765 commit 662d4db

7 files changed

Lines changed: 61 additions & 56 deletions

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"require": {
77
"php": ">=5.3.0",
88
"evenement/evenement": "^3.0 || ^2.0 || ^1.0",
9-
"react/event-loop": "^1.0 || ^0.5 || ^0.4 || ^0.3",
9+
"react/event-loop": "^1.0 || ^0.5 || ^0.4 || ^0.3.5",
1010
"react/stream": "^1.0 || ^0.7.6"
1111
},
1212
"require-dev": {

src/Process.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use Evenement\EventEmitter;
66
use React\EventLoop\LoopInterface;
7-
use React\EventLoop\Timer\TimerInterface;
87
use React\Stream\ReadableResourceStream;
98
use React\Stream\WritableResourceStream;
109

@@ -116,7 +115,7 @@ public function start(LoopInterface $loop, $interval = 0.1)
116115
return;
117116
}
118117

119-
$loop->addPeriodicTimer($interval, function (TimerInterface $timer) use ($that, $loop) {
118+
$loop->addPeriodicTimer($interval, function ($timer) use ($that, $loop) {
120119
if (!$that->isRunning()) {
121120
$that->close();
122121
$loop->cancelTimer($timer);

tests/AbstractProcessTest.php

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22

33
namespace React\Tests\ChildProcess;
44

5-
use React\ChildProcess\Process;
6-
use React\EventLoop\Timer\Timer;
75
use PHPUnit\Framework\ExpectationFailedException;
86
use PHPUnit\Framework\TestCase;
7+
use React\ChildProcess\Process;
98
use SebastianBergmann\Environment\Runtime;
109

1110
abstract class AbstractProcessTest extends TestCase
@@ -156,8 +155,8 @@ public function testProcessWithDefaultCwdAndEnv()
156155

157156
$output = '';
158157

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

185184
$output = '';
186185

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

210209
$output = '';
211210

212-
$loop->addTimer(0.001, function(Timer $timer) use ($process, &$output) {
213-
$process->start($timer->getLoop());
211+
$loop->addTimer(0.001, function () use ($process, $loop, &$output) {
212+
$process->start($loop);
214213
$process->stdout->on('data', function () use (&$output) {
215214
$output .= func_get_arg(0);
216215
});
@@ -236,8 +235,8 @@ public function testStartAndAllowProcessToExitSuccessfullyUsingEventLoop()
236235
$termSignal = func_get_arg(1);
237236
});
238237

239-
$loop->addTimer(0.001, function(Timer $timer) use ($process) {
240-
$process->start($timer->getLoop());
238+
$loop->addTimer(0.001, function () use ($process, $loop) {
239+
$process->start($loop);
241240
});
242241

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

262261
$output = '';
263262

264-
$loop->addTimer(0.001, function(Timer $timer) use ($process, &$output) {
265-
$process->start($timer->getLoop());
263+
$loop->addTimer(0.001, function () use ($process, $loop, &$output) {
264+
$process->start($loop);
266265
$process->stderr->on('data', function () use (&$output) {
267266
$output .= func_get_arg(0);
268267
});
@@ -338,8 +337,8 @@ public function testTerminateWithDefaultTermSignalUsingEventLoop()
338337
$termSignal = func_get_arg(1);
339338
});
340339

341-
$loop->addTimer(0.001, function(Timer $timer) use ($process) {
342-
$process->start($timer->getLoop());
340+
$loop->addTimer(0.001, function () use ($process, $loop) {
341+
$process->start($loop);
343342
$process->terminate();
344343
});
345344

@@ -379,19 +378,19 @@ public function testTerminateWithStopAndContinueSignalsUsingEventLoop()
379378
});
380379

381380
$that = $this;
382-
$loop->addTimer(0.001, function(Timer $timer) use ($process, $that) {
383-
$process->start($timer->getLoop());
381+
$loop->addTimer(0.001, function () use ($process, $loop, $that) {
382+
$process->start($loop);
384383
$process->terminate(SIGSTOP);
385384

386-
$that->assertSoon(function() use ($process, $that) {
385+
$that->assertSoon(function () use ($process, $that) {
387386
$that->assertTrue($process->isStopped());
388387
$that->assertTrue($process->isRunning());
389388
$that->assertEquals(SIGSTOP, $process->getStopSignal());
390389
});
391390

392391
$process->terminate(SIGCONT);
393392

394-
$that->assertSoon(function() use ($process, $that) {
393+
$that->assertSoon(function () use ($process, $that) {
395394
$that->assertFalse($process->isStopped());
396395
$that->assertEquals(SIGSTOP, $process->getStopSignal());
397396
});
@@ -444,7 +443,12 @@ function ($output) use (&$stdErr) {
444443
}
445444
);
446445

447-
$loop->tick();
446+
// tick loop once
447+
$loop->addTimer(0, function () use ($loop) {
448+
$loop->stop();
449+
});
450+
$loop->run();
451+
448452
sleep(1); // comment this line out and it works fine
449453

450454
$loop->run();

tests/ExtLibevLoopProcessTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace React\Tests\ChildProcess;
4+
5+
use React\EventLoop\ExtLibevLoop;
6+
use React\EventLoop\LibEvLoop;
7+
8+
class ExtLibevLoopProcessTest extends AbstractProcessTest
9+
{
10+
public function createLoop()
11+
{
12+
if (!class_exists('libev\EventLoop')) {
13+
$this->markTestSkipped('ext-libev is not installed.');
14+
}
15+
16+
return class_exists('React\EventLoop\ExtLibevLoop') ? new ExtLibevLoop() : new LibEvLoop();
17+
}
18+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace React\Tests\ChildProcess;
4+
5+
use React\EventLoop\ExtLibeventLoop;
6+
use React\EventLoop\LibEventLoop;
7+
8+
class ExtLibeventLoopProcessTest extends AbstractProcessTest
9+
{
10+
public function createLoop()
11+
{
12+
if (!function_exists('event_base_new')) {
13+
$this->markTestSkipped('ext-libevent is not installed.');
14+
}
15+
16+
return class_exists('React\EventLoop\ExtLibeventLoop') ? new ExtLibeventLoop() : new LibEventLoop();
17+
}
18+
}

tests/LibEvLoopProcessTest.php

Lines changed: 0 additions & 17 deletions
This file was deleted.

tests/LibEventLoopProcessTest.php

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)