Skip to content

Commit b7e442a

Browse files
authored
Reverse pipeline init from an array (#1596)
1 parent 36cb899 commit b7e442a

File tree

2 files changed

+16
-20
lines changed

2 files changed

+16
-20
lines changed

tests/Collection/BuilderCollectionFunctionalTest.php

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
use MongoDB\Builder\Stage;
99
use PHPUnit\Framework\Attributes\TestWith;
1010

11-
use function iterator_to_array;
12-
1311
class BuilderCollectionFunctionalTest extends FunctionalTestCase
1412
{
1513
public function setUp(): void
@@ -24,15 +22,15 @@ public function setUp(): void
2422
public function testAggregate(bool $pipelineAsArray): void
2523
{
2624
$this->collection->insertMany([['x' => 10], ['x' => 10], ['x' => 10]]);
27-
$pipeline = new Pipeline(
25+
$pipeline = [
2826
Stage::bucketAuto(
2927
groupBy: Expression::intFieldPath('x'),
3028
buckets: 2,
3129
),
32-
);
30+
];
3331

34-
if ($pipelineAsArray) {
35-
$pipeline = iterator_to_array($pipeline);
32+
if (! $pipelineAsArray) {
33+
$pipeline = new Pipeline(...$pipeline);
3634
}
3735

3836
$results = $this->collection->aggregate($pipeline)->toArray();
@@ -272,12 +270,12 @@ public function testWatch(bool $pipelineAsArray): void
272270
$this->markTestSkipped('Test does not apply on sharded clusters: need more than a single getMore call on the change stream.');
273271
}
274272

275-
$pipeline = new Pipeline(
273+
$pipeline = [
276274
Stage::match(operationType: Query::eq('insert')),
277-
);
275+
];
278276

279-
if ($pipelineAsArray) {
280-
$pipeline = iterator_to_array($pipeline);
277+
if (! $pipelineAsArray) {
278+
$pipeline = new Pipeline(...$pipeline);
281279
}
282280

283281
$changeStream = $this->collection->watch($pipeline);

tests/Database/BuilderDatabaseFunctionalTest.php

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
use MongoDB\Builder\Stage;
99
use PHPUnit\Framework\Attributes\TestWith;
1010

11-
use function iterator_to_array;
12-
1311
class BuilderDatabaseFunctionalTest extends FunctionalTestCase
1412
{
1513
public function tearDown(): void
@@ -25,7 +23,7 @@ public function testAggregate(bool $pipelineAsArray): void
2523
{
2624
$this->skipIfServerVersion('<', '6.0.0', '$documents stage is not supported');
2725

28-
$pipeline = new Pipeline(
26+
$pipeline = [
2927
Stage::documents([
3028
['x' => 1],
3129
['x' => 2],
@@ -35,10 +33,10 @@ public function testAggregate(bool $pipelineAsArray): void
3533
groupBy: Expression::intFieldPath('x'),
3634
buckets: 2,
3735
),
38-
);
36+
];
3937

40-
if ($pipelineAsArray) {
41-
$pipeline = iterator_to_array($pipeline);
38+
if (! $pipelineAsArray) {
39+
$pipeline = new Pipeline(...$pipeline);
4240
}
4341

4442
$results = $this->database->aggregate($pipeline)->toArray();
@@ -55,12 +53,12 @@ public function testWatch(bool $pipelineAsArray): void
5553
$this->markTestSkipped('Test does not apply on sharded clusters: need more than a single getMore call on the change stream.');
5654
}
5755

58-
$pipeline = new Pipeline(
56+
$pipeline = [
5957
Stage::match(operationType: Query::eq('insert')),
60-
);
58+
];
6159

62-
if ($pipelineAsArray) {
63-
$pipeline = iterator_to_array($pipeline);
60+
if (! $pipelineAsArray) {
61+
$pipeline = new Pipeline(...$pipeline);
6462
}
6563

6664
$changeStream = $this->database->watch($pipeline);

0 commit comments

Comments
 (0)