Skip to content

Commit

Permalink
Another test
Browse files Browse the repository at this point in the history
  • Loading branch information
trowski committed Dec 21, 2023
1 parent 788cac6 commit 725bba9
Showing 1 changed file with 30 additions and 10 deletions.
40 changes: 30 additions & 10 deletions test/MergeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -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) {
Expand All @@ -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());
}

/**
Expand Down Expand Up @@ -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;
});
Expand Down

0 comments on commit 725bba9

Please sign in to comment.