From 5b3279f6b2d7fe842eba294405e8ecc7ad13a28b Mon Sep 17 00:00:00 2001 From: Riley Aven Date: Mon, 14 Oct 2024 18:58:56 -0400 Subject: [PATCH] Add successful and failed --- src/Illuminate/Process/ProcessPoolResults.php | 19 ++++++++++++++ tests/Process/ProcessTest.php | 25 +++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/src/Illuminate/Process/ProcessPoolResults.php b/src/Illuminate/Process/ProcessPoolResults.php index 840a109315d7..5bb49abf2406 100644 --- a/src/Illuminate/Process/ProcessPoolResults.php +++ b/src/Illuminate/Process/ProcessPoolResults.php @@ -3,6 +3,7 @@ namespace Illuminate\Process; use ArrayAccess; +use Illuminate\Process\Exceptions\ProcessFailedException; use Illuminate\Support\Collection; class ProcessPoolResults implements ArrayAccess @@ -79,4 +80,22 @@ public function offsetUnset($offset): void { unset($this->results[$offset]); } + + /** + * Determine if the process was successful. + * + * @return bool + */ + public function successful() { + return collect($this->results)->every(fn($poolResult) => $poolResult->successful()); + } + + /** + * Determine if the process failed. + * + * @return bool + */ + public function failed() { + return !$this->successful(); + } } diff --git a/tests/Process/ProcessTest.php b/tests/Process/ProcessTest.php index 841860cacd26..8b51dad64f9a 100644 --- a/tests/Process/ProcessTest.php +++ b/tests/Process/ProcessTest.php @@ -47,6 +47,31 @@ public function testProcessPool() $this->assertTrue(str_contains($results[0]->output(), 'ProcessTest.php')); $this->assertTrue(str_contains($results[1]->output(), 'ProcessTest.php')); + + $this->assertTrue($results->successful()); + } + + public function testProcessPoolFailed() + { + $factory = new Factory; + + $factory->fake([ + 'cat *' => $factory->result(exitCode: 1), + ]); + + $pool = $factory->pool(function ($pool) { + return [ + $pool->path(__DIR__)->command($this->ls()), + $pool->path(__DIR__)->command('cat test'), + ]; + }); + + $results = $pool->start()->wait(); + + $this->assertTrue($results[0]->successful()); + $this->assertTrue($results[1]->failed()); + + $this->assertTrue($results->failed()); } public function testInvokedProcessPoolCount()