@@ -1154,7 +1154,7 @@ public function pipesCodeProvider()
1154
1154
* @dataProvider provideVariousIncrementals
1155
1155
*/
1156
1156
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 );
1158
1158
$ process ->start ();
1159
1159
$ result = '' ;
1160
1160
$ limit = microtime (true ) + 3 ;
@@ -1182,7 +1182,7 @@ public function testIteratorInput()
1182
1182
yield 'pong ' ;
1183
1183
};
1184
1184
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 ());
1186
1186
$ process ->run ();
1187
1187
$ this ->assertSame ('pingpong ' , $ process ->getOutput ());
1188
1188
}
@@ -1191,7 +1191,7 @@ public function testSimpleInputStream()
1191
1191
{
1192
1192
$ input = new InputStream ();
1193
1193
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); ' ));
1195
1195
$ process ->setInput ($ input );
1196
1196
1197
1197
$ process ->start (function ($ type , $ data ) use ($ input ) {
@@ -1225,7 +1225,7 @@ public function testInputStreamWithCallable()
1225
1225
$ input ->onEmpty ($ stream );
1226
1226
$ input ->write ($ stream ());
1227
1227
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 ); ' ));
1229
1229
$ process ->setInput ($ input );
1230
1230
$ process ->start (function ($ type , $ data ) use ($ input ) {
1231
1231
$ input ->close ();
@@ -1243,7 +1243,7 @@ public function testInputStreamWithGenerator()
1243
1243
$ input ->close ();
1244
1244
});
1245
1245
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); ' ));
1247
1247
$ process ->setInput ($ input );
1248
1248
$ process ->start ();
1249
1249
$ input ->write ('ping ' );
@@ -1257,7 +1257,7 @@ public function testInputStreamOnEmpty()
1257
1257
$ input = new InputStream ();
1258
1258
$ input ->onEmpty (function () use (&$ i ) {++$ i ;});
1259
1259
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; ' ));
1261
1261
$ process ->setInput ($ input );
1262
1262
$ process ->start (function ($ type , $ data ) use ($ input ) {
1263
1263
if ('123 ' === $ data ) {
@@ -1274,7 +1274,7 @@ public function testIteratorOutput()
1274
1274
{
1275
1275
$ input = new InputStream ();
1276
1276
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); ' ));
1278
1278
$ process ->setInput ($ input );
1279
1279
$ process ->start ();
1280
1280
$ output = array ();
@@ -1310,12 +1310,12 @@ public function testNonBlockingNorClearingIteratorOutput()
1310
1310
{
1311
1311
$ input = new InputStream ();
1312
1312
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)); ' ));
1314
1314
$ process ->setInput ($ input );
1315
1315
$ process ->start ();
1316
1316
$ output = array ();
1317
1317
1318
- foreach ($ process ->getIterator (false , false ) as $ type => $ data ) {
1318
+ foreach ($ process ->getIterator ($ process :: ITER_NON_BLOCKING | $ process :: ITER_KEEP_OUTPUT ) as $ type => $ data ) {
1319
1319
$ output [] = array ($ type , $ data );
1320
1320
break ;
1321
1321
}
@@ -1326,7 +1326,7 @@ public function testNonBlockingNorClearingIteratorOutput()
1326
1326
1327
1327
$ input ->write (123 );
1328
1328
1329
- foreach ($ process ->getIterator (false , false ) as $ type => $ data ) {
1329
+ foreach ($ process ->getIterator ($ process :: ITER_NON_BLOCKING | $ process :: ITER_KEEP_OUTPUT ) as $ type => $ data ) {
1330
1330
if ('' !== $ data ) {
1331
1331
$ output [] = array ($ type , $ data );
1332
1332
}
@@ -1342,6 +1342,21 @@ public function testNonBlockingNorClearingIteratorOutput()
1342
1342
$ this ->assertSame ($ expectedOutput , $ output );
1343
1343
}
1344
1344
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
+
1345
1360
/**
1346
1361
* @param string $commandline
1347
1362
* @param null|string $cwd
0 commit comments