소스 검색

Merge branch 'fix-index-info' into 1.0.x

Closes #117.

* fix-index-info:
  Add changelog entry
  Fix the Collection::getIndexInfo method for missing "unique" option
Andreas Braun 9 년 전
부모
커밋
e93279ce41
3개의 변경된 파일26개의 추가작업 그리고 3개의 파일을 삭제
  1. 10 0
      CHANGELOG-1.0.md
  2. 7 2
      lib/Mongo/MongoCollection.php
  3. 9 1
      tests/Alcaeus/MongoDbAdapter/Mongo/MongoCollectionTest.php

+ 10 - 0
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)
 ------------------
 

+ 7 - 2
lib/Mongo/MongoCollection.php

@@ -706,12 +706,18 @@ class MongoCollection
     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 @@ class MongoCollection
         return ['db', 'name'];
     }
 }
-

+ 9 - 1
tests/Alcaeus/MongoDbAdapter/Mongo/MongoCollectionTest.php

@@ -1177,6 +1177,7 @@ class MongoCollectionTest extends TestCase
     {
         $collection = $this->getCollection();
         $collection->createIndex(['foo' => 1]);
+        $collection->createIndex(['bar' => 1], ['unique' => true]);
 
         $expected = [
             [
@@ -1191,9 +1192,16 @@ class MongoCollectionTest extends TestCase
                 '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()
         );