From ecfa0eee833e4549835a250e7fc5c3e96325f306 Mon Sep 17 00:00:00 2001 From: beberlei Date: Fri, 4 Dec 2009 23:03:08 +0000 Subject: [PATCH] [2.0] DDC-169 - Added tests for case-handling which is necessary for Comparator --- lib/Doctrine/DBAL/Schema/Table.php | 4 +- .../Tests/DBAL/Schema/ComparatorTest.php | 39 +++++++++++++++++++ .../Doctrine/Tests/DBAL/Schema/SchemaTest.php | 27 +++++++++++++ .../Doctrine/Tests/DBAL/Schema/TableTest.php | 28 +++++++++++++ 4 files changed, 96 insertions(+), 2 deletions(-) diff --git a/lib/Doctrine/DBAL/Schema/Table.php b/lib/Doctrine/DBAL/Schema/Table.php index 831f37866..a898c8c98 100644 --- a/lib/Doctrine/DBAL/Schema/Table.php +++ b/lib/Doctrine/DBAL/Schema/Table.php @@ -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; } /** diff --git a/tests/Doctrine/Tests/DBAL/Schema/ComparatorTest.php b/tests/Doctrine/Tests/DBAL/Schema/ComparatorTest.php index abdf92492..ea3925bf0 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/ComparatorTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/ComparatorTest.php @@ -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)); + } } \ No newline at end of file diff --git a/tests/Doctrine/Tests/DBAL/Schema/SchemaTest.php b/tests/Doctrine/Tests/DBAL/Schema/SchemaTest.php index b6eb865be..05974a541 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/SchemaTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/SchemaTest.php @@ -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"); diff --git a/tests/Doctrine/Tests/DBAL/Schema/TableTest.php b/tests/Doctrine/Tests/DBAL/Schema/TableTest.php index 608c3dd1a..3e99eff6f 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/TableTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/TableTest.php @@ -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');