Skip to content

Commit

Permalink
#881 DDC-2825 - refactoring test logic to use data-provider instead o…
Browse files Browse the repository at this point in the history
…f code repetitions
  • Loading branch information
Ocramius committed Jan 14, 2015
1 parent f874189 commit 80ce601
Showing 1 changed file with 28 additions and 45 deletions.
73 changes: 28 additions & 45 deletions tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2825Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
);
}

Expand All @@ -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();
Expand Down

0 comments on commit 80ce601

Please sign in to comment.