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

Merge branch '1.0.x'

* 1.0.x:
  Fix handling of BSON types in TypeConverter
  Make options in createCollection optional
Andreas Braun 9 лет назад
Родитель
Сommit
70fc902ae8

+ 12 - 0
CHANGELOG-1.0.md

@@ -3,6 +3,18 @@ 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.
+
+ * [#155](https://github.com/alcaeus/mongo-php-adapter/pull/155) fixes the handling
+ of BSON types when converting legacy types to BSON types.
+ * [#154](https://github.com/alcaeus/mongo-php-adapter/pull/154) makes the `options`
+ parameter in `MongoDB::createCollection` optional.
+
 1.0.8 (2017-01-11)
 ------------------
 

+ 2 - 0
lib/Alcaeus/MongoDbAdapter/TypeConverter.php

@@ -41,6 +41,8 @@ class TypeConverter
         switch (true) {
             case $value instanceof TypeInterface:
                 return $value->toBSONType();
+            case $value instanceof BSON\Type:
+                return $value;
             case is_array($value):
             case is_object($value);
                 $result = [];

+ 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'])) {

+ 22 - 0
tests/Alcaeus/MongoDbAdapter/Mongo/MongoCollectionTest.php

@@ -2,6 +2,7 @@
 
 namespace Alcaeus\MongoDbAdapter\Tests\Mongo;
 
+use MongoDB\BSON\Regex;
 use MongoDB\Driver\ReadPreference;
 use Alcaeus\MongoDbAdapter\Tests\TestCase;
 
@@ -1784,6 +1785,27 @@ class MongoCollectionTest extends TestCase
         $this->assertCount(1, $items);
         $this->assertCount(1, $items[0]['loveItems']);
     }
+
+    public static function dataFindWithRegex()
+    {
+        return [
+            'MongoRegex' => [new \MongoRegex('/^foo.*/i')],
+            'BSONRegex' => [new Regex('^foo.*', 'i')],
+        ];
+    }
+
+    /**
+     * @dataProvider dataFindWithRegex
+     */
+    public function testFindWithRegex($regex)
+    {
+        $this->skipTestIf(extension_loaded('mongo'));
+        $document = ['name' => 'FOO 123'];
+        $this->getCollection()->insert($document);
+
+        $cursor = $this->getCollection()->find(['name' => $regex]);
+        $this->assertSame(1, $cursor->count());
+    }
 }
 
 class PrivatePropertiesStub

+ 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();