Skip to content

Commit 6541b8b

Browse files
committed
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.
1 parent 87c08d5 commit 6541b8b

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/MongoDbSessionHandlerTest.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ protected function setUp()
3434
$mongoClass = version_compare(phpversion('mongo'), '1.3.0', '<') ? 'Mongo' : 'MongoClient';
3535

3636
$this->mongo = $this->getMockBuilder($mongoClass)
37+
->disableOriginalConstructor()
3738
->getMock();
3839

3940
$this->options = array(
@@ -202,13 +203,8 @@ public function testGc()
202203

203204
private function createMongoCollectionMock()
204205
{
205-
$mongoClient = $this->getMockBuilder('MongoClient')
206-
->getMock();
207-
$mongoDb = $this->getMockBuilder('MongoDB')
208-
->setConstructorArgs(array($mongoClient, 'database-name'))
209-
->getMock();
210206
$collection = $this->getMockBuilder('MongoCollection')
211-
->setConstructorArgs(array($mongoDb, 'collection-name'))
207+
->disableOriginalConstructor()
212208
->getMock();
213209

214210
return $collection;

0 commit comments

Comments
 (0)