Skip to content

Commit 808c52c

Browse files
author
Riley Aven
committed
Add successful and failed
1 parent 231091c commit 808c52c

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

src/Illuminate/Process/ProcessPoolResults.php

+18
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,22 @@ public function offsetUnset($offset): void
7979
{
8080
unset($this->results[$offset]);
8181
}
82+
83+
/**
84+
* Determine if the process was successful.
85+
*
86+
* @return bool
87+
*/
88+
public function successful() {
89+
return collect($this->results)->every(fn($poolResult) => $poolResult->successful());
90+
}
91+
92+
/**
93+
* Determine if the process failed.
94+
*
95+
* @return bool
96+
*/
97+
public function failed() {
98+
return !$this->successful();
99+
}
82100
}

tests/Process/ProcessTest.php

+25
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)