File tree Expand file tree Collapse file tree 2 files changed +17
-8
lines changed
src/Symfony/Component/Process Expand file tree Collapse file tree 2 files changed +17
-8
lines changed Original file line number Diff line number Diff line change @@ -450,27 +450,28 @@ public function waitUntil(callable $callback): bool
450450 }
451451 $ callback = $ this ->buildCallback ($ callback );
452452
453- $ wait = true ;
454- do {
453+ $ ready = false ;
454+ while ( true ) {
455455 $ this ->checkTimeout ();
456456 $ running = '\\' === \DIRECTORY_SEPARATOR ? $ this ->isRunning () : $ this ->processPipes ->areOpen ();
457457 $ output = $ this ->processPipes ->readAndWrite ($ running , '\\' !== \DIRECTORY_SEPARATOR || !$ running );
458458
459459 foreach ($ output as $ type => $ data ) {
460460 if (3 !== $ type ) {
461- $ wait = ! $ callback (self ::STDOUT === $ type ? self ::OUT : self ::ERR , $ data );
461+ $ ready = $ ready || $ callback (self ::STDOUT === $ type ? self ::OUT : self ::ERR , $ data );
462462 } elseif (!isset ($ this ->fallbackStatus ['signaled ' ])) {
463463 $ this ->fallbackStatus ['exitcode ' ] = (int ) $ data ;
464464 }
465465 }
466- if ($ wait && !$ this ->isRunning ()) {
466+ if ($ ready ) {
467+ return true ;
468+ }
469+ if (!$ running ) {
467470 return false ;
468471 }
469472
470473 usleep (1000 );
471- } while ($ wait );
472-
473- return true ;
474+ }
474475 }
475476
476477 /**
Original file line number Diff line number Diff line change @@ -141,7 +141,7 @@ public function testWaitUntilSpecificOutput()
141141 $ start = microtime (true );
142142
143143 $ completeOutput = '' ;
144- $ p ->waitUntil (function ($ type , $ output ) use (&$ completeOutput ) {
144+ $ result = $ p ->waitUntil (function ($ type , $ output ) use (&$ completeOutput ) {
145145 $ completeOutput .= $ output ;
146146 if (false !== strpos ($ output , 'One more ' )) {
147147 return true ;
@@ -150,6 +150,7 @@ public function testWaitUntilSpecificOutput()
150150 return false ;
151151 });
152152 $ p ->stop ();
153+ $ this ->assertTrue ($ result );
153154
154155 if ('\\' === \DIRECTORY_SEPARATOR ) {
155156 // Windows is slower
@@ -160,6 +161,13 @@ public function testWaitUntilSpecificOutput()
160161 $ this ->assertEquals ("First iteration output \nSecond iteration output \nOne more iteration output \n" , $ completeOutput );
161162 }
162163
164+ public function testWaitUntilCanReturnFalse ()
165+ {
166+ $ p = $ this ->getProcess ('echo foo ' );
167+ $ p ->start ();
168+ $ this ->assertFalse ($ p ->waitUntil (function () { return false ; }));
169+ }
170+
163171 public function testAllOutputIsActuallyReadOnTermination ()
164172 {
165173 // this code will result in a maximum of 2 reads of 8192 bytes by calling
You can’t perform that action at this time.
0 commit comments