22
33namespace MongoDB \Tests \Collection ;
44
5+ use MongoDB \Builder \Expression ;
56use MongoDB \Builder \Pipeline ;
67use MongoDB \Builder \Query ;
78use MongoDB \Builder \Stage ;
89
10+ use function iterator_to_array ;
11+
912class BuilderCollectionFunctionalTest extends FunctionalTestCase
1013{
1114 public function setUp (): void
@@ -17,7 +20,18 @@ public function setUp(): void
1720
1821 public function testAggregate (): void
1922 {
20- $ this ->markTestSkipped ('Not supported yet ' );
23+ $ this ->collection ->insertMany ([['x ' => 10 ], ['x ' => 10 ], ['x ' => 10 ]]);
24+ $ pipeline = new Pipeline (
25+ Stage::bucketAuto (
26+ groupBy: Expression::intFieldPath ('x ' ),
27+ buckets: 2 ,
28+ ),
29+ );
30+ // Extract the list of stages for arg type restriction
31+ $ pipeline = iterator_to_array ($ pipeline );
32+
33+ $ results = $ this ->collection ->aggregate ($ pipeline )->toArray ();
34+ $ this ->assertCount (2 , $ results );
2135 }
2236
2337 public function testBulkWriteDeleteMany (): void
@@ -245,6 +259,24 @@ public function testUpdateManyWithPipeline(): void
245259
246260 public function testWatch (): void
247261 {
248- $ this ->markTestSkipped ('Not supported yet ' );
262+ $ this ->skipIfChangeStreamIsNotSupported ();
263+
264+ if ($ this ->isShardedCluster ()) {
265+ $ this ->markTestSkipped ('Test does not apply on sharded clusters: need more than a single getMore call on the change stream. ' );
266+ }
267+
268+ $ pipeline = new Pipeline (
269+ Stage::match (operationType: Query::eq ('insert ' )),
270+ );
271+ // Extract the list of stages for arg type restriction
272+ $ pipeline = iterator_to_array ($ pipeline );
273+
274+ $ changeStream = $ this ->collection ->watch ($ pipeline );
275+ $ changeStream ->rewind ();
276+ $ this ->assertNull ($ changeStream ->current ());
277+ $ this ->collection ->insertOne (['x ' => 3 ]);
278+ $ changeStream ->next ();
279+ $ this ->assertTrue ($ changeStream ->valid ());
280+ $ this ->assertEquals ('insert ' , $ changeStream ->current ()->operationType );
249281 }
250282}
0 commit comments