Skip to content
This repository has been archived by the owner on Nov 11, 2020. It is now read-only.

Fix Connection::isConnected() for driver versions 1.5.0+ #195

Merged
merged 2 commits into from
Dec 8, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
7 changes: 6 additions & 1 deletion lib/Doctrine/MongoDB/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down
15 changes: 15 additions & 0 deletions tests/Doctrine/MongoDB/Tests/ConnectionFunctionalTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace Doctrine\MongoDB\Tests;

class ConnectionFunctionalTest extends BaseTest
{
public function testIsConnected()
{
$this->assertFalse($this->conn->isConnected());
$this->conn->connect();
$this->assertTrue($this->conn->isConnected());
$this->conn->close();
$this->assertFalse($this->conn->isConnected());
}
}