File tree 4 files changed +24
-3
lines changed
tests/Alcaeus/MongoDbAdapter
4 files changed +24
-3
lines changed Original file line number Diff line number Diff line change @@ -277,7 +277,7 @@ protected function ensureIterator()
277
277
* @param \Traversable $traversable
278
278
* @return \Generator
279
279
*/
280
- private function wrapTraversable (\Traversable $ traversable )
280
+ protected function wrapTraversable (\Traversable $ traversable )
281
281
{
282
282
foreach ($ traversable as $ key => $ value ) {
283
283
yield $ key => $ value ;
Original file line number Diff line number Diff line change @@ -426,6 +426,20 @@ protected function ensureCursor()
426
426
return $ this ->cursor ;
427
427
}
428
428
429
+ /**
430
+ * @param \Traversable $traversable
431
+ * @return \Generator
432
+ */
433
+ protected function wrapTraversable (\Traversable $ traversable )
434
+ {
435
+ foreach ($ traversable as $ key => $ value ) {
436
+ if (isset ($ value ->_id ) && ($ value ->_id instanceof \MongoDB \BSON \ObjectID || !is_object ($ value ->_id ))) {
437
+ $ key = (string ) $ value ->_id ;
438
+ }
439
+ yield $ key => $ value ;
440
+ }
441
+ }
442
+
429
443
/**
430
444
* @return array
431
445
*/
Original file line number Diff line number Diff line change @@ -35,7 +35,7 @@ public function testInfo()
35
35
$ this ->assertEquals ($ expected , $ cursor ->info ());
36
36
37
37
// Ensure cursor started iterating
38
- iterator_to_array ($ cursor );
38
+ $ array = iterator_to_array ($ cursor );
39
39
40
40
$ expected ['started_iterating ' ] = true ;
41
41
$ expected += [
@@ -49,5 +49,11 @@ public function testInfo()
49
49
];
50
50
51
51
$ this ->assertEquals ($ expected , $ cursor ->info ());
52
+
53
+ $ i = 0 ;
54
+ foreach ($ array as $ key => $ value ) {
55
+ $ this ->assertEquals ($ i , $ key );
56
+ $ i ++;
57
+ }
52
58
}
53
59
}
Original file line number Diff line number Diff line change @@ -19,9 +19,10 @@ public function testCursorConvertsTypes()
19
19
$ this ->assertCount (2 , $ cursor );
20
20
21
21
$ iterated = 0 ;
22
- foreach ($ cursor as $ item ) {
22
+ foreach ($ cursor as $ key => $ item ) {
23
23
$ iterated ++;
24
24
$ this ->assertInstanceOf ('MongoId ' , $ item ['_id ' ]);
25
+ $ this ->assertEquals ($ key , (string ) $ item ['_id ' ]);
25
26
$ this ->assertSame ('bar ' , $ item ['foo ' ]);
26
27
}
27
28
You can’t perform that action at this time.
0 commit comments