-
Notifications
You must be signed in to change notification settings - Fork 264
PHPLIB-1419 Encode Agg builder objects in Collection methods #1383
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,9 @@ | |
|
||
namespace MongoDB\Tests; | ||
|
||
use MongoDB\Builder\Pipeline; | ||
use MongoDB\Builder\Query; | ||
use MongoDB\Builder\Stage; | ||
use MongoDB\Client; | ||
use MongoDB\Driver\BulkWrite; | ||
use MongoDB\Driver\Command; | ||
|
@@ -13,6 +16,7 @@ | |
|
||
use function call_user_func; | ||
use function is_callable; | ||
use function iterator_to_array; | ||
use function sprintf; | ||
|
||
/** | ||
|
@@ -137,4 +141,25 @@ public function testAddAndRemoveSubscriber(): void | |
|
||
$client->getManager()->executeCommand('admin', new Command(['ping' => 1])); | ||
} | ||
|
||
public function testWatchWithBuilderPipeline(): void | ||
{ | ||
$this->skipIfChangeStreamIsNotSupported(); | ||
|
||
if ($this->isShardedCluster()) { | ||
$this->markTestSkipped('Test does not apply on sharded clusters: need more than a single getMore call on the change stream.'); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I assume this was copied from 32bade4 also introduced I won't push for changing this, but wanted to provide some context. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the context. In fact, I've simplified the documentation example you pointed. Given what's being tested, I don't think it's essential for the test to run on all server typologies. |
||
|
||
$pipeline = new Pipeline( | ||
Stage::match(operationType: Query::eq('insert')), | ||
); | ||
// Extract the list of stages for arg type restriction | ||
$pipeline = iterator_to_array($pipeline); | ||
|
||
$changeStream = $this->client->watch($pipeline); | ||
$this->client->selectCollection($this->getDatabaseName(), $this->getCollectionName())->insertOne(['x' => 3]); | ||
$changeStream->next(); | ||
$this->assertTrue($changeStream->valid()); | ||
$this->assertEquals('insert', $changeStream->current()->operationType); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?php | ||
|
||
namespace MongoDB\Tests\Database; | ||
|
||
use MongoDB\Builder\Expression; | ||
use MongoDB\Builder\Pipeline; | ||
use MongoDB\Builder\Query; | ||
use MongoDB\Builder\Stage; | ||
|
||
use function iterator_to_array; | ||
|
||
class BuilderDatabaseFunctionalTest extends FunctionalTestCase | ||
{ | ||
public function tearDown(): void | ||
{ | ||
$this->dropCollection($this->getDatabaseName(), $this->getCollectionName()); | ||
|
||
parent::tearDown(); | ||
} | ||
|
||
public function testAggregate(): void | ||
{ | ||
$this->skipIfServerVersion('<', '6.0.0', '$documents stage is not supported'); | ||
|
||
$pipeline = new Pipeline( | ||
Stage::documents([ | ||
['x' => 1], | ||
['x' => 2], | ||
['x' => 3], | ||
]), | ||
Stage::bucketAuto( | ||
groupBy: Expression::intFieldPath('x'), | ||
buckets: 2, | ||
), | ||
); | ||
// Extract the list of stages for arg type restriction | ||
$pipeline = iterator_to_array($pipeline); | ||
|
||
$results = $this->database->aggregate($pipeline)->toArray(); | ||
$this->assertCount(2, $results); | ||
} | ||
|
||
public function testWatch(): void | ||
{ | ||
$this->skipIfChangeStreamIsNotSupported(); | ||
|
||
if ($this->isShardedCluster()) { | ||
$this->markTestSkipped('Test does not apply on sharded clusters: need more than a single getMore call on the change stream.'); | ||
} | ||
|
||
$pipeline = new Pipeline( | ||
Stage::match(operationType: Query::eq('insert')), | ||
); | ||
// Extract the list of stages for arg type restriction | ||
$pipeline = iterator_to_array($pipeline); | ||
|
||
$changeStream = $this->database->watch($pipeline); | ||
$this->database->selectCollection($this->getCollectionName())->insertOne(['x' => 3]); | ||
$changeStream->next(); | ||
$this->assertTrue($changeStream->valid()); | ||
$this->assertEquals('insert', $changeStream->current()->operationType); | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.