Просмотр исходного кода

Ensure correct return types in MongoDB class

Andreas Braun 10 лет назад
Родитель
Сommit
524ef02177
2 измененных файлов с 21 добавлено и 3 удалено
  1. 4 3
      lib/Mongo/MongoDB.php
  2. 17 0
      tests/Alcaeus/MongoDbAdapter/MongoDBTest.php

+ 4 - 3
lib/Mongo/MongoDB.php

@@ -14,6 +14,7 @@
  */
 
 use Alcaeus\MongoDbAdapter\Helper;
+use Alcaeus\MongoDbAdapter\TypeConverter;
 use MongoDB\Model\CollectionInfo;
 
 /**
@@ -220,7 +221,7 @@ class MongoDB
      */
     public function drop()
     {
-        return $this->db->drop();
+        return TypeConverter::convertObjectToLegacyArray($this->db->drop());
     }
 
     /**
@@ -233,7 +234,7 @@ class MongoDB
      */
     public function repair($preserve_cloned_files = FALSE, $backup_original_files = FALSE)
     {
-        return [];
+        $this->notImplemented();
     }
 
     /**
@@ -278,7 +279,7 @@ class MongoDB
             $coll = $coll->getName();
         }
 
-        return $this->db->dropCollection((string) $coll);
+        return TypeConverter::convertObjectToLegacyArray($this->db->dropCollection((string) $coll));
     }
 
     /**

+ 17 - 0
tests/Alcaeus/MongoDbAdapter/MongoDBTest.php

@@ -162,4 +162,21 @@ class MongoDBTest extends TestCase
 
         $this->fail('The test collection was not found');
     }
+
+    public function testDrop()
+    {
+        $this->getCollection()->insert(['foo' => 'bar']);
+        $this->assertSame(['dropped' => 'mongo-php-adapter', 'ok' => 1.0], $this->getDatabase()->drop());
+    }
+
+    public function testDropCollection()
+    {
+        $this->getCollection()->insert(['foo' => 'bar']);
+        $expected = [
+            'ns' => (string) $this->getCollection(),
+            'nIndexesWas' => 1,
+            'ok' => 1.0
+        ];
+        $this->assertSame($expected, $this->getDatabase()->dropCollection('test'));
+    }
 }