瀏覽代碼

Ensure correct return types in MongoDB class

Andreas Braun 10 年之前
父節點
當前提交
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\Helper;
+use Alcaeus\MongoDbAdapter\TypeConverter;
 use MongoDB\Model\CollectionInfo;
 use MongoDB\Model\CollectionInfo;
 
 
 /**
 /**
@@ -220,7 +221,7 @@ class MongoDB
      */
      */
     public function drop()
     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)
     public function repair($preserve_cloned_files = FALSE, $backup_original_files = FALSE)
     {
     {
-        return [];
+        $this->notImplemented();
     }
     }
 
 
     /**
     /**
@@ -278,7 +279,7 @@ class MongoDB
             $coll = $coll->getName();
             $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');
         $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'));
+    }
 }
 }