From 80ce601eae98c076b1045a95c3cac2b8697c6728 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Wed, 14 Jan 2015 19:02:44 +0100 Subject: [PATCH] #881 DDC-2825 - refactoring test logic to use data-provider instead of code repetitions --- .../ORM/Functional/Ticket/DDC2825Test.php | 73 +++++++------------ 1 file changed, 28 insertions(+), 45 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2825Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2825Test.php index 230833e487b..b33d2fa30ac 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2825Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2825Test.php @@ -24,68 +24,51 @@ protected function setup() if ( ! $platform->supportsSchemas() && ! $platform->canEmulateSchemas()) { $this->markTestSkipped("This test is only useful for databases that support schemas or can emulate them."); } - - try { - $this->_schemaTool->createSchema(array( - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2825MySchemaMyTable'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2825MySchemaMyTable2'), - $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2825MySchemaOrder'), - )); - } catch (ToolsException $e) { - // tables already exist - } - } - - public function testMappingsContainCorrectlyDefinedOrEmulatedSchema() - { - $this->checkClassMetadata(DDC2825ClassWithExplicitlyDefinedSchema::CLASSNAME, 'myschema', 'mytable'); - $this->checkClassMetadata(DDC2825ClassWithImplicitlyDefinedSchema::CLASSNAME, 'myschema', 'mytable2'); - $this->checkClassMetadata(DDC2825ClassWithImplicitlyDefinedSchemaAndQuotedTableName::CLASSNAME, 'myschema', 'order'); } /** - * Test with a table with a schema + * @dataProvider getTestedClasses + * + * @param string $className + * @param string $schema + * @param string $table */ - public function testFetchingFromEntityWithExplicitlyDefinedSchemaInMappings() + public function testClassSchemaMappingsValidity($className, $schema, $table) { - $this->_em->persist(new DDC2825ClassWithExplicitlyDefinedSchema()); - $this->_em->flush(); - $this->_em->clear(); - - $this->assertCount( - 1, - $this->_em->getRepository(DDC2825ClassWithExplicitlyDefinedSchema::CLASSNAME)->findAll() - ); + $this->checkClassMetadata($className, $schema, $table); } /** - * Test with schema defined directly as a table annotation property + * @dataProvider getTestedClasses + * + * @param string $className */ - public function testFetchingFromEntityWithImplicitlyDefinedSchemaInMappings() + public function testPersistenceOfEntityWithSchemaMapping($className) { - $this->_em->persist(new DDC2825ClassWithImplicitlyDefinedSchema()); + try { + $this->_schemaTool->createSchema(array($this->_em->getClassMetadata($className))); + } catch (ToolsException $e) { + // table already exists + } + + $this->_em->persist(new $className()); $this->_em->flush(); $this->_em->clear(); - $this->assertCount( - 1, - $this->_em->getRepository(DDC2825ClassWithImplicitlyDefinedSchema::CLASSNAME)->findAll() - ); + $this->assertCount(1, $this->_em->getRepository($className)->findAll()); } /** - * Test with a table named "order" (which is a reserved keyword) to make sure the table name is not - * incorrectly escaped when a schema is used and that the platform doesn't support schemas + * Data provider + * + * @return string[][] */ - public function testFetchingFromEntityWithImplicitlyDefinedSchemaAndQuotedTableNameInMappings() + public function getTestedClasses() { - $this->_em->persist(new DDC2825ClassWithImplicitlyDefinedSchemaAndQuotedTableName()); - $this->_em->flush(); - $this->_em->clear(); - - $this->assertCount( - 1, - $this->_em->getRepository(DDC2825ClassWithImplicitlyDefinedSchemaAndQuotedTableName::CLASSNAME)->findAll() + return array( + array(DDC2825ClassWithExplicitlyDefinedSchema::CLASSNAME, 'myschema', 'mytable'), + array(DDC2825ClassWithImplicitlyDefinedSchema::CLASSNAME, 'myschema', 'mytable2'), + array(DDC2825ClassWithImplicitlyDefinedSchemaAndQuotedTableName::CLASSNAME, 'myschema', 'order'), ); } @@ -98,7 +81,7 @@ public function testFetchingFromEntityWithImplicitlyDefinedSchemaAndQuotedTableN * @param string $expectedSchemaName Expected schema name * @param string $expectedTableName Expected table name */ - protected function checkClassMetadata($className, $expectedSchemaName, $expectedTableName) + private function checkClassMetadata($className, $expectedSchemaName, $expectedTableName) { $classMetadata = $this->_em->getClassMetadata($className); $platform = $this->_em->getConnection()->getDatabasePlatform();