Explorar o código

Merge pull request #90 from alcaeus/force-database-string

Ensure database and collection names are cast to string
Andreas %!s(int64=9) %!d(string=hai) anos
pai
achega
985ec39df5

+ 10 - 0
CHANGELOG-1.0.md

@@ -3,6 +3,16 @@ CHANGELOG
 
 
 This changelog references the relevant changes done in minor version updates.
 This changelog references the relevant changes done in minor version updates.
 
 
+1.0.2 (????-??-??)
+------------------
+
+All issues and pull requests under this release may be found under the
+[1.0.2](https://github.com/alcaeus/mongo-php-adapter/issues?q=milestone%3A1.0.2)
+milestone.
+
+ * [#90](https://github.com/alcaeus/mongo-php-adapter/pull/90) ensures that database
+ and collection names are properly cast to string on creation.
+
 1.0.1 (2016-04-01)
 1.0.1 (2016-04-01)
 ------------------
 ------------------
 
 

+ 1 - 1
lib/Mongo/MongoCollection.php

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

+ 1 - 1
lib/Mongo/MongoDB.php

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

+ 1 - 1
lib/Mongo/MongoGridFS.php

@@ -70,7 +70,7 @@ class MongoGridFS extends MongoCollection
         }
         }
 
 
         $this->database = $db;
         $this->database = $db;
-        $this->prefix = $prefix;
+        $this->prefix = (string) $prefix;
         $this->filesName = $prefix . '.files';
         $this->filesName = $prefix . '.files';
         $this->chunksName = $prefix . '.chunks';
         $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->assertInstanceOf('MongoCollection', $collection->{'foo' . chr(0)});
         $this->assertSame('test', $collection->getName());
         $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
 class PrivatePropertiesStub