Skip to content

Commit

Permalink
[10.x] Adds Countable to the InvokedProcessPool class. (#46346)
Browse files Browse the repository at this point in the history
* feat: Add `total` method.

* Implements `Countable`
  • Loading branch information
xiCO2k authored Mar 6, 2023
1 parent 80f9249 commit ee9487f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/Illuminate/Process/InvokedProcessPool.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace Illuminate\Process;

class InvokedProcessPool
use Countable;

class InvokedProcessPool implements Countable
{
/**
* The array of invoked processes.
Expand Down Expand Up @@ -52,4 +54,14 @@ public function wait()
{
return new ProcessPoolResults(collect($this->invokedProcesses)->map->wait()->all());
}

/**
* Get the total number of processes.
*
* @return int
*/
public function count(): int
{
return count($this->invokedProcesses);
}
}
14 changes: 14 additions & 0 deletions tests/Process/ProcessTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,20 @@ public function testProcessPool()
$this->assertTrue(str_contains($results[1]->output(), 'ProcessTest.php'));
}

public function testInvokedProcessPoolCount()
{
$factory = new Factory;

$pool = $factory->pool(function ($pool) {
return [
$pool->path(__DIR__)->command($this->ls()),
$pool->path(__DIR__)->command($this->ls()),
];
})->start();

$this->assertCount(2, $pool);
}

public function testProcessPoolCanReceiveOutputForEachProcessViaStartMethod()
{
$factory = new Factory;
Expand Down

0 comments on commit ee9487f

Please sign in to comment.