#881 DDC-2825 - refactoring test logic to use data-provider instead of code repetitions
This commit is contained in:
parent
f874189456
commit
80ce601eae
@ -24,68 +24,51 @@ class DDC2825Test extends \Doctrine\Tests\OrmFunctionalTestCase
|
|||||||
if ( ! $platform->supportsSchemas() && ! $platform->canEmulateSchemas()) {
|
if ( ! $platform->supportsSchemas() && ! $platform->canEmulateSchemas()) {
|
||||||
$this->markTestSkipped("This test is only useful for databases that support schemas or can emulate them.");
|
$this->markTestSkipped("This test is only useful for databases that support schemas or can emulate them.");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider getTestedClasses
|
||||||
|
*
|
||||||
|
* @param string $className
|
||||||
|
* @param string $schema
|
||||||
|
* @param string $table
|
||||||
|
*/
|
||||||
|
public function testClassSchemaMappingsValidity($className, $schema, $table)
|
||||||
|
{
|
||||||
|
$this->checkClassMetadata($className, $schema, $table);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider getTestedClasses
|
||||||
|
*
|
||||||
|
* @param string $className
|
||||||
|
*/
|
||||||
|
public function testPersistenceOfEntityWithSchemaMapping($className)
|
||||||
|
{
|
||||||
try {
|
try {
|
||||||
$this->_schemaTool->createSchema(array(
|
$this->_schemaTool->createSchema(array($this->_em->getClassMetadata($className)));
|
||||||
$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2825MySchemaMyTable'),
|
|
||||||
$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2825MySchemaMyTable2'),
|
|
||||||
$this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2825MySchemaOrder'),
|
|
||||||
));
|
|
||||||
} catch (ToolsException $e) {
|
} catch (ToolsException $e) {
|
||||||
// tables already exist
|
// table already exists
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testMappingsContainCorrectlyDefinedOrEmulatedSchema()
|
$this->_em->persist(new $className());
|
||||||
{
|
|
||||||
$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
|
|
||||||
*/
|
|
||||||
public function testFetchingFromEntityWithExplicitlyDefinedSchemaInMappings()
|
|
||||||
{
|
|
||||||
$this->_em->persist(new DDC2825ClassWithExplicitlyDefinedSchema());
|
|
||||||
$this->_em->flush();
|
$this->_em->flush();
|
||||||
$this->_em->clear();
|
$this->_em->clear();
|
||||||
|
|
||||||
$this->assertCount(
|
$this->assertCount(1, $this->_em->getRepository($className)->findAll());
|
||||||
1,
|
|
||||||
$this->_em->getRepository(DDC2825ClassWithExplicitlyDefinedSchema::CLASSNAME)->findAll()
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test with schema defined directly as a table annotation property
|
* Data provider
|
||||||
|
*
|
||||||
|
* @return string[][]
|
||||||
*/
|
*/
|
||||||
public function testFetchingFromEntityWithImplicitlyDefinedSchemaInMappings()
|
public function getTestedClasses()
|
||||||
{
|
{
|
||||||
$this->_em->persist(new DDC2825ClassWithImplicitlyDefinedSchema());
|
return array(
|
||||||
$this->_em->flush();
|
array(DDC2825ClassWithExplicitlyDefinedSchema::CLASSNAME, 'myschema', 'mytable'),
|
||||||
$this->_em->clear();
|
array(DDC2825ClassWithImplicitlyDefinedSchema::CLASSNAME, 'myschema', 'mytable2'),
|
||||||
|
array(DDC2825ClassWithImplicitlyDefinedSchemaAndQuotedTableName::CLASSNAME, 'myschema', 'order'),
|
||||||
$this->assertCount(
|
|
||||||
1,
|
|
||||||
$this->_em->getRepository(DDC2825ClassWithImplicitlyDefinedSchema::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
|
|
||||||
*/
|
|
||||||
public function testFetchingFromEntityWithImplicitlyDefinedSchemaAndQuotedTableNameInMappings()
|
|
||||||
{
|
|
||||||
$this->_em->persist(new DDC2825ClassWithImplicitlyDefinedSchemaAndQuotedTableName());
|
|
||||||
$this->_em->flush();
|
|
||||||
$this->_em->clear();
|
|
||||||
|
|
||||||
$this->assertCount(
|
|
||||||
1,
|
|
||||||
$this->_em->getRepository(DDC2825ClassWithImplicitlyDefinedSchemaAndQuotedTableName::CLASSNAME)->findAll()
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -98,7 +81,7 @@ class DDC2825Test extends \Doctrine\Tests\OrmFunctionalTestCase
|
|||||||
* @param string $expectedSchemaName Expected schema name
|
* @param string $expectedSchemaName Expected schema name
|
||||||
* @param string $expectedTableName Expected table name
|
* @param string $expectedTableName Expected table name
|
||||||
*/
|
*/
|
||||||
protected function checkClassMetadata($className, $expectedSchemaName, $expectedTableName)
|
private function checkClassMetadata($className, $expectedSchemaName, $expectedTableName)
|
||||||
{
|
{
|
||||||
$classMetadata = $this->_em->getClassMetadata($className);
|
$classMetadata = $this->_em->getClassMetadata($className);
|
||||||
$platform = $this->_em->getConnection()->getDatabasePlatform();
|
$platform = $this->_em->getConnection()->getDatabasePlatform();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user