diff --git a/CHANGELOG-1.0.md b/CHANGELOG-1.0.md index 38130e3a..55d74184 100644 --- a/CHANGELOG-1.0.md +++ b/CHANGELOG-1.0.md @@ -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) ------------------ diff --git a/lib/Mongo/MongoCollection.php b/lib/Mongo/MongoCollection.php index 570b54a8..d9ea40f1 100644 --- a/lib/Mongo/MongoCollection.php +++ b/lib/Mongo/MongoCollection.php @@ -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())); @@ -1010,4 +1016,3 @@ public function __sleep() return ['db', 'name']; } } - diff --git a/tests/Alcaeus/MongoDbAdapter/Mongo/MongoCollectionTest.php b/tests/Alcaeus/MongoDbAdapter/Mongo/MongoCollectionTest.php index a3ffecdd..450118af 100644 --- a/tests/Alcaeus/MongoDbAdapter/Mongo/MongoCollectionTest.php +++ b/tests/Alcaeus/MongoDbAdapter/Mongo/MongoCollectionTest.php @@ -1177,6 +1177,7 @@ public function testGetIndexInfo() { $collection = $this->getCollection(); $collection->createIndex(['foo' => 1]); + $collection->createIndex(['bar' => 1], ['unique' => true]); $expected = [ [ @@ -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() );