Skip to content

Commit

Permalink
Add new fields for listCollections command
Browse files Browse the repository at this point in the history
  • Loading branch information
alcaeus committed Aug 17, 2017
1 parent 96e5026 commit b4e4627
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
17 changes: 13 additions & 4 deletions lib/Mongo/MongoDB.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,19 @@ public function getCollectionInfo(array $options = [])
}

$getCollectionInfo = function (CollectionInfo $collectionInfo) {
return [
'name' => $collectionInfo->getName(),
'options' => $collectionInfo->getOptions(),
];
// @todo do away with __debugInfo once https://jira.mongodb.org/browse/PHPLIB-226 is fixed
$info = $collectionInfo->__debugInfo();

return array_filter(
[
'name' => $collectionInfo->getName(),
'type' => isset($info['type']) ? $info['type'] : null,
'options' => $collectionInfo->getOptions(),
'info' => isset($info['info']) ? (array) $info['info'] : null,
'idIndex' => isset($info['idIndex']) ? (array) $info['idIndex'] : null,
],
function ($item) { return $item !== null; }
);
};

$eligibleCollections = array_filter(
Expand Down
19 changes: 18 additions & 1 deletion tests/Alcaeus/MongoDbAdapter/Mongo/MongoDBTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,24 @@ public function testGetCollectionInfo()

foreach ($this->getDatabase()->getCollectionInfo() as $collectionInfo) {
if ($collectionInfo['name'] === 'test') {
$this->assertSame(['name' => 'test', 'options' => []], $collectionInfo);
$expected = [
'name' => 'test',
'options' => []
];

if (version_compare($this->getServerVersion(), '3.4.0', '>=')) {
$expected += [
'type' => 'collection',
'info' => ['readOnly' => false],
'idIndex' => [
'v' => $this->getDefaultIndexVersion(),
'key' => ['_id' => 1],
'name' => '_id_',
'ns' => (string) $this->getCollection(),
],
];
}
$this->assertEquals($expected, $collectionInfo);
return;
}
}
Expand Down

0 comments on commit b4e4627

Please sign in to comment.