Parcourir la source

Make options in createCollection optional

Andreas Braun il y a 9 ans
Parent
commit
1a379307d4
3 fichiers modifiés avec 29 ajouts et 1 suppressions
  1. 10 0
      CHANGELOG-1.0.md
  2. 1 1
      lib/Mongo/MongoDB.php
  3. 18 0
      tests/Alcaeus/MongoDbAdapter/Mongo/MongoDBTest.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.9 (????-??-??)
+------------------
+
+All issues and pull requests under this release may be found under the
+[1.0.9](https://github.com/alcaeus/mongo-php-adapter/issues?q=milestone%3A1.0.9)
+milestone.
+
+ * [#154](https://github.com/alcaeus/mongo-php-adapter/pull/154) makes the `options`
+ parameter in `MongoDB::createCollection` optional.
+
 1.0.8 (2017-01-11)
 ------------------
 

+ 1 - 1
lib/Mongo/MongoDB.php

@@ -290,7 +290,7 @@ class MongoDB
      * @param array $options
      * @return MongoCollection Returns a collection object representing the new collection.
      */
-    public function createCollection($name, $options)
+    public function createCollection($name, $options = [])
     {
         try {
             if (isset($options['capped'])) {

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

@@ -55,6 +55,24 @@ class MongoDBTest extends TestCase
         $database->selectCollection('foo' . chr(0));
     }
 
+    public function testCreateCollectionWithoutOptions()
+    {
+        $database = $this->getDatabase();
+
+        $collection = $database->createCollection('test');
+        $this->assertInstanceOf('MongoCollection', $collection);
+
+        $checkDatabase = $this->getCheckDatabase();
+        foreach ($checkDatabase->listCollections() as $collectionInfo) {
+            if ($collectionInfo->getName() === 'test') {
+                $this->assertFalse($collectionInfo->isCapped());
+                return;
+            }
+        }
+
+        $this->fail('Did not find expected collection');
+    }
+
     public function testCreateCollection()
     {
         $database = $this->getDatabase();