@@ -50,9 +50,6 @@ public function testStopWithTimeoutIsActuallyWorking()
50
50
if (defined ('PHP_WINDOWS_VERSION_BUILD ' )) {
51
51
$ this ->markTestSkipped ('Stop with timeout does not work on windows, it requires posix signals ' );
52
52
}
53
- if (!function_exists ('pcntl_signal ' )) {
54
- $ this ->markTestSkipped ('This test require pcntl_signal function ' );
55
- }
56
53
57
54
// exec is mandatory here since we send a signal to the process
58
55
// see https://github.com/symfony/symfony/issues/5030 about prepending
@@ -61,7 +58,7 @@ public function testStopWithTimeoutIsActuallyWorking()
61
58
$ p ->start ();
62
59
usleep (100000 );
63
60
$ start = microtime (true );
64
- $ p ->stop (1.1 );
61
+ $ p ->stop (1.1 , SIGKILL );
65
62
while ($ p ->isRunning ()) {
66
63
usleep (1000 );
67
64
}
@@ -224,7 +221,7 @@ public function testGetExitCode()
224
221
225
222
public function testStatus ()
226
223
{
227
- $ process = $ this ->getProcess ('php -r "sleep(1 );" ' );
224
+ $ process = $ this ->getProcess ('php -r "usleep(500000 );" ' );
228
225
$ this ->assertFalse ($ process ->isRunning ());
229
226
$ this ->assertFalse ($ process ->isStarted ());
230
227
$ this ->assertFalse ($ process ->isTerminated ());
@@ -277,6 +274,17 @@ public function testProcessIsNotSignaled()
277
274
$ this ->assertFalse ($ process ->hasBeenSignaled ());
278
275
}
279
276
277
+ public function testProcessWithoutTermSignalIsNotSignaled ()
278
+ {
279
+ if (defined ('PHP_WINDOWS_VERSION_BUILD ' )) {
280
+ $ this ->markTestSkipped ('Windows does not support POSIX signals ' );
281
+ }
282
+
283
+ $ process = $ this ->getProcess ('php -m ' );
284
+ $ process ->run ();
285
+ $ this ->assertFalse ($ process ->hasBeenSignaled ());
286
+ }
287
+
280
288
public function testProcessWithoutTermSignal ()
281
289
{
282
290
if (defined ('PHP_WINDOWS_VERSION_BUILD ' )) {
@@ -387,6 +395,70 @@ public function testCheckTimeoutOnStartedProcess()
387
395
$ this ->assertLessThan ($ timeout + $ precision , $ duration );
388
396
}
389
397
398
+ public function testGetPid ()
399
+ {
400
+ $ process = $ this ->getProcess ('php -r "sleep(1);" ' );
401
+ $ process ->start ();
402
+ $ this ->assertGreaterThan (0 , $ process ->getPid ());
403
+ $ process ->stop ();
404
+ }
405
+
406
+ public function testGetPidIsNullBeforeStart ()
407
+ {
408
+ $ process = $ this ->getProcess ('php -r "sleep(1);" ' );
409
+ $ this ->assertNull ($ process ->getPid ());
410
+ }
411
+
412
+ public function testGetPidIsNullAfterRun ()
413
+ {
414
+ $ process = $ this ->getProcess ('php -m ' );
415
+ $ process ->run ();
416
+ $ this ->assertNull ($ process ->getPid ());
417
+ }
418
+
419
+ public function testSignal ()
420
+ {
421
+ $ process = $ this ->getProcess ('exec php -f ' . __DIR__ . '/SignalListener.php ' );
422
+ $ process ->start ();
423
+ usleep (500000 );
424
+ $ process ->signal (SIGUSR1 );
425
+
426
+ while ($ process ->isRunning () && false === strpos ($ process ->getoutput (), 'Caught SIGUSR1 ' )) {
427
+ usleep (10000 );
428
+ }
429
+
430
+ $ this ->assertEquals ('Caught SIGUSR1 ' , $ process ->getOutput ());
431
+ }
432
+
433
+ /**
434
+ * @expectedException Symfony\Component\Process\Exception\LogicException
435
+ */
436
+ public function testSignalProcessNotRunning ()
437
+ {
438
+ $ process = $ this ->getProcess ('php -m ' );
439
+ $ process ->signal (SIGHUP );
440
+ }
441
+
442
+ /**
443
+ * @expectedException Symfony\Component\Process\Exception\RuntimeException
444
+ */
445
+ public function testSignalWithWrongIntSignal ()
446
+ {
447
+ $ process = $ this ->getProcess ('php -r "sleep(3);" ' );
448
+ $ process ->start ();
449
+ $ process ->signal (-4 );
450
+ }
451
+
452
+ /**
453
+ * @expectedException Symfony\Component\Process\Exception\RuntimeException
454
+ */
455
+ public function testSignalWithWrongNonIntSignal ()
456
+ {
457
+ $ process = $ this ->getProcess ('php -r "sleep(3);" ' );
458
+ $ process ->start ();
459
+ $ process ->signal ('Céphalopodes ' );
460
+ }
461
+
390
462
public function responsesCodeProvider ()
391
463
{
392
464
return array (
0 commit comments