File tree Expand file tree Collapse file tree 3 files changed +46
-4
lines changed Expand file tree Collapse file tree 3 files changed +46
-4
lines changed Original file line number Diff line number Diff line change @@ -274,12 +274,16 @@ public function pool(callable $callback)
274
274
/**
275
275
* Start defining a series of piped processes.
276
276
*
277
- * @param callable $callback
277
+ * @param callable|array $callback
278
278
* @return \Illuminate\Process\Pipe
279
279
*/
280
- public function pipe (callable $ callback , ?callable $ output = null )
280
+ public function pipe (callable | array $ callback , ?callable $ output = null )
281
281
{
282
- return (new Pipe ($ this , $ callback ))->run (output: $ output );
282
+ return is_array ($ callback )
283
+ ? (new Pipe ($ this , fn ($ pipe ) => collect ($ callback )->each (
284
+ fn ($ command ) => $ pipe ->command ($ command )
285
+ )))->run (output: $ output )
286
+ : (new Pipe ($ this , $ callback ))->run (output: $ output );
283
287
}
284
288
285
289
/**
Original file line number Diff line number Diff line change 35
35
* @method static \Illuminate\Process\Factory assertDidntRun(\Closure|string $callback)
36
36
* @method static \Illuminate\Process\Factory assertNothingRan()
37
37
* @method static \Illuminate\Process\Pool pool(callable $callback)
38
- * @method static \Illuminate\Process\Pipe pipe(callable $callback, callable|null $output = null)
38
+ * @method static \Illuminate\Process\Pipe pipe(callable|array $callback, callable|null $output = null)
39
39
* @method static \Illuminate\Process\ProcessPoolResults concurrently(callable $callback, callable|null $output = null)
40
40
* @method static \Illuminate\Process\PendingProcess newPendingProcess()
41
41
* @method static void macro(string $name, object|callable $macro)
Original file line number Diff line number Diff line change @@ -534,6 +534,44 @@ public function testProcessPipeFailed()
534
534
$ this ->assertTrue ($ pipe ->failed ());
535
535
}
536
536
537
+ public function testProcessSimplePipe ()
538
+ {
539
+ if (windows_os ()) {
540
+ $ this ->markTestSkipped ('Requires Linux. ' );
541
+ }
542
+
543
+ $ factory = new Factory ;
544
+ $ factory ->fake ([
545
+ 'cat * ' => "Hello, world \nfoo \nbar " ,
546
+ ]);
547
+
548
+ $ pipe = $ factory ->pipe ([
549
+ 'cat test ' ,
550
+ 'grep -i "foo" ' ,
551
+ ]);
552
+
553
+ $ this ->assertSame ("foo \n" , $ pipe ->output ());
554
+ }
555
+
556
+ public function testProcessSimplePipeFailed ()
557
+ {
558
+ if (windows_os ()) {
559
+ $ this ->markTestSkipped ('Requires Linux. ' );
560
+ }
561
+
562
+ $ factory = new Factory ;
563
+ $ factory ->fake ([
564
+ 'cat * ' => $ factory ->result (exitCode: 1 ),
565
+ ]);
566
+
567
+ $ pipe = $ factory ->pipe ([
568
+ 'cat test ' ,
569
+ 'grep -i "foo" ' ,
570
+ ]);
571
+
572
+ $ this ->assertTrue ($ pipe ->failed ());
573
+ }
574
+
537
575
public function testFakeInvokedProcessOutputWithLatestOutput ()
538
576
{
539
577
$ factory = new Factory ;
You can’t perform that action at this time.
0 commit comments