1
0
mirror of synced 2024-12-12 22:36:02 +03:00

[2.0] DDC-169 - Added tests for case-handling which is necessary for Comparator

This commit is contained in:
beberlei 2009-12-04 23:03:08 +00:00
parent 0788cdf15e
commit ecfa0eee83
4 changed files with 96 additions and 2 deletions

View File

@ -196,14 +196,14 @@ class Table extends AbstractAsset
* @param string $columnName
* @param string $columnType
* @param array $options
* @return Table
* @return Column
*/
public function createColumn($columnName, $typeName, array $options=array())
{
$column = new Column($columnName, Type::getType($typeName), $options);
$this->_addColumn($column);
return $this;
return $column;
}
/**

View File

@ -471,4 +471,43 @@ class ComparatorTest extends \PHPUnit_Framework_TestCase
$this->assertType('Doctrine\DBAL\Schema\TableDiff', $tableDiff);
$this->assertEquals(1, count($tableDiff->changedForeignKeys));
}
public function testTablesCaseInsensitive()
{
$schemaA = new Schema();
$schemaA->createTable('foo');
$schemaA->createTable('bAr');
$schemaA->createTable('BAZ');
$schemaA->createTable('new');
$schemaB = new Schema();
$schemaB->createTable('FOO');
$schemaB->createTable('bar');
$schemaB->createTable('Baz');
$schemaB->createTable('old');
$c = new Comparator();
$diff = $c->compare($schemaA, $schemaB);
$this->assertSchemaTableChangeCount($diff, 1, 0, 1);
}
public function testSequencesCaseInsenstive()
{
}
/**
*
* @param SchemaDiff $diff
* @param int $newTableCount
* @param int $changeTableCount
* @param int $removeTableCount
*/
public function assertSchemaTableChangeCount($diff, $newTableCount=0, $changeTableCount=0, $removeTableCount=0)
{
$this->assertEquals($newTableCount, count($diff->newTables));
$this->assertEquals($changeTableCount, count($diff->changedTables));
$this->assertEquals($removeTableCount, count($diff->removedTables));
}
}

View File

@ -26,6 +26,19 @@ class SchemaTest extends \PHPUnit_Framework_TestCase
$this->assertTrue($schema->hasTable($tableName));
}
public function testTableMatchingCaseInsenstive()
{
$table = new Table("Foo");
$schema = new Schema(array($table));
$this->assertTrue($schema->hasTable("foo"));
$this->assertTrue($schema->hasTable("FOO"));
$this->assertSame($table, $schema->getTable('FOO'));
$this->assertSame($table, $schema->getTable('foo'));
$this->assertSame($table, $schema->getTable('Foo'));
}
public function testGetUnknownTableThrowsException()
{
$this->setExpectedException("Doctrine\DBAL\Schema\SchemaException");
@ -97,6 +110,20 @@ class SchemaTest extends \PHPUnit_Framework_TestCase
$this->assertArrayHasKey('a_seq', $sequences);
}
public function testSequenceAccessCaseInsensitive()
{
$sequence = new Sequence("a_Seq");
$schema = new Schema(array(), array($sequence));
$this->assertTrue($schema->hasSequence('a_seq'));
$this->assertTrue($schema->hasSequence('a_Seq'));
$this->assertTrue($schema->hasSequence('A_SEQ'));
$this->assertEquals($sequence, $schema->getSequence('a_seq'));
$this->assertEquals($sequence, $schema->getSequence('a_Seq'));
$this->assertEquals($sequence, $schema->getSequence('A_SEQ'));
}
public function testGetUnknownSequenceThrowsException()
{
$this->setExpectedException("Doctrine\DBAL\Schema\SchemaException");

View File

@ -38,6 +38,20 @@ class TableTest extends \PHPUnit_Framework_TestCase
$this->assertEquals(2, count($table->getColumns()));
}
public function testColumnsCaseInsensitive()
{
$table = new Table("foo");
$column = $table->createColumn('Foo', 'integer');
$this->assertTrue($table->hasColumn('Foo'));
$this->assertTrue($table->hasColumn('foo'));
$this->assertTrue($table->hasColumn('FOO'));
$this->assertSame($column, $table->getColumn('Foo'));
$this->assertSame($column, $table->getColumn('foo'));
$this->assertSame($column, $table->getColumn('FOO'));
}
public function testCreateColumn()
{
$type = Type::getType('integer');
@ -91,6 +105,7 @@ class TableTest extends \PHPUnit_Framework_TestCase
$type = \Doctrine\DBAL\Types\Type::getType('integer');
$columns = array(new Column("foo", $type), new Column("bar", $type), new Column("baz", $type));
$table = new Table("foo", $columns);
$table->addIndex(array("foo", "bar", "baz"));
$table->addUniqueIndex(array("foo", "bar", "baz"));
@ -98,6 +113,19 @@ class TableTest extends \PHPUnit_Framework_TestCase
$this->assertTrue($table->hasIndex("foo_bar_baz_uniq"));
}
public function testIndexCaseInsensitive()
{
$type = \Doctrine\DBAL\Types\Type::getType('integer');
$columns = array(new Column("foo", $type), new Column("bar", $type), new Column("baz", $type));
$table = new Table("foo", $columns);
$table->addIndex(array("foo", "bar", "baz"), "Foo_Idx");
$this->assertTrue($table->hasIndex('foo_idx'));
$this->assertTrue($table->hasIndex('Foo_Idx'));
$this->assertTrue($table->hasIndex('FOO_IDX'));
}
public function testAddIndexes()
{
$type = \Doctrine\DBAL\Types\Type::getType('integer');