Skip to content

Commit

Permalink
Merge branch 'fix-index-info' into 1.0.x
Browse files Browse the repository at this point in the history
Closes #117.

* fix-index-info:
  Add changelog entry
  Fix the Collection::getIndexInfo method for missing "unique" option
  • Loading branch information
alcaeus committed Jun 23, 2016
2 parents 92feaf5 + c923700 commit e93279c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG-1.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@ CHANGELOG

This changelog references the relevant changes done in minor version updates.

1.0.5 (xxxx-xx-xx)
------------------

All issues and pull requests under this release may be found under the
[1.0.5](https://github.com/alcaeus/mongo-php-adapter/issues?q=milestone%3A1.0.5)
milestone.

* [#117](https://github.com/alcaeus/mongo-php-adapter/pull/117) adds a missing
flag to indexes when calling `MongoCollection::getIndexInfo`.

1.0.4 (2016-06-22)
------------------

Expand Down
9 changes: 7 additions & 2 deletions lib/Mongo/MongoCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -706,12 +706,18 @@ public function deleteIndexes()
public function getIndexInfo()
{
$convertIndex = function(\MongoDB\Model\IndexInfo $indexInfo) {
return [
$infos = [
'v' => $indexInfo->getVersion(),
'key' => $indexInfo->getKey(),
'name' => $indexInfo->getName(),
'ns' => $indexInfo->getNamespace(),
];

if ($indexInfo->isUnique()) {
$infos['unique'] = true;
}

return $infos;
};

return array_map($convertIndex, iterator_to_array($this->collection->listIndexes()));
Expand Down Expand Up @@ -1010,4 +1016,3 @@ public function __sleep()
return ['db', 'name'];
}
}

10 changes: 9 additions & 1 deletion tests/Alcaeus/MongoDbAdapter/Mongo/MongoCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1177,6 +1177,7 @@ public function testGetIndexInfo()
{
$collection = $this->getCollection();
$collection->createIndex(['foo' => 1]);
$collection->createIndex(['bar' => 1], ['unique' => true]);

$expected = [
[
Expand All @@ -1191,9 +1192,16 @@ public function testGetIndexInfo()
'name' => 'foo_1',
'ns' => 'mongo-php-adapter.test',
],
[
'v' => 1,
'key' => ['bar' => 1],
'name' => 'bar_1',
'ns' => 'mongo-php-adapter.test',
'unique' => true,
],
];

$this->assertSame(
$this->assertEquals(
$expected,
$collection->getIndexInfo()
);
Expand Down

0 comments on commit e93279c

Please sign in to comment.