Bladeren bron

Ensure database and collection names are cast to string

Andreas Braun 9 jaren geleden
bovenliggende
commit
b7ba46b68b

+ 1 - 1
lib/Mongo/MongoCollection.php

@@ -61,7 +61,7 @@ class MongoCollection
     {
         $this->checkCollectionName($name);
         $this->db = $db;
-        $this->name = $name;
+        $this->name = (string) $name;
 
         $this->setReadPreferenceFromArray($db->getReadPreference());
         $this->setWriteConcernFromArray($db->getWriteConcern());

+ 1 - 1
lib/Mongo/MongoDB.php

@@ -64,7 +64,7 @@ class MongoDB
     {
         $this->checkDatabaseName($name);
         $this->connection = $conn;
-        $this->name = $name;
+        $this->name = (string) $name;
 
         $this->setReadPreferenceFromArray($conn->getReadPreference());
         $this->setWriteConcernFromArray($conn->getWriteConcern());

+ 1 - 1
lib/Mongo/MongoGridFS.php

@@ -70,7 +70,7 @@ class MongoGridFS extends MongoCollection
         }
 
         $this->database = $db;
-        $this->prefix = $prefix;
+        $this->prefix = (string) $prefix;
         $this->filesName = $prefix . '.files';
         $this->chunksName = $prefix . '.chunks';
 

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

@@ -1479,6 +1479,15 @@ class MongoCollectionTest extends TestCase
         $this->assertInstanceOf('MongoCollection', $collection->{'foo' . chr(0)});
         $this->assertSame('test', $collection->getName());
     }
+
+    public function testSelectCollectionWithDatabaseObject()
+    {
+        $client = $this->getClient();
+        $database = $this->getDatabase($client);
+
+        $collection = $client->selectCollection($database, 'test');
+        $this->assertSame('mongo-php-adapter.test', (string) $collection);
+    }
 }
 
 class PrivatePropertiesStub