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 1818namespace MongoDB \Model ;
1919
2020use IteratorIterator ;
21+ use Traversable ;
22+ use function array_key_exists ;
2123
2224/**
2325 * IndexInfoIterator for both listIndexes command and legacy query results.
3436 */
3537class IndexInfoIteratorIterator extends IteratorIterator implements IndexInfoIterator
3638{
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+
3752 /**
3853 * Return the current element as an IndexInfo instance.
3954 *
@@ -43,6 +58,12 @@ class IndexInfoIteratorIterator extends IteratorIterator implements IndexInfoIte
4358 */
4459 public function current ()
4560 {
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 );
4768 }
4869}
Original file line number Diff line number Diff line change @@ -149,6 +149,6 @@ private function executeCommand(Server $server)
149149
150150 $ cursor ->setTypeMap (['root ' => 'array ' , 'document ' => 'array ' ]);
151151
152- return new IndexInfoIteratorIterator (new CachingIterator ($ cursor ));
152+ return new IndexInfoIteratorIterator (new CachingIterator ($ cursor ), $ this -> databaseName . ' . ' . $ this -> collectionName );
153153 }
154154}
Original file line number Diff line number Diff line change @@ -31,6 +31,7 @@ public function testListIndexesForNewlyCreatedCollection()
3131 foreach ($ indexes as $ index ) {
3232 $ this ->assertInstanceOf (IndexInfo::class, $ index );
3333 $ this ->assertEquals (['_id ' => 1 ], $ index ->getKey ());
34+ $ this ->assertSame ($ this ->getNamespace (), $ index ->getNamespace ());
3435 }
3536 }
3637
You can’t perform that action at this time.
0 commit comments