Ver Fonte

Ensure options in mongo uri of integer type to be integers after extracting them

Kevin de Heer há 6 anos atrás
pai
commit
1fe220e0c7

+ 2 - 0
lib/Mongo/MongoClient.php

@@ -376,6 +376,8 @@ class MongoClient
             $keyValue = explode('=', $option);
             if ($keyValue[0] === 'readPreferenceTags') {
                 $options[$keyValue[0]][] = $this->getReadPreferenceTags($keyValue[1]);
+            } elseif (ctype_digit($keyValue[1])) {
+                $options[$keyValue[0]] = (int) $keyValue[1];
             } else {
                 $options[$keyValue[0]] = $keyValue[1];
             }

+ 8 - 0
tests/Alcaeus/MongoDbAdapter/Mongo/MongoClientTest.php

@@ -279,6 +279,14 @@ class MongoClientTest extends TestCase
         $collection->insert($document);
     }
 
+    public function testConnectionUriOptionIntegerTypeCasting()
+    {
+        $client = new \MongoClient('mongodb://localhost/db?w=0&wtimeout=0', ['connect' => false]);
+
+        $this->skipTestIf(extension_loaded('mongo'));
+        $this->assertSame(['w' => 0, 'wtimeout' => 0], $client->getWriteConcern());
+    }
+
     /**
      * @param array $options
      * @return string