diff --git a/composer.json b/composer.json index d7e330f8..8bbca5e9 100644 --- a/composer.json +++ b/composer.json @@ -13,7 +13,7 @@ ], "require": { "php": ">=5.3.2", - "ext-mongo": ">=1.2.12,<1.6-dev", + "ext-mongo": ">=1.2.12,<1.7-dev", "doctrine/common": ">=2.1.0,<2.5-dev" }, "autoload": { diff --git a/lib/Doctrine/MongoDB/Connection.php b/lib/Doctrine/MongoDB/Connection.php index 32731820..cf15ef0d 100644 --- a/lib/Doctrine/MongoDB/Connection.php +++ b/lib/Doctrine/MongoDB/Connection.php @@ -143,7 +143,12 @@ public function isConnected() return false; } - return $this->mongo->connected; + /* MongoClient::$connected is deprecated in 1.5.0+, so count the list of + * connected hosts instead. + */ + return version_compare(phpversion('mongo'), '1.5.0', '<') + ? $this->mongo->connected + : count($this->mongo->getHosts()) > 0; } /** diff --git a/tests/Doctrine/MongoDB/Tests/ConnectionFunctionalTest.php b/tests/Doctrine/MongoDB/Tests/ConnectionFunctionalTest.php new file mode 100644 index 00000000..c1704dfc --- /dev/null +++ b/tests/Doctrine/MongoDB/Tests/ConnectionFunctionalTest.php @@ -0,0 +1,15 @@ +assertFalse($this->conn->isConnected()); + $this->conn->connect(); + $this->assertTrue($this->conn->isConnected()); + $this->conn->close(); + $this->assertFalse($this->conn->isConnected()); + } +}