Skip to content

Commit 8048c98

Browse files
Riley19280Riley Avencrynobonetaylorotwell
authored
[11.x] Add successful and failed methods to ProcessPoolResults (#53160)
* Add successful and failed * formatting * formatting * formatting * formatting --------- Co-authored-by: Riley Aven <[email protected]> Co-authored-by: Mior Muhammad Zaki <[email protected]> Co-authored-by: Taylor Otwell <[email protected]>
1 parent 04e2e19 commit 8048c98

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

src/Illuminate/Process/ProcessPoolResults.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,26 @@ public function __construct(array $results)
2525
$this->results = $results;
2626
}
2727

28+
/**
29+
* Determine if all of the processes in the pool were successful.
30+
*
31+
* @return bool
32+
*/
33+
public function successful()
34+
{
35+
return $this->collect()->every(fn ($p) => $p->successful());
36+
}
37+
38+
/**
39+
* Determine if any of the processes in the pool failed.
40+
*
41+
* @return bool
42+
*/
43+
public function failed()
44+
{
45+
return ! $this->successful();
46+
}
47+
2848
/**
2949
* Get the results as a collection.
3050
*

tests/Process/ProcessTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,31 @@ public function testProcessPool()
4747

4848
$this->assertTrue(str_contains($results[0]->output(), 'ProcessTest.php'));
4949
$this->assertTrue(str_contains($results[1]->output(), 'ProcessTest.php'));
50+
51+
$this->assertTrue($results->successful());
52+
}
53+
54+
public function testProcessPoolFailed()
55+
{
56+
$factory = new Factory;
57+
58+
$factory->fake([
59+
'cat *' => $factory->result(exitCode: 1),
60+
]);
61+
62+
$pool = $factory->pool(function ($pool) {
63+
return [
64+
$pool->path(__DIR__)->command($this->ls()),
65+
$pool->path(__DIR__)->command('cat test'),
66+
];
67+
});
68+
69+
$results = $pool->start()->wait();
70+
71+
$this->assertTrue($results[0]->successful());
72+
$this->assertTrue($results[1]->failed());
73+
74+
$this->assertTrue($results->failed());
5075
}
5176

5277
public function testInvokedProcessPoolCount()

0 commit comments

Comments
 (0)