File tree Expand file tree Collapse file tree 3 files changed +24
-2
lines changed Expand file tree Collapse file tree 3 files changed +24
-2
lines changed Original file line number Diff line number Diff line change 18
18
namespace MongoDB \Model ;
19
19
20
20
use IteratorIterator ;
21
+ use Traversable ;
22
+ use function array_key_exists ;
21
23
22
24
/**
23
25
* IndexInfoIterator for both listIndexes command and legacy query results.
34
36
*/
35
37
class IndexInfoIteratorIterator extends IteratorIterator implements IndexInfoIterator
36
38
{
39
+ /** @var string|null $ns */
40
+ private $ ns ;
41
+
42
+ /**
43
+ * @param string|null $ns
44
+ */
45
+ public function __construct (Traversable $ iterator , $ ns = null )
46
+ {
47
+ parent ::__construct ($ iterator );
48
+
49
+ $ this ->ns = $ ns ;
50
+ }
51
+
37
52
/**
38
53
* Return the current element as an IndexInfo instance.
39
54
*
@@ -43,6 +58,12 @@ class IndexInfoIteratorIterator extends IteratorIterator implements IndexInfoIte
43
58
*/
44
59
public function current ()
45
60
{
46
- return new IndexInfo (parent ::current ());
61
+ $ info = parent ::current ();
62
+
63
+ if (! array_key_exists ('ns ' , $ info ) && $ this ->ns !== null ) {
64
+ $ info ['ns ' ] = $ this ->ns ;
65
+ }
66
+
67
+ return new IndexInfo ($ info );
47
68
}
48
69
}
Original file line number Diff line number Diff line change @@ -149,6 +149,6 @@ private function executeCommand(Server $server)
149
149
150
150
$ cursor ->setTypeMap (['root ' => 'array ' , 'document ' => 'array ' ]);
151
151
152
- return new IndexInfoIteratorIterator (new CachingIterator ($ cursor ));
152
+ return new IndexInfoIteratorIterator (new CachingIterator ($ cursor ), $ this -> databaseName . ' . ' . $ this -> collectionName );
153
153
}
154
154
}
Original file line number Diff line number Diff line change @@ -31,6 +31,7 @@ public function testListIndexesForNewlyCreatedCollection()
31
31
foreach ($ indexes as $ index ) {
32
32
$ this ->assertInstanceOf (IndexInfo::class, $ index );
33
33
$ this ->assertEquals (['_id ' => 1 ], $ index ->getKey ());
34
+ $ this ->assertSame ($ this ->getNamespace (), $ index ->getNamespace ());
34
35
}
35
36
}
36
37
You can’t perform that action at this time.
0 commit comments