Skip to content
Browse files

Merge pull request #83 from doctrine/mongoclient

Support Mongo driver 1.3.1+ and MongoClient class
  • Loading branch information...
2 parents 5b08a48 + 9726159 commit e688ce284d1a7693a807103fe698b8daf51c3b87 @jmikola jmikola committed Dec 5, 2012
View
2 .travis.yml
@@ -5,7 +5,7 @@ php:
- 5.4
env:
- - MONGO_VERSION=1.2.12
+ - MONGO_VERSION=1.3.1
services: mongodb
View
2 composer.json
@@ -12,7 +12,7 @@
],
"require": {
"php": ">=5.3.2",
- "ext-mongo": ">=1.2.12,<1.3-dev",
+ "ext-mongo": ">=1.3.1,<1.4-dev",
"symfony/yaml": ">=2.0,<2.3-dev",
"symfony/console": ">=2.0,<2.3-dev",
"doctrine/common": ">=2.1.0,<2.5-dev"
View
10 lib/Doctrine/MongoDB/Collection.php
@@ -616,16 +616,6 @@ protected function doSave(array &$a, array $options)
return $this->getMongoCollection()->save($a, $options);
}
- public function setSlaveOkay($ok = true)
- {
- return $this->getMongoCollection()->setSlaveOkay($ok);
- }
-
- public function getSlaveOkay()
- {
- return $this->getMongoCollection()->getSlaveOkay();
- }
-
public function validate($scanData = false)
{
return $this->getMongoCollection()->validate($scanData);
View
18 lib/Doctrine/MongoDB/Connection.php
@@ -23,7 +23,7 @@
Doctrine\MongoDB\Event\EventArgs;
/**
- * Wrapper for the PHP Mongo class.
+ * Wrapper for the PHP MongoClient class.
*
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link www.doctrine-project.org
@@ -33,7 +33,7 @@
class Connection
{
/**
- * @var Mongo $mongo
+ * @var MongoClient $mongo
*/
protected $mongo;
@@ -67,14 +67,14 @@ class Connection
protected $cmd;
/**
- * Create a new Mongo wrapper instance.
+ * Create a new MongoClient wrapper instance.
*
* @param mixed $server A string server name, an existing Mongo instance or can be omitted.
* @param array $options
*/
public function __construct($server = null, array $options = array(), Configuration $config = null, EventManager $evm = null)
{
- if ($server instanceof \Mongo) {
+ if ($server instanceof \MongoClient) {
$this->mongo = $server;
} elseif ($server !== null) {
$this->server = $server;
@@ -95,7 +95,7 @@ public function initialize($reinitialize = false)
$server = $this->server;
$options = $this->options;
$this->mongo = $this->retry(function() use($server, $options) {
- return new \Mongo($server ?: 'mongodb://localhost:27017', $options);
+ return new \MongoClient($server ?: 'mongodb://localhost:27017', $options);
});
if ($this->eventManager->hasListeners(Events::postConnect)) {
@@ -145,19 +145,19 @@ public function log(array $log)
}
/**
- * Set the PHP Mongo instance to wrap.
+ * Set the PHP MongoClient instance to wrap.
*
- * @param Mongo $mongo The PHP Mongo instance
+ * @param MongoCient $mongo The PHP Mongo instance
*/
- public function setMongo(\Mongo $mongo)
+ public function setMongo(\MongoClient $mongo)
{
$this->mongo = $mongo;
}
/**
* Returns the PHP Mongo instance being wrapped.
*
- * @return Mongo
+ * @return MongoClient
*/
public function getMongo()
{
View
12 lib/Doctrine/MongoDB/Database.php
@@ -200,16 +200,6 @@ protected function doGetGridFs($name)
);
}
- public function setSlaveOkay($ok = true)
- {
- return $this->getMongoDB()->setSlaveOkay($ok);
- }
-
- public function getSlaveOkay()
- {
- return $this->getMongoDB()->getSlaveOkay();
- }
-
public function getProfilingLevel()
{
return $this->getMongoDB()->getProfilingLevel();
@@ -277,4 +267,4 @@ public function __toString()
{
return $this->name;
}
-}
+}
View
43 tests/Doctrine/MongoDB/Tests/CollectionTest.php
@@ -391,38 +391,7 @@ public function testSave()
$coll = $this->getTestCollection($mockConnection, $mongoCollection, $mockDatabase);
$document = array();
$result = $coll->save($document, array());
- $this->assertEquals(true, $result);
- }
-
- public function testSetSlaveOkay()
- {
- $mockConnection = $this->getMockConnection();
- $mongoCollection = $this->getMockMongoCollection();
- $mongoCollection->expects($this->once())
- ->method('setSlaveOkay')
- ->with(true)
- ->will($this->returnValue(false));
-
- $mockDatabase = $this->getMockDatabase();
- $coll = $this->getTestCollection($mockConnection, $mongoCollection, $mockDatabase);
- $document = array();
- $result = $coll->setSlaveOkay(true);
- $this->assertEquals(false, $result);
- }
-
- public function testGetSlaveOkay()
- {
- $mockConnection = $this->getMockConnection();
- $mongoCollection = $this->getMockMongoCollection();
- $mongoCollection->expects($this->once())
- ->method('getSlaveOkay')
- ->will($this->returnValue(false));
-
- $mockDatabase = $this->getMockDatabase();
- $coll = $this->getTestCollection($mockConnection, $mongoCollection, $mockDatabase);
- $document = array();
- $result = $coll->getSlaveOkay();
- $this->assertEquals(false, $result);
+ $this->assertArrayHasKeyValue(array('ok' => 1.0), $result);
}
public function testValidate()
@@ -490,6 +459,14 @@ private function getTestCollection(Connection $connection, MongoCollection $mong
$collection->setMongoCollection($mongoCollection);
return $collection;
}
+
+ private function assertArrayHasKeyValue($expected, $array, $message = '')
+ {
+ foreach ((array) $expected as $key => $value) {
+ $this->assertArrayHasKey($key, $expected, $message);
+ $this->assertEquals($value, $expected[$key], $message);
+ }
+ }
}
class TestLoggableCollectionStub extends LoggableCollection
@@ -516,4 +493,4 @@ public function getMongoCollection()
{
return $this->mongoCollection;
}
-}
+}
View
4 tests/Doctrine/MongoDB/Tests/ConnectionTest.php
@@ -13,7 +13,7 @@ public function testInitialize()
$conn = new Connection();
$this->assertNull($conn->getMongo());
$conn->initialize();
- $this->assertInstanceOf('Mongo', $conn->getMongo());
+ $this->assertInstanceOf('MongoClient', $conn->getMongo());
}
public function testLog()
@@ -138,4 +138,4 @@ private function getMockMongoCollection()
{
return $this->getMock('MongoCollection', array(), array(), '', false, false);
}
-}
+}
View
16 tests/Doctrine/MongoDB/Tests/Query/BuilderTest.php
@@ -190,7 +190,7 @@ public function testInsertQuery()
);
$this->assertEquals($expected, $qb->getNewObj());
$this->assertEquals(Query::TYPE_INSERT, $qb->getType());
- $this->assertTrue($qb->getQuery()->execute());
+ $this->assertArrayHasKeyValue(array('ok' => 1.0), $qb->getQuery()->execute());
}
public function testUpdateQuery()
@@ -209,7 +209,7 @@ public function testUpdateQuery()
$query = $qb->getQuery();
$this->assertEquals(Query::TYPE_UPDATE, $query->getType());
- $this->assertTrue($query->execute());
+ $this->assertArrayHasKeyValue(array('ok' => 1.0), $query->execute());
}
public function testRemoveQuery()
@@ -219,7 +219,7 @@ public function testRemoveQuery()
->field('username')->equals('jwage');
$this->assertEquals(Query::TYPE_REMOVE, $qb->getType());
- $this->assertTrue($qb->getQuery()->execute());
+ $this->assertArrayHasKeyValue(array('ok' => 1.0), $qb->getQuery()->execute());
}
/**
@@ -518,4 +518,12 @@ private function getTestQueryBuilder()
{
return $this->conn->selectCollection('db', 'users')->createQueryBuilder();
}
-}
+
+ private function assertArrayHasKeyValue($expected, $array, $message = '')
+ {
+ foreach ((array) $expected as $key => $value) {
+ $this->assertArrayHasKey($key, $expected, $message);
+ $this->assertEquals($value, $expected[$key], $message);
+ }
+ }
+}

0 comments on commit e688ce2

Please sign in to comment.
Something went wrong with that request. Please try again.