diff --git a/Tests/Form/Type/DocumentTypeTest.php b/Tests/Form/Type/DocumentTypeTest.php index d5a7da72..79b17410 100644 --- a/Tests/Form/Type/DocumentTypeTest.php +++ b/Tests/Form/Type/DocumentTypeTest.php @@ -44,6 +44,11 @@ protected function setUp() if (!class_exists('Doctrine\\ODM\\MongoDB\\Version')) { $this->markTestSkipped('Doctrine MongoDB ODM is not available.'); } + try { + new \Mongo(); + } catch (\MongoException $e) { + $this->markTestSkipped('Unable to connect to Mongo.'); + } $this->documentManager = TestCase::createTestDocumentManager(); $this->documentManager->createQueryBuilder(self::DOCUMENT_CLASS) diff --git a/Tests/Security/DocumentUserProviderTest.php b/Tests/Security/DocumentUserProviderTest.php index 2266d585..328ea442 100644 --- a/Tests/Security/DocumentUserProviderTest.php +++ b/Tests/Security/DocumentUserProviderTest.php @@ -26,13 +26,13 @@ class DocumentUserProviderTest extends TestCase protected function setUp() { + parent::setUp(); + $this->documentManager = TestCase::createTestDocumentManager(); $this->documentManager->createQueryBuilder(self::DOCUMENT_CLASS) ->remove() ->getQuery() ->execute(); - - parent::setUp(); } public function testRefreshUserGetsUserByIdentifier() diff --git a/Tests/TestCase.php b/Tests/TestCase.php index 034ee804..885d3df5 100644 --- a/Tests/TestCase.php +++ b/Tests/TestCase.php @@ -29,6 +29,11 @@ protected function setUp() if (!class_exists('Doctrine\\ODM\\MongoDB\\Version')) { $this->markTestSkipped('Doctrine MongoDB ODM is not available.'); } + try { + new \Mongo(); + } catch (\MongoException $e) { + $this->markTestSkipped('Unable to connect to Mongo.'); + } } /** diff --git a/Tests/Validator/Constraints/UniqueValidatorTest.php b/Tests/Validator/Constraints/UniqueValidatorTest.php index 6c317e03..beed1943 100644 --- a/Tests/Validator/Constraints/UniqueValidatorTest.php +++ b/Tests/Validator/Constraints/UniqueValidatorTest.php @@ -35,12 +35,9 @@ protected function setUp() __DIR__ . '/../DependencyInjection/Fixtures/Bundles/AnnotationsBundle/Document' )); - $this->dropDocumentCollection(); - } - - protected function tearDown() - { - $this->dropDocumentCollection(); + $this->documentManager + ->getDocumentCollection('Symfony\Bundle\DoctrineMongoDBBundle\Tests\Fixtures\Validator\Document') + ->drop(); } public function testValidateUniquenessForScalarField() @@ -222,13 +219,6 @@ public function testEmbeddedDocumentIsNotUnsupported() $violationsList = $validator->validate(new EmbeddedDocument()); } - private function dropDocumentCollection() - { - if ($this->documentManager) { - $this->documentManager->getDocumentCollection('Doctrine\Bundle\MongoDBBundle\Tests\Fixtures\Validator\Document')->drop(); - } - } - private function createMockRegistry($documentManagerName = null) { $registry = $this->getMock('Doctrine\Common\Persistence\ManagerRegistry'); diff --git a/Tests/bootstrap.php b/Tests/bootstrap.php index 76885243..f1febb60 100644 --- a/Tests/bootstrap.php +++ b/Tests/bootstrap.php @@ -17,3 +17,11 @@ } elseif (file_exists($file = __DIR__.'/autoload.php.dist')) { require_once $file; } + +register_shutdown_function(function() { + try { + $mongo = new Mongo(); + $mongo->doctrine->drop(); + } catch (\MongoException $e) { + } +});