@@ -1154,7 +1154,7 @@ public function pipesCodeProvider()
11541154 * @dataProvider provideVariousIncrementals
11551155 */
11561156 public function testIncrementalOutputDoesNotRequireAnotherCall ($ stream , $ method ) {
1157- $ process = new Process (self ::$ phpBin .' -r ' .escapeshellarg ('$n = 0; while ($n < 3) { file_put_contents( \'' .$ stream .'\', $n, 1); $n++; usleep(1000); } ' ), null , null , null , null );
1157+ $ process = $ this -> getProcess (self ::$ phpBin .' -r ' .escapeshellarg ('$n = 0; while ($n < 3) { file_put_contents( \'' .$ stream .'\', $n, 1); $n++; usleep(1000); } ' ), null , null , null , null );
11581158 $ process ->start ();
11591159 $ result = '' ;
11601160 $ limit = microtime (true ) + 3 ;
@@ -1182,7 +1182,7 @@ public function testIteratorInput()
11821182 yield 'pong ' ;
11831183 };
11841184
1185- $ process = new Process (self ::$ phpBin .' -r ' .escapeshellarg ('stream_copy_to_stream(STDIN, STDOUT); ' ), null , null , $ input ());
1185+ $ process = $ this -> getProcess (self ::$ phpBin .' -r ' .escapeshellarg ('stream_copy_to_stream(STDIN, STDOUT); ' ), null , null , $ input ());
11861186 $ process ->run ();
11871187 $ this ->assertSame ('pingpong ' , $ process ->getOutput ());
11881188 }
@@ -1191,7 +1191,7 @@ public function testSimpleInputStream()
11911191 {
11921192 $ input = new InputStream ();
11931193
1194- $ process = new Process (self ::$ phpBin .' -r ' .escapeshellarg ('echo \'ping \'; stream_copy_to_stream(STDIN, STDOUT); ' ));
1194+ $ process = $ this -> getProcess (self ::$ phpBin .' -r ' .escapeshellarg ('echo \'ping \'; stream_copy_to_stream(STDIN, STDOUT); ' ));
11951195 $ process ->setInput ($ input );
11961196
11971197 $ process ->start (function ($ type , $ data ) use ($ input ) {
@@ -1225,7 +1225,7 @@ public function testInputStreamWithCallable()
12251225 $ input ->onEmpty ($ stream );
12261226 $ input ->write ($ stream ());
12271227
1228- $ process = new Process (self ::$ phpBin .' -r ' .escapeshellarg ('stream_copy_to_stream (STDIN, STDOUT ); ' ));
1228+ $ process = $ this -> getProcess (self ::$ phpBin .' -r ' .escapeshellarg ('echo fread (STDIN, 3 ); ' ));
12291229 $ process ->setInput ($ input );
12301230 $ process ->start (function ($ type , $ data ) use ($ input ) {
12311231 $ input ->close ();
@@ -1243,7 +1243,7 @@ public function testInputStreamWithGenerator()
12431243 $ input ->close ();
12441244 });
12451245
1246- $ process = new Process (self ::$ phpBin .' -r ' .escapeshellarg ('stream_copy_to_stream(STDIN, STDOUT); ' ));
1246+ $ process = $ this -> getProcess (self ::$ phpBin .' -r ' .escapeshellarg ('stream_copy_to_stream(STDIN, STDOUT); ' ));
12471247 $ process ->setInput ($ input );
12481248 $ process ->start ();
12491249 $ input ->write ('ping ' );
@@ -1257,7 +1257,7 @@ public function testInputStreamOnEmpty()
12571257 $ input = new InputStream ();
12581258 $ input ->onEmpty (function () use (&$ i ) {++$ i ;});
12591259
1260- $ process = new Process (self ::$ phpBin .' -r ' .escapeshellarg ('echo 123; echo fread(STDIN, 1); echo 456; ' ));
1260+ $ process = $ this -> getProcess (self ::$ phpBin .' -r ' .escapeshellarg ('echo 123; echo fread(STDIN, 1); echo 456; ' ));
12611261 $ process ->setInput ($ input );
12621262 $ process ->start (function ($ type , $ data ) use ($ input ) {
12631263 if ('123 ' === $ data ) {
@@ -1274,7 +1274,7 @@ public function testIteratorOutput()
12741274 {
12751275 $ input = new InputStream ();
12761276
1277- $ process = new Process (self ::$ phpBin .' -r ' .escapeshellarg ('fwrite(STDOUT, 123); fwrite(STDERR, 234); fwrite(STDOUT, fread(STDIN, 3)); fwrite(STDERR, 456); ' ));
1277+ $ process = $ this -> getProcess (self ::$ phpBin .' -r ' .escapeshellarg ('fwrite(STDOUT, 123); fwrite(STDERR, 234); flush(); usleep(10000 ); fwrite(STDOUT, fread(STDIN, 3)); fwrite(STDERR, 456); ' ));
12781278 $ process ->setInput ($ input );
12791279 $ process ->start ();
12801280 $ output = array ();
@@ -1310,12 +1310,12 @@ public function testNonBlockingNorClearingIteratorOutput()
13101310 {
13111311 $ input = new InputStream ();
13121312
1313- $ process = new Process (self ::$ phpBin .' -r ' .escapeshellarg ('fwrite(STDOUT, fread(STDIN, 3)); ' ));
1313+ $ process = $ this -> getProcess (self ::$ phpBin .' -r ' .escapeshellarg ('fwrite(STDOUT, fread(STDIN, 3)); ' ));
13141314 $ process ->setInput ($ input );
13151315 $ process ->start ();
13161316 $ output = array ();
13171317
1318- foreach ($ process ->getIterator (false , false ) as $ type => $ data ) {
1318+ foreach ($ process ->getIterator ($ process :: ITER_NON_BLOCKING | $ process :: ITER_KEEP_OUTPUT ) as $ type => $ data ) {
13191319 $ output [] = array ($ type , $ data );
13201320 break ;
13211321 }
@@ -1326,7 +1326,7 @@ public function testNonBlockingNorClearingIteratorOutput()
13261326
13271327 $ input ->write (123 );
13281328
1329- foreach ($ process ->getIterator (false , false ) as $ type => $ data ) {
1329+ foreach ($ process ->getIterator ($ process :: ITER_NON_BLOCKING | $ process :: ITER_KEEP_OUTPUT ) as $ type => $ data ) {
13301330 if ('' !== $ data ) {
13311331 $ output [] = array ($ type , $ data );
13321332 }
@@ -1342,6 +1342,21 @@ public function testNonBlockingNorClearingIteratorOutput()
13421342 $ this ->assertSame ($ expectedOutput , $ output );
13431343 }
13441344
1345+ public function testChainedProcesses ()
1346+ {
1347+ $ p1 = new Process (self ::$ phpBin .' -r ' .escapeshellarg ('fwrite(STDERR, 123); fwrite(STDOUT, 456); ' ));
1348+ $ p2 = $ this ->getProcess (sprintf ('%s -r %s ' , self ::$ phpBin , escapeshellarg ('stream_copy_to_stream(STDIN, STDOUT); ' )));
1349+ $ p2 ->setInput ($ p1 );
1350+
1351+ $ p1 ->start ();
1352+ $ p2 ->run ();
1353+
1354+ $ this ->assertSame ('123 ' , $ p1 ->getErrorOutput ());
1355+ $ this ->assertSame ('' , $ p1 ->getOutput ());
1356+ $ this ->assertSame ('' , $ p2 ->getErrorOutput ());
1357+ $ this ->assertSame ('456 ' , $ p2 ->getOutput ());
1358+ }
1359+
13451360 /**
13461361 * @param string $commandline
13471362 * @param null|string $cwd
0 commit comments