diff --git a/src/Illuminate/Process/InvokedProcessPool.php b/src/Illuminate/Process/InvokedProcessPool.php index 9a04c13d2acd..29f8a6579bb5 100644 --- a/src/Illuminate/Process/InvokedProcessPool.php +++ b/src/Illuminate/Process/InvokedProcessPool.php @@ -2,7 +2,9 @@ namespace Illuminate\Process; -class InvokedProcessPool +use Countable; + +class InvokedProcessPool implements Countable { /** * The array of invoked processes. @@ -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); + } } diff --git a/tests/Process/ProcessTest.php b/tests/Process/ProcessTest.php index d9613d916b75..4a58cd94fb12 100644 --- a/tests/Process/ProcessTest.php +++ b/tests/Process/ProcessTest.php @@ -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;