@@ -765,6 +765,77 @@ public function testFakeInvokedProcessOutputWithLatestOutput()
765765 $ this ->assertEquals ("ONE \nTWO \nTHREE \n" , $ output [2 ]);
766766 }
767767
768+ public function testFakeInvokedProcessWaitUntil ()
769+ {
770+ $ factory = new Factory ;
771+
772+ $ factory ->fake (function () use ($ factory ) {
773+ return $ factory ->describe ()
774+ ->output ('WAITING ' )
775+ ->output ('READY ' )
776+ ->output ('DONE ' )
777+ ->runsFor (iterations: 3 );
778+ });
779+
780+ $ process = $ factory ->start ('echo "WAITING"; sleep 1; echo "READY"; sleep 1; echo "DONE"; ' );
781+
782+ $ callbackInvoked = [];
783+
784+ $ result = $ process ->waitUntil (function ($ type , $ buffer ) use (&$ callbackInvoked ) {
785+ $ callbackInvoked [] = $ buffer ;
786+ return str_contains ($ buffer , 'READY ' );
787+ });
788+
789+ $ this ->assertInstanceOf (ProcessResult::class, $ result );
790+ $ this ->assertTrue ($ result ->successful ());
791+ $ this ->assertContains ("WAITING \n" , $ callbackInvoked );
792+ $ this ->assertContains ("READY \n" , $ callbackInvoked );
793+ }
794+
795+ public function testFakeInvokedProcessWaitUntilWithNoCallback ()
796+ {
797+ $ factory = new Factory ;
798+
799+ $ factory ->fake (function () use ($ factory ) {
800+ return $ factory ->describe ()
801+ ->output ('OUTPUT ' );
802+ });
803+
804+ $ process = $ factory ->start ('echo "OUTPUT" ' );
805+
806+ $ result = $ process ->waitUntil ();
807+
808+ $ this ->assertInstanceOf (ProcessResult::class, $ result );
809+ $ this ->assertTrue ($ result ->successful ());
810+ $ this ->assertEquals ("OUTPUT \n" , $ result ->output ());
811+ }
812+
813+ public function testFakeInvokedProcessWaitUntilStopsWhenConditionMet ()
814+ {
815+ $ factory = new Factory ;
816+
817+ $ factory ->fake (function () use ($ factory ) {
818+ return $ factory ->describe ()
819+ ->output ('STEP1 ' )
820+ ->output ('TARGET ' )
821+ ->output ('STEP3 ' )
822+ ->runsFor (iterations: 3 );
823+ });
824+
825+ $ process = $ factory ->start ('echo "STEP1"; sleep 1; echo "TARGET"; sleep 1; echo "STEP3"; ' );
826+
827+ $ callbackCount = 0 ;
828+
829+ $ result = $ process ->waitUntil (function ($ type , $ buffer ) use (&$ callbackCount ) {
830+ $ callbackCount ++;
831+ return str_contains ($ buffer , 'TARGET ' );
832+ });
833+
834+ $ this ->assertInstanceOf (ProcessResult::class, $ result );
835+ $ this ->assertTrue ($ result ->successful ());
836+ $ this ->assertEquals (2 , $ callbackCount );
837+ }
838+
768839 public function testBasicFakeAssertions ()
769840 {
770841 $ factory = new Factory ;
0 commit comments