Skip to content

PHPLIB-1617 Reverse pipeline init from an array #1596

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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