Permalink
Browse files

the rest of the tests for SchemaManager

  • Loading branch information...
1 parent f0ddc56 commit 231dc888be3673658254aad3946e04440400b24c @avalanche123 avalanche123 committed Aug 23, 2010
Showing with 102 additions and 1 deletion.
  1. +102 −1 tests/Doctrine/ODM/MongoDB/Tests/SchemaManagerTest.php
@@ -141,6 +141,107 @@ public function testCreateCollections(array $classes)
$this->dm->getSchemaManager()->createCollections();
}
+ /**
+ * @dataProvider getIndexedClasses
+ */
+ public function testDropCollections(array $classes)
+ {
+ $metadatas = array();
+ foreach ($classes as $className) {
+ $metadata = $this->getClassMetadata($className);
+ $metadata->expects($this->once())
+ ->method('getCollection')
+ ->will($this->returnValue($className));
+ $documentDB = $this->getDocumentDB($className);
+ $documentDB->expects($this->once())
+ ->method('dropCollection')
+ ->with($className);
+ $this->dm->setDocumentDB($className, $documentDB);
+ $this->dm->setClassMetadata($className, $metadata);
+ $metadatas[] = $metadata;
+ }
+
+ $metadataFactory = $this->getMetadataFactory();
+ $metadataFactory->expects($this->once())
+ ->method('getAllMetadata')
+ ->will($this->returnValue($metadatas));
+
+ $this->dm->setMetadataFactory($metadataFactory);
+ $this->dm->setSchemaManager(new \Doctrine\ODM\MongoDB\SchemaManager($this->dm));
+
+ $this->dm->getSchemaManager()->dropCollections();
+ }
+
+ public function testDropDocumentCollection()
+ {
+ $className = 'Documents\CmsArticle';
+ $collectionName = 'cms_articles';
+ $classMetadata = $this->getClassMetadata($className);
+ $classMetadata->expects($this->once())
+ ->method('getCollection')
+ ->will($this->returnValue($collectionName));
+
+ $documentDB = $this->getDocumentDB($className);
+ $documentDB->expects($this->once())
+ ->method('dropCollection')
+ ->with($collectionName);
+ $this->dm->setDocumentDB($className, $documentDB);
+
+ $this->dm->setClassMetadata($className, $classMetadata);
+
+ $this->dm->getSchemaManager()->dropDocumentCollection($className);
+ }
+
+ public function testCreateDocumentDatabase()
+ {
+ $className = 'Documents\CmsArticle';
+ $dbName = 'test_db';
+ $mongo = $this->dm->getMongo();
+ $mongo->expects($this->once())
+ ->method('selectDB')
+ ->will($this->returnValue(new \MongoDB(new \Mongo(), $dbName))); // TODO: find a way to mock MongoDB instance
+
+ $this->dm->getSchemaManager()->createDocumentDatabase($className);
+ }
+
+ public function testDropDocumentDatabase()
+ {
+ $className = 'Documents\CmsArticle';
+ $dbName = 'test_db';
+
+ $documentDB = $this->getDocumentDB($className);
+ $documentDB->expects($this->once())
+ ->method('drop');
+ $this->dm->setDocumentDB($className, $documentDB);
+
+ $this->dm->getSchemaManager()->dropDocumentDatabase($className);
+ }
+
+ /**
+ * @dataProvider getIndexedClasses
+ */
+ public function testDropDatabases(array $classes)
+ {
+ $metadatas = array();
+ foreach ($classes as $className) {
+ $documentDB = $this->getDocumentDB($className);
+ $documentDB->expects($this->once())
+ ->method('drop');
+ $this->dm->setDocumentDB($className, $documentDB);
+ $metadatas[] = (object) array('name' => $className);
+ }
+
+ $metadataFactory = $this->getMetadataFactory();
+ $metadataFactory->expects($this->once())
+ ->method('getAllMetadata')
+ ->will($this->returnValue($metadatas));
+
+ $this->dm->setMetadataFactory($metadataFactory);
+ $this->dm->setSchemaManager(new \Doctrine\ODM\MongoDB\SchemaManager($this->dm));
+
+ $this->dm->getSchemaManager()->dropDatabases();
+ }
+
protected function getDocumentManager()
{
$config = new Configuration();
@@ -157,7 +258,7 @@ protected function getDocumentManager()
protected function getMongo()
{
- return $this->getMock('Doctrine\ODM\MongoDB\Mongo');
+ return $this->getMock('Doctrine\ODM\MongoDB\Mongo', array('selectDB'), array(), '', false, false);
}
protected function getMetadataFactory()

0 comments on commit 231dc88

Please sign in to comment.