12
12
namespace Symfony \Component \Process \Tests ;
13
13
14
14
use Symfony \Component \Process \Exception \LogicException ;
15
+ use Symfony \Component \Process \PhpExecutableFinder ;
15
16
use Symfony \Component \Process \Process ;
16
17
use Symfony \Component \Process \Exception \RuntimeException ;
17
18
use Symfony \Component \Process \ProcessPipes ;
21
22
*/
22
23
abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase
23
24
{
25
+ protected static $ phpBin ;
26
+
27
+ public static function setUpBeforeClass ()
28
+ {
29
+ $ phpBin = new PhpExecutableFinder ();
30
+ self ::$ phpBin = $ phpBin ->find ();
31
+ }
32
+
24
33
public function testThatProcessDoesNotThrowWarningDuringRun ()
25
34
{
26
35
@trigger_error ('Test Error ' , E_USER_NOTICE );
27
- $ process = $ this ->getProcess (" php -r 'sleep(3)' " );
36
+ $ process = $ this ->getProcess (self :: $ phpBin . " -r 'sleep(3)' " );
28
37
$ process ->run ();
29
38
$ actualError = error_get_last ();
30
39
$ this ->assertEquals ('Test Error ' , $ actualError ['message ' ]);
@@ -158,7 +167,7 @@ public function testProcessPipes($code, $size)
158
167
159
168
public function testSetStdinWhileRunningThrowsAnException ()
160
169
{
161
- $ process = $ this ->getProcess (' php -r "usleep(500000);" ' );
170
+ $ process = $ this ->getProcess (self :: $ phpBin . ' -r "usleep(500000);" ' );
162
171
$ process ->start ();
163
172
try {
164
173
$ process ->setStdin ('foobar ' );
@@ -177,7 +186,7 @@ public function testSetStdinWhileRunningThrowsAnException()
177
186
*/
178
187
public function testInvalidStdin ($ value )
179
188
{
180
- $ process = $ this ->getProcess (' php -v ' );
189
+ $ process = $ this ->getProcess (self :: $ phpBin . ' -v ' );
181
190
$ process ->setStdin ($ value );
182
191
}
183
192
@@ -195,7 +204,7 @@ public function provideInvalidStdinValues()
195
204
*/
196
205
public function testValidStdin ($ expected , $ value )
197
206
{
198
- $ process = $ this ->getProcess (' php -v ' );
207
+ $ process = $ this ->getProcess (self :: $ phpBin . ' -v ' );
199
208
$ process ->setStdin ($ value );
200
209
$ this ->assertSame ($ expected , $ process ->getStdin ());
201
210
}
@@ -452,7 +461,7 @@ public function testExitCodeText()
452
461
453
462
public function testStartIsNonBlocking ()
454
463
{
455
- $ process = $ this ->getProcess (' php -r "usleep(500000);" ' );
464
+ $ process = $ this ->getProcess (self :: $ phpBin . ' -r "usleep(500000);" ' );
456
465
$ start = microtime (true );
457
466
$ process ->start ();
458
467
$ end = microtime (true );
@@ -462,14 +471,14 @@ public function testStartIsNonBlocking()
462
471
463
472
public function testUpdateStatus ()
464
473
{
465
- $ process = $ this ->getProcess (' php -h ' );
474
+ $ process = $ this ->getProcess (self :: $ phpBin . ' -v ' );
466
475
$ process ->run ();
467
476
$ this ->assertTrue (strlen ($ process ->getOutput ()) > 0 );
468
477
}
469
478
470
479
public function testGetExitCodeIsNullOnStart ()
471
480
{
472
- $ process = $ this ->getProcess (' php -r "usleep(200000);" ' );
481
+ $ process = $ this ->getProcess (self :: $ phpBin . ' -r "usleep(200000);" ' );
473
482
$ this ->assertNull ($ process ->getExitCode ());
474
483
$ process ->start ();
475
484
$ this ->assertNull ($ process ->getExitCode ());
@@ -479,7 +488,7 @@ public function testGetExitCodeIsNullOnStart()
479
488
480
489
public function testGetExitCodeIsNullOnWhenStartingAgain ()
481
490
{
482
- $ process = $ this ->getProcess (' php -r "usleep(200000);" ' );
491
+ $ process = $ this ->getProcess (self :: $ phpBin . ' -r "usleep(200000);" ' );
483
492
$ process ->run ();
484
493
$ this ->assertEquals (0 , $ process ->getExitCode ());
485
494
$ process ->start ();
@@ -490,14 +499,14 @@ public function testGetExitCodeIsNullOnWhenStartingAgain()
490
499
491
500
public function testGetExitCode ()
492
501
{
493
- $ process = $ this ->getProcess (' php -m ' );
502
+ $ process = $ this ->getProcess (self :: $ phpBin . ' -v ' );
494
503
$ process ->run ();
495
504
$ this ->assertSame (0 , $ process ->getExitCode ());
496
505
}
497
506
498
507
public function testStatus ()
499
508
{
500
- $ process = $ this ->getProcess (' php -r "usleep(500000);" ' );
509
+ $ process = $ this ->getProcess (self :: $ phpBin . ' -r "usleep(500000);" ' );
501
510
$ this ->assertFalse ($ process ->isRunning ());
502
511
$ this ->assertFalse ($ process ->isStarted ());
503
512
$ this ->assertFalse ($ process ->isTerminated ());
@@ -516,7 +525,7 @@ public function testStatus()
516
525
517
526
public function testStop ()
518
527
{
519
- $ process = $ this ->getProcess (' php -r "sleep(4);" ' );
528
+ $ process = $ this ->getProcess (self :: $ phpBin . ' -r "sleep(4);" ' );
520
529
$ process ->start ();
521
530
$ this ->assertTrue ($ process ->isRunning ());
522
531
$ process ->stop ();
@@ -525,14 +534,14 @@ public function testStop()
525
534
526
535
public function testIsSuccessful ()
527
536
{
528
- $ process = $ this ->getProcess (' php -m ' );
537
+ $ process = $ this ->getProcess (self :: $ phpBin . ' -v ' );
529
538
$ process ->run ();
530
539
$ this ->assertTrue ($ process ->isSuccessful ());
531
540
}
532
541
533
542
public function testIsSuccessfulOnlyAfterTerminated ()
534
543
{
535
- $ process = $ this ->getProcess (' php -r "sleep(1);" ' );
544
+ $ process = $ this ->getProcess (self :: $ phpBin . ' -r "sleep(1);" ' );
536
545
$ process ->start ();
537
546
while ($ process ->isRunning ()) {
538
547
$ this ->assertFalse ($ process ->isSuccessful ());
@@ -544,7 +553,7 @@ public function testIsSuccessfulOnlyAfterTerminated()
544
553
545
554
public function testIsNotSuccessful ()
546
555
{
547
- $ process = $ this ->getProcess (' php -r "usleep(500000);throw new \Exception( \'BOUM \');" ' );
556
+ $ process = $ this ->getProcess (self :: $ phpBin . ' -r "usleep(500000);throw new \Exception( \'BOUM \');" ' );
548
557
$ process ->start ();
549
558
$ this ->assertTrue ($ process ->isRunning ());
550
559
$ process ->wait ();
@@ -557,7 +566,7 @@ public function testProcessIsNotSignaled()
557
566
$ this ->markTestSkipped ('Windows does not support POSIX signals ' );
558
567
}
559
568
560
- $ process = $ this ->getProcess (' php -m ' );
569
+ $ process = $ this ->getProcess (self :: $ phpBin . ' -v ' );
561
570
$ process ->run ();
562
571
$ this ->assertFalse ($ process ->hasBeenSignaled ());
563
572
}
@@ -568,7 +577,7 @@ public function testProcessWithoutTermSignalIsNotSignaled()
568
577
$ this ->markTestSkipped ('Windows does not support POSIX signals ' );
569
578
}
570
579
571
- $ process = $ this ->getProcess (' php -m ' );
580
+ $ process = $ this ->getProcess (self :: $ phpBin . ' -v ' );
572
581
$ process ->run ();
573
582
$ this ->assertFalse ($ process ->hasBeenSignaled ());
574
583
}
@@ -579,7 +588,7 @@ public function testProcessWithoutTermSignal()
579
588
$ this ->markTestSkipped ('Windows does not support POSIX signals ' );
580
589
}
581
590
582
- $ process = $ this ->getProcess (' php -m ' );
591
+ $ process = $ this ->getProcess (self :: $ phpBin . ' -v ' );
583
592
$ process ->run ();
584
593
$ this ->assertEquals (0 , $ process ->getTermSignal ());
585
594
}
@@ -590,7 +599,7 @@ public function testProcessIsSignaledIfStopped()
590
599
$ this ->markTestSkipped ('Windows does not support POSIX signals ' );
591
600
}
592
601
593
- $ process = $ this ->getProcess (' php -r "sleep(4);" ' );
602
+ $ process = $ this ->getProcess (self :: $ phpBin . ' -r "sleep(4);" ' );
594
603
$ process ->start ();
595
604
$ process ->stop ();
596
605
$ this ->assertTrue ($ process ->hasBeenSignaled ());
@@ -605,7 +614,7 @@ public function testProcessWithTermSignal()
605
614
// SIGTERM is only defined if pcntl extension is present
606
615
$ termSignal = defined ('SIGTERM ' ) ? SIGTERM : 15 ;
607
616
608
- $ process = $ this ->getProcess (' php -r "sleep(4);" ' );
617
+ $ process = $ this ->getProcess (self :: $ phpBin . ' -r "sleep(4);" ' );
609
618
$ process ->start ();
610
619
$ process ->stop ();
611
620
@@ -634,7 +643,7 @@ public function testProcessThrowsExceptionWhenExternallySignaled()
634
643
635
644
public function testRestart ()
636
645
{
637
- $ process1 = $ this ->getProcess (' php -r "echo getmypid();" ' );
646
+ $ process1 = $ this ->getProcess (self :: $ phpBin . ' -r "echo getmypid();" ' );
638
647
$ process1 ->run ();
639
648
$ process2 = $ process1 ->restart ();
640
649
@@ -656,7 +665,7 @@ public function testPhpDeadlock()
656
665
657
666
// Sleep doesn't work as it will allow the process to handle signals and close
658
667
// file handles from the other end.
659
- $ process = $ this ->getProcess (' php -r "while (true) {}" ' );
668
+ $ process = $ this ->getProcess (self :: $ phpBin . ' -r "while (true) {}" ' );
660
669
$ process ->start ();
661
670
662
671
// PHP will deadlock when it tries to cleanup $process
@@ -665,7 +674,7 @@ public function testPhpDeadlock()
665
674
public function testRunProcessWithTimeout ()
666
675
{
667
676
$ timeout = 0.5 ;
668
- $ process = $ this ->getProcess (' php -r "usleep(600000);" ' );
677
+ $ process = $ this ->getProcess (self :: $ phpBin . ' -r "usleep(600000);" ' );
669
678
$ process ->setTimeout ($ timeout );
670
679
$ start = microtime (true );
671
680
try {
@@ -687,13 +696,13 @@ public function testRunProcessWithTimeout()
687
696
688
697
public function testCheckTimeoutOnNonStartedProcess ()
689
698
{
690
- $ process = $ this ->getProcess (' php -r "sleep(3);" ' );
699
+ $ process = $ this ->getProcess (self :: $ phpBin . ' -r "sleep(3);" ' );
691
700
$ process ->checkTimeout ();
692
701
}
693
702
694
703
public function testCheckTimeoutOnTerminatedProcess ()
695
704
{
696
- $ process = $ this ->getProcess (' php -v ' );
705
+ $ process = $ this ->getProcess (self :: $ phpBin . ' -v ' );
697
706
$ process ->run ();
698
707
$ process ->checkTimeout ();
699
708
}
@@ -702,7 +711,7 @@ public function testCheckTimeoutOnStartedProcess()
702
711
{
703
712
$ timeout = 0.5 ;
704
713
$ precision = 100000 ;
705
- $ process = $ this ->getProcess (' php -r "sleep(3);" ' );
714
+ $ process = $ this ->getProcess (self :: $ phpBin . ' -r "sleep(3);" ' );
706
715
$ process ->setTimeout ($ timeout );
707
716
$ start = microtime (true );
708
717
@@ -738,21 +747,21 @@ public function testStartAfterATimeout()
738
747
739
748
public function testGetPid ()
740
749
{
741
- $ process = $ this ->getProcess (' php -r "usleep(500000);" ' );
750
+ $ process = $ this ->getProcess (self :: $ phpBin . ' -r "usleep(500000);" ' );
742
751
$ process ->start ();
743
752
$ this ->assertGreaterThan (0 , $ process ->getPid ());
744
753
$ process ->wait ();
745
754
}
746
755
747
756
public function testGetPidIsNullBeforeStart ()
748
757
{
749
- $ process = $ this ->getProcess (' php -r "sleep(1);" ' );
758
+ $ process = $ this ->getProcess (self :: $ phpBin . ' -r "sleep(1);" ' );
750
759
$ this ->assertNull ($ process ->getPid ());
751
760
}
752
761
753
762
public function testGetPidIsNullAfterRun ()
754
763
{
755
- $ process = $ this ->getProcess (' php -m ' );
764
+ $ process = $ this ->getProcess (self :: $ phpBin . ' -v ' );
756
765
$ process ->run ();
757
766
$ this ->assertNull ($ process ->getPid ());
758
767
}
@@ -797,7 +806,7 @@ public function testExitCodeIsAvailableAfterSignal()
797
10000
806
public function testSignalProcessNotRunning ()
798
807
{
799
808
$ this ->verifyPosixIsEnabled ();
800
- $ process = $ this ->getProcess (' php -m ' );
809
+ $ process = $ this ->getProcess (self :: $ phpBin . ' -v ' );
801
810
$ process ->signal (SIGHUP );
802
811
}
803
812
@@ -806,7 +815,7 @@ public function testSignalProcessNotRunning()
806
815
*/
807
816
public function testMethodsThatNeedARunningProcess ($ method )
808
817
{
809
- $ process = $ this ->getProcess (' php -m ' );
818
+ $ process = $ this ->getProcess (self :: $ phpBin . ' -v ' );
810
819
$ this ->setExpectedException ('Symfony\Component\Process\Exception\LogicException ' , sprintf ('Process must be started before calling %s. ' , $ method ));
811
820
$ process ->{$ method }();
812
821
}
@@ -827,7 +836,7 @@ public function provideMethodsThatNeedARunningProcess()
827
836
*/
828
837
public function testMethodsThatNeedATerminatedProcess ($ method )
829
838
{
830
- $ process = $ this ->getProcess (' php -r "sleep(1);" ' );
839
+ $ process = $ this ->getProcess (self :: $ phpBin . ' -r "sleep(1);" ' );
831
840
$ process ->start ();
832
841
try {
833
842
$ process ->{$ method }();
@@ -869,7 +878,7 @@ public function testSignalWithWrongIntSignal()
869
878
$ this ->markTestSkipped ('POSIX signals do not work on Windows ' );
870
879
}
871
880
872
- $ process = $ this ->getProcess (' php -r "sleep(3);" ' );
881
+ $ process = $ this ->getProcess (self :: $ phpBin . ' -r "sleep(3);" ' );
873
882
$ process ->start ();
874
883
$ process ->signal (-4 );
875
884
}
@@ -883,7 +892,7 @@ public function testSignalWithWrongNonIntSignal()
883
892
$ this ->markTestSkipped ('POSIX signals do not work on Windows ' );
884
893
}
885
894
886
- $ process = $ this ->getProcess (' php -r "sleep(3);" ' );
895
+ $ process = $ this ->getProcess (self :: $ phpBin . ' -r "sleep(3);" ' );
887
896
$ process ->start ();
888
897
$ process ->signal ('Céphalopodes ' );
889
898
}
0 commit comments