Permalink
Browse files

Cast createCollection() options for MongoDB 2.6 compatibility

MongoDB 2.6 complains if the size/max options are non-numeric (e.g. null). See: doctrine/DoctrineMongoDBBundle#239
  • Loading branch information...
1 parent 9550db5 commit c832bd2ffe51d621e8ba13e08f584dd107080b72 @jmikola jmikola committed Apr 29, 2014
Showing with 29 additions and 0 deletions.
  1. +4 −0 lib/Doctrine/MongoDB/Database.php
  2. +25 −0 tests/Doctrine/MongoDB/Tests/DatabaseTest.php
View
4 lib/Doctrine/MongoDB/Database.php
@@ -128,6 +128,10 @@ public function createCollection($name, $cappedOrOptions = false, $size = 0, $ma
? array_merge(array('capped' => false, 'size' => 0, 'max' => 0), $cappedOrOptions)
: array('capped' => $cappedOrOptions, 'size' => $size, 'max' => $max);
+ $options['capped'] = (boolean) $options['capped'];
+ $options['size'] = (integer) $options['size'];
+ $options['max'] = (integer) $options['max'];
+
if ($this->eventManager->hasListeners(Events::preCreateCollection)) {
$this->eventManager->dispatchEvent(Events::preCreateCollection, new CreateCollectionEventArgs($this, $name, $options));
}
View
25 tests/Doctrine/MongoDB/Tests/DatabaseTest.php
@@ -60,6 +60,31 @@ public function testCreateCollectionWithOptionsArgument()
$this->assertInstanceOf('Doctrine\MongoDB\Collection', $collection);
}
+ public function testCreateCollectionCappedOptionsAreCast()
+ {
+ $mongoDB = $this->getMockMongoDB();
+
+ if (version_compare(phpversion('mongo'), '1.4.0', '>=')) {
+ $mongoDB->expects($this->once())
+ ->method('createCollection')
+ ->with('foo', array('capped' => false, 'size' => 0, 'max' => 0));
+ } else {
+ $mongoDB->expects($this->once())
+ ->method('createCollection')
+ ->with('foo', false, 0, 0);
+ }
+
+ $mongoDB->expects($this->once())
+ ->method('selectCollection')
+ ->with('foo')
+ ->will($this->returnValue($this->getMockMongoCollection()));
+
+ $database = new Database($this->getMockConnection(), $mongoDB, $this->getMockEventManager());
+ $collection = $database->createCollection('foo', array('capped' => 0, 'size' => null, 'max' => null));
+
+ $this->assertInstanceOf('Doctrine\MongoDB\Collection', $collection);
+ }
+
public function testGetSetSlaveOkay()
{
if (version_compare(phpversion('mongo'), '1.3.0', '>=')) {

0 comments on commit c832bd2

Please sign in to comment.