Unverified Commit 23e32ddc authored by Andreas Braun's avatar Andreas Braun

Merge pull request #718

parents 150177a5 a2f87dc6
......@@ -18,6 +18,8 @@
namespace MongoDB\Model;
use IteratorIterator;
use Traversable;
use function array_key_exists;
/**
* IndexInfoIterator for both listIndexes command and legacy query results.
......@@ -34,6 +36,19 @@ use IteratorIterator;
*/
class IndexInfoIteratorIterator extends IteratorIterator implements IndexInfoIterator
{
/** @var string|null $ns */
private $ns;
/**
* @param string|null $ns
*/
public function __construct(Traversable $iterator, $ns = null)
{
parent::__construct($iterator);
$this->ns = $ns;
}
/**
* Return the current element as an IndexInfo instance.
*
......@@ -43,6 +58,12 @@ class IndexInfoIteratorIterator extends IteratorIterator implements IndexInfoIte
*/
public function current()
{
return new IndexInfo(parent::current());
$info = parent::current();
if (! array_key_exists('ns', $info) && $this->ns !== null) {
$info['ns'] = $this->ns;
}
return new IndexInfo($info);
}
}
......@@ -149,6 +149,6 @@ class ListIndexes implements Executable
$cursor->setTypeMap(['root' => 'array', 'document' => 'array']);
return new IndexInfoIteratorIterator(new CachingIterator($cursor));
return new IndexInfoIteratorIterator(new CachingIterator($cursor), $this->databaseName . '.' . $this->collectionName);
}
}
......@@ -31,6 +31,7 @@ class ListIndexesFunctionalTest extends FunctionalTestCase
foreach ($indexes as $index) {
$this->assertInstanceOf(IndexInfo::class, $index);
$this->assertEquals(['_id' => 1], $index->getKey());
$this->assertSame($this->getNamespace(), $index->getNamespace());
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment