Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[10.x] Adds Countable to the InvokedProcessPool class. #46346

Merged
merged 2 commits into from
Mar 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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