Skip to content

Commit

Permalink
[11.x] Add successful and failed methods to ProcessPoolResults (#53160
Browse files Browse the repository at this point in the history
)

* 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]>
  • Loading branch information
4 people authored Oct 15, 2024
1 parent 04e2e19 commit 8048c98
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/Illuminate/Process/ProcessPoolResults.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,26 @@ public function __construct(array $results)
$this->results = $results;
}

/**
* Determine if all of the processes in the pool were successful.
*
* @return bool
*/
public function successful()
{
return $this->collect()->every(fn ($p) => $p->successful());
}

/**
* Determine if any of the processes in the pool failed.
*
* @return bool
*/
public function failed()
{
return ! $this->successful();
}

/**
* Get the results as a collection.
*
Expand Down
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 8048c98

Please sign in to comment.