18
18
use PHPUnit \Framework \AssertionFailedError ;
19
19
use stdClass ;
20
20
use Throwable ;
21
- use Traversable ;
22
21
use function array_diff_key ;
23
22
use function array_key_exists ;
24
23
use function array_map ;
@@ -204,10 +203,6 @@ private function execute()
204
203
Assert::fail ('Unsupported entity type: ' . get_class ($ object ));
205
204
}
206
205
207
- if ($ result instanceof Traversable && ! $ result instanceof ChangeStream) {
208
- return iterator_to_array ($ result );
209
- }
210
-
211
206
return $ result ;
212
207
}
213
208
@@ -249,16 +244,16 @@ private function executeForClient(Client $client)
249
244
switch ($ this ->name ) {
250
245
case 'createChangeStream ' :
251
246
$ changeStream = $ client ->watch (
252
- $ args ['pipeline ' ] ?? [] ,
247
+ $ args ['pipeline ' ],
253
248
array_diff_key ($ args , ['pipeline ' => 1 ])
254
249
);
255
250
$ changeStream ->rewind ();
256
251
257
252
return $ changeStream ;
258
253
case 'listDatabaseNames ' :
259
- return $ client ->listDatabaseNames ($ args );
254
+ return iterator_to_array ( $ client ->listDatabaseNames ($ args) );
260
255
case 'listDatabases ' :
261
- return $ client ->listDatabases ($ args );
256
+ return iterator_to_array ( $ client ->listDatabases ($ args) );
262
257
default :
263
258
Assert::fail ('Unsupported client operation: ' . $ this ->name );
264
259
}
@@ -270,18 +265,18 @@ private function executeForCollection(Collection $collection)
270
265
271
266
switch ($ this ->name ) {
272
267
case 'aggregate ' :
273
- return $ collection ->aggregate (
268
+ return iterator_to_array ( $ collection ->aggregate (
274
269
$ args ['pipeline ' ],
275
270
array_diff_key ($ args , ['pipeline ' => 1 ])
276
- );
271
+ )) ;
277
272
case 'bulkWrite ' :
278
273
return $ collection ->bulkWrite (
279
274
array_map ('self::prepareBulkWriteRequest ' , $ args ['requests ' ]),
280
275
array_diff_key ($ args , ['requests ' => 1 ])
281
276
);
282
277
case 'createChangeStream ' :
283
278
$ changeStream = $ collection ->watch (
284
- $ args ['pipeline ' ] ?? [] ,
279
+ $ args ['pipeline ' ],
285
280
array_diff_key ($ args , ['pipeline ' => 1 ])
286
281
);
287
282
$ changeStream ->rewind ();
@@ -299,9 +294,8 @@ private function executeForCollection(Collection $collection)
299
294
);
300
295
case 'count ' :
301
296
case 'countDocuments ' :
302
- case 'find ' :
303
297
return $ collection ->{$ this ->name }(
304
- $ args ['filter ' ] ?? [] ,
298
+ $ args ['filter ' ],
305
299
array_diff_key ($ args , ['filter ' => 1 ])
306
300
);
307
301
case 'estimatedDocumentCount ' :
@@ -321,11 +315,16 @@ private function executeForCollection(Collection $collection)
321
315
322
316
return $ collection ->distinct (
323
317
$ args ['fieldName ' ],
324
- $ args ['filter ' ] ?? [] ,
318
+ $ args ['filter ' ],
325
319
array_diff_key ($ args , ['fieldName ' => 1 , 'filter ' => 1 ])
326
320
);
327
321
case 'drop ' :
328
322
return $ collection ->drop ($ args );
323
+ case 'find ' :
324
+ return iterator_to_array ($ collection ->find (
325
+ $ args ['filter ' ],
326
+ array_diff_key ($ args , ['filter ' => 1 ])
327
+ ));
329
328
case 'findOne ' :
330
329
return $ collection ->findOne ($ args ['filter ' ], array_diff_key ($ args , ['filter ' => 1 ]));
331
330
case 'findOneAndReplace ' :
@@ -378,7 +377,7 @@ private function executeForCollection(Collection $collection)
378
377
array_diff_key ($ args , ['document ' => 1 ])
379
378
);
380
379
case 'listIndexes ' :
381
- return $ collection ->listIndexes ($ args );
380
+ return iterator_to_array ( $ collection ->listIndexes ($ args) );
382
381
case 'mapReduce ' :
383
382
return $ collection ->mapReduce (
384
383
$ args ['map ' ],
@@ -397,13 +396,13 @@ private function executeForDatabase(Database $database)
397
396
398
397
switch ($ this ->name ) {
399
398
case 'aggregate ' :
400
- return $ database ->aggregate (
399
+ return iterator_to_array ( $ database ->aggregate (
401
400
$ args ['pipeline ' ],
402
401
array_diff_key ($ args , ['pipeline ' => 1 ])
403
- );
402
+ )) ;
404
403
case 'createChangeStream ' :
405
404
$ changeStream = $ database ->watch (
406
- $ args ['pipeline ' ] ?? [] ,
405
+ $ args ['pipeline ' ],
407
406
array_diff_key ($ args , ['pipeline ' => 1 ])
408
407
);
409
408
$ changeStream ->rewind ();
@@ -420,9 +419,9 @@ private function executeForDatabase(Database $database)
420
419
array_diff_key ($ args , ['collection ' => 1 ])
421
420
);
422
421
case 'listCollectionNames ' :
423
- return $ database ->listCollectionNames ($ args );
422
+ return iterator_to_array ( $ database ->listCollectionNames ($ args) );
424
423
case 'listCollections ' :
425
- return $ database ->listCollections ($ args );
424
+ return iterator_to_array ( $ database ->listCollections ($ args) );
426
425
case 'runCommand ' :
427
426
return $ database ->command (
428
427
$ args ['command ' ],
0 commit comments