Skip to content

Commit

Permalink
Add successful and failed
Browse files Browse the repository at this point in the history
  • Loading branch information
Riley Aven committed Oct 14, 2024
1 parent 231091c commit 5b3279f
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/Illuminate/Process/ProcessPoolResults.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Illuminate\Process;

use ArrayAccess;
use Illuminate\Process\Exceptions\ProcessFailedException;
use Illuminate\Support\Collection;

class ProcessPoolResults implements ArrayAccess
Expand Down Expand Up @@ -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();
}
}
25 changes: 25 additions & 0 deletions tests/Process/ProcessTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 5b3279f

Please sign in to comment.