Преглед изворни кода

Add new fields for listCollections command

Andreas Braun пре 8 година
родитељ
комит
b4e4627134
2 измењених фајлова са 31 додато и 5 уклоњено
  1. 13 4
      lib/Mongo/MongoDB.php
  2. 18 1
      tests/Alcaeus/MongoDbAdapter/Mongo/MongoDBTest.php

+ 13 - 4
lib/Mongo/MongoDB.php

@@ -143,10 +143,19 @@ class MongoDB
         }
 
         $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(

+ 18 - 1
tests/Alcaeus/MongoDbAdapter/Mongo/MongoDBTest.php

@@ -274,7 +274,24 @@ class MongoDBTest extends TestCase
 
         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;
             }
         }