diff --git a/test/MergeTest.php b/test/MergeTest.php index 29eafb3..962897b 100644 --- a/test/MergeTest.php +++ b/test/MergeTest.php @@ -21,21 +21,42 @@ public function getArrays(): array /** * @dataProvider getArrays - * - * @param array $array - * @param array $expected */ public function testMerge(array $array, array $expected): void { - $pipelines = \array_map(static function (array $iterator): Pipeline { - return Pipeline::fromIterable($iterator)->tap(fn () => delay(0.01)); - }, $array); + $pipelines = \array_map( + fn (array $iterator) => Pipeline::fromIterable($iterator) + ->tap(fn () => delay(0.01)), + $array, + ); $pipeline = Pipeline::merge($pipelines); self::assertSame($expected, $pipeline->toArray()); } + /** + * @dataProvider getArrays + * @depends testMerge + */ + public function testMergeWithConcurrentMap(array $array, array $expected): void + { + $mapper = static fn (int $value) => $value * 10; + + $pipelines = \array_map( + fn (array $iterator) => Pipeline::fromIterable($iterator) + ->tap(fn () => delay(0.01)) + ->concurrent(3) + ->ordered() + ->map($mapper), + $array, + ); + + $pipeline = Pipeline::merge($pipelines); + + self::assertSame(\array_map($mapper, $expected), $pipeline->toArray()); + } + /** * @depends testMerge */ @@ -44,7 +65,6 @@ public function testMergeWithDelayedYields(): void $pipelines = []; $values1 = [$this->asyncValue(0.01, 1), $this->asyncValue(0.05, 2), $this->asyncValue(0.07, 3)]; $values2 = [$this->asyncValue(0.02, 4), $this->asyncValue(0.04, 5), $this->asyncValue(0.06, 6)]; - $expected = [1, 4, 5, 2, 6, 3]; $pipelines[] = Pipeline::fromIterable(function () use ($values1) { foreach ($values1 as $value) { @@ -60,7 +80,7 @@ public function testMergeWithDelayedYields(): void $pipeline = Pipeline::merge($pipelines); - self::assertSame($expected, $pipeline->toArray()); + self::assertSame([1, 4, 5, 2, 6, 3], $pipeline->toArray()); } /** @@ -90,8 +110,8 @@ public function testDisposedMerge(): void */ public function testMergeWithFailedPipeline(): void { - $exception = new TestException; - $generator = Pipeline::fromIterable(static function () use ($exception) { + $exception = new TestException(); + $generator = Pipeline::fromIterable(function () use ($exception) { yield 1; // Emit once before failing. throw $exception; });