@@ -167,6 +167,10 @@ public function testProcessPipes($code, $size)
167
167
$ this ->assertEquals ($ expectedLength , strlen ($ p ->getErrorOutput ()));
168
168
}
169
169
170
+ /**
171
+ * @expectedException Symfony\Component\Process\Exception\LogicException
172
+ * @expectedExceptionMessage STDIN can not be set while the process is running.
173
+ */
170
174
public function testSetStdinWhileRunningThrowsAnException ()
171
175
{
172
176
$ process = $ this ->getProcess (self ::$ phpBin .' -r "usleep(500000);" ' );
@@ -176,9 +180,10 @@ public function testSetStdinWhileRunningThrowsAnException()
176
180
$ process ->stop ();
177
181
$ this ->fail ('A LogicException should have been raised. ' );
178
182
} catch (LogicException $ e ) {
179
- $ this ->assertEquals ('STDIN can not be set while the process is running. ' , $ e ->getMessage ());
180
183
}
181
184
$ process ->stop ();
185
+
186
+ throw $ e ;
182
187
}
183
188
184
189
/**
@@ -659,6 +664,10 @@ public function testRestart()
659
664
$ this ->assertNotEquals ($ process1 ->getOutput (), $ process2 ->getOutput ());
660
665
}
661
666
667
+ /**
668
+ * @expectedException Symfony\Component\Process\Exception\RuntimeException
669
+ * @expectedExceptionMessage The process timed-out.
670
+ */
662
671
public function testRunProcessWithTimeout ()
663
672
{
664
673
$ timeout = 0.5 ;
@@ -672,14 +681,13 @@ public function testRunProcessWithTimeout()
672
681
}
673
682
$ duration = microtime (true ) - $ start ;
674
683
675
- if ('\\' === DIRECTORY_SEPARATOR ) {
676
- // Windows is a bit slower as it read file handles, then allow twice the precision
677
- $ maxDuration = $ timeout + 2 * Process::TIMEOUT_PRECISION ;
678
- } else {
684
+ if ('\\' !== DIRECTORY_SEPARATOR ) {
685
+ // On Windows, timers are too transient
679
686
$ maxDuration = $ timeout + Process::TIMEOUT_PRECISION ;
687
+ $ this ->assertLessThan ($ maxDuration , $ duration );
680
688
}
681
689
682
- $ this -> assertLessThan ( $ maxDuration , $ duration ) ;
690
+ throw $ e ;
683
691
}
684
692
685
693
public function testCheckTimeoutOnNonStartedProcess ()
@@ -695,6 +703,10 @@ public function testCheckTimeoutOnTerminatedProcess()
695
703
$ process ->checkTimeout ();
696
704
}
697
705
706
+ /**
707
+ * @expectedException Symfony\Component\Process\Exception\RuntimeException
708
+ * @expectedExceptionMessage The process timed-out.
709
+ */
698
710
public function testCheckTimeoutOnStartedProcess ()
699
711
{
700
712
$ timeout = 0.5 ;
@@ -717,8 +729,14 @@ public function testCheckTimeoutOnStartedProcess()
717
729
718
730
$ this ->assertLessThan ($ timeout + $ precision , $ duration );
719
731
$ this ->assertFalse ($ process ->isSuccessful ());
732
+
733
+ throw $ e ;
720
734
}
721
735
736
+ /**
737
+ * @expectedException Symfony\Component\Process\Exception\RuntimeException
738
+ * @expectedExceptionMessage The process timed-out.
739
+ */
722
740
public function testStartAfterATimeout ()
723
741
{
724
742
$ process = $ this ->getProcess (sprintf ('%s -r %s ' , self ::$ phpBin , escapeshellarg ('$n = 1000; while ($n--) {echo \'\'; usleep(1000); } ' )));
@@ -731,6 +749,8 @@ public function testStartAfterATimeout()
731
749
$ process ->start ();
732
750
usleep (10000 );
733
751
$ process ->stop ();
752
+
753
+ throw $ e ;
734
754
}
735
755
736
756
public function testGetPid ()
@@ -760,14 +780,14 @@ public function testSignal()
760
780
$ this ->markTestSkipped ('Extension pcntl is required. ' );
761
781
}
762
782
763
- $ process = $ this ->getProcess ('exec php -f ' .__DIR__ .'/SignalListener.php ' );
783
+ $ process = $ this ->getProcess ('exec ' . self :: $ phpBin . ' ' .__DIR__ .'/SignalListener.php ' );
764
784
$ process ->start ();
765
- usleep (500000 );
766
- $ process ->signal (SIGUSR1 );
767
785
768
- while ($ process -> isRunning () && false === strpos ($ process ->getOutput (), 'Caught SIGUSR1 ' )) {
769
- usleep (10000 );
786
+ while (false === strpos ($ process ->getOutput (), 'Caught ' )) {
787
+ usleep (1000 );
770
788
}
789
+ $ process ->signal (SIGUSR1 );
790
+ $ process ->wait ();
771
791
772
792
$ this ->assertEquals ('Caught SIGUSR1 ' , $ process ->getOutput ());
773
793
}
@@ -828,6 +848,8 @@ public function provideMethodsThatNeedARunningProcess()
828
848
829
849
/**
830
850
* @dataProvider provideMethodsThatNeedATerminatedProcess
851
+ * @expectedException Symfony\Component\Process\Exception\LogicException
852
+ * @expectedExceptionMessage Process must be terminated before calling
831
853
*/
832
854
public function testMethodsThatNeedATerminatedProcess ($ method )
833
855
{
@@ -838,10 +860,10 @@ public function testMethodsThatNeedATerminatedProcess($method)
838
860
$ process ->stop (0 );
839
861
$ this ->fail ('A LogicException must have been thrown ' );
840
862
} catch (\Exception $ e ) {
841
- $ this ->assertInstanceOf ('Symfony\Component\Process\Exception\LogicException ' , $ e );
842
- $ this ->assertEquals (sprintf ('Process must be terminated before calling %s. ' , $ method ), $ e ->getMessage ());
843
863
}
844
864
$ process ->stop (0 );
865
+
866
+ throw $ e ;
845
867
}
846
868
847
869
public function provideMethodsThatNeedATerminatedProcess ()
0 commit comments