Skip to content

Commit

Permalink
Reverse pipeline init from an array (#1596)
Browse files Browse the repository at this point in the history
  • Loading branch information
GromNaN authored Feb 10, 2025
1 parent 36cb899 commit b7e442a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 20 deletions.
18 changes: 8 additions & 10 deletions tests/Collection/BuilderCollectionFunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
use MongoDB\Builder\Stage;
use PHPUnit\Framework\Attributes\TestWith;

use function iterator_to_array;

class BuilderCollectionFunctionalTest extends FunctionalTestCase
{
public function setUp(): void
Expand All @@ -24,15 +22,15 @@ public function setUp(): void
public function testAggregate(bool $pipelineAsArray): void
{
$this->collection->insertMany([['x' => 10], ['x' => 10], ['x' => 10]]);
$pipeline = new Pipeline(
$pipeline = [
Stage::bucketAuto(
groupBy: Expression::intFieldPath('x'),
buckets: 2,
),
);
];

if ($pipelineAsArray) {
$pipeline = iterator_to_array($pipeline);
if (! $pipelineAsArray) {
$pipeline = new Pipeline(...$pipeline);
}

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

$pipeline = new Pipeline(
$pipeline = [
Stage::match(operationType: Query::eq('insert')),
);
];

if ($pipelineAsArray) {
$pipeline = iterator_to_array($pipeline);
if (! $pipelineAsArray) {
$pipeline = new Pipeline(...$pipeline);
}

$changeStream = $this->collection->watch($pipeline);
Expand Down
18 changes: 8 additions & 10 deletions tests/Database/BuilderDatabaseFunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
use MongoDB\Builder\Stage;
use PHPUnit\Framework\Attributes\TestWith;

use function iterator_to_array;

class BuilderDatabaseFunctionalTest extends FunctionalTestCase
{
public function tearDown(): void
Expand All @@ -25,7 +23,7 @@ public function testAggregate(bool $pipelineAsArray): void
{
$this->skipIfServerVersion('<', '6.0.0', '$documents stage is not supported');

$pipeline = new Pipeline(
$pipeline = [
Stage::documents([
['x' => 1],
['x' => 2],
Expand All @@ -35,10 +33,10 @@ public function testAggregate(bool $pipelineAsArray): void
groupBy: Expression::intFieldPath('x'),
buckets: 2,
),
);
];

if ($pipelineAsArray) {
$pipeline = iterator_to_array($pipeline);
if (! $pipelineAsArray) {
$pipeline = new Pipeline(...$pipeline);
}

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

$pipeline = new Pipeline(
$pipeline = [
Stage::match(operationType: Query::eq('insert')),
);
];

if ($pipelineAsArray) {
$pipeline = iterator_to_array($pipeline);
if (! $pipelineAsArray) {
$pipeline = new Pipeline(...$pipeline);
}

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

0 comments on commit b7e442a

Please sign in to comment.