don't call constructors on Mongo mock objects

Calling the parent constructor of the mocked `Mongo` class tries to
connect to a local MongoDB server which fails in case no local server
was configured.

Similarly, when the parent constructor of the mocked `MongoCollection`
class is called it performs checks on the passed arguments which fails
again when a connection was not established successfully before.
This commit is contained in:
Christian Flothmann 2015-10-28 22:19:48 +01:00
parent 87c08d5fe5
commit 6541b8b726
1 changed files with 2 additions and 6 deletions

View File

@ -34,6 +34,7 @@ class MongoDbSessionHandlerTest extends \PHPUnit_Framework_TestCase
$mongoClass = version_compare(phpversion('mongo'), '1.3.0', '<') ? 'Mongo' : 'MongoClient';
$this->mongo = $this->getMockBuilder($mongoClass)
->disableOriginalConstructor()
->getMock();
$this->options = array(
@ -202,13 +203,8 @@ class MongoDbSessionHandlerTest extends \PHPUnit_Framework_TestCase
private function createMongoCollectionMock()
{
$mongoClient = $this->getMockBuilder('MongoClient')
->getMock();
$mongoDb = $this->getMockBuilder('MongoDB')
->setConstructorArgs(array($mongoClient, 'database-name'))
->getMock();
$collection = $this->getMockBuilder('MongoCollection')
->setConstructorArgs(array($mongoDb, 'collection-name'))
->disableOriginalConstructor()
->getMock();
return $collection;