Skip to content

Commit ee9487f

Browse files
authored
[10.x] Adds Countable to the InvokedProcessPool class. (#46346)
* feat: Add `total` method. * Implements `Countable`
1 parent 80f9249 commit ee9487f

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

src/Illuminate/Process/InvokedProcessPool.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
namespace Illuminate\Process;
44

5-
class InvokedProcessPool
5+
use Countable;
6+
7+
class InvokedProcessPool implements Countable
68
{
79
/**
810
* The array of invoked processes.
@@ -52,4 +54,14 @@ public function wait()
5254
{
5355
return new ProcessPoolResults(collect($this->invokedProcesses)->map->wait()->all());
5456
}
57+
58+
/**
59+
* Get the total number of processes.
60+
*
61+
* @return int
62+
*/
63+
public function count(): int
64+
{
65+
return count($this->invokedProcesses);
66+
}
5567
}

tests/Process/ProcessTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,20 @@ public function testProcessPool()
5454
$this->assertTrue(str_contains($results[1]->output(), 'ProcessTest.php'));
5555
}
5656

57+
public function testInvokedProcessPoolCount()
58+
{
59+
$factory = new Factory;
60+
61+
$pool = $factory->pool(function ($pool) {
62+
return [
63+
$pool->path(__DIR__)->command($this->ls()),
64+
$pool->path(__DIR__)->command($this->ls()),
65+
];
66+
})->start();
67+
68+
$this->assertCount(2, $pool);
69+
}
70+
5771
public function testProcessPoolCanReceiveOutputForEachProcessViaStartMethod()
5872
{
5973
$factory = new Factory;

0 commit comments

Comments
 (0)