From 2a68c2acff94af8dc52ab762a015bebdf46e80af Mon Sep 17 00:00:00 2001 From: Jeremy Mikola Date: Mon, 8 Dec 2014 17:21:44 -0500 Subject: [PATCH 1/2] Allow 1.6.x driver versions in composer.json --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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": { From 7cc3ad0065b862fa8bbad8df5a59c163fd8561a4 Mon Sep 17 00:00:00 2001 From: Jeremy Mikola Date: Mon, 8 Dec 2014 17:22:13 -0500 Subject: [PATCH 2/2] Fix Connection::isConnected() for driver versions 1.5.0+ --- lib/Doctrine/MongoDB/Connection.php | 7 ++++++- .../MongoDB/Tests/ConnectionFunctionalTest.php | 15 +++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 tests/Doctrine/MongoDB/Tests/ConnectionFunctionalTest.php 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()); + } +}