From 946fa6d7cab73de2b48bcb8ec0cd46f5faee47f9 Mon Sep 17 00:00:00 2001 From: beberlei Date: Thu, 25 Feb 2010 21:51:30 +0000 Subject: [PATCH] [2.0] Refactored Doctrine\DBAL\Schema API a bit Table::createColumn() was inconsistent with all the other methods being add* --- lib/Doctrine/DBAL/Schema/Table.php | 2 +- lib/Doctrine/ORM/Tools/SchemaTool.php | 6 ++-- .../SchemaManagerFunctionalTestCase.php | 20 +++++------ .../Platforms/AbstractPlatformTestCase.php | 8 ++--- .../DBAL/Platforms/MySqlPlatformTest.php | 2 +- .../Tests/DBAL/Schema/ComparatorTest.php | 34 +++++++++---------- .../Doctrine/Tests/DBAL/Schema/SchemaTest.php | 14 ++++---- .../Doctrine/Tests/DBAL/Schema/TableTest.php | 28 +++++++-------- .../Schema/Visitor/SchemaSqlCollectorTest.php | 6 ++-- .../ORM/Functional/DatabaseDriverTest.php | 10 +++--- 10 files changed, 65 insertions(+), 65 deletions(-) diff --git a/lib/Doctrine/DBAL/Schema/Table.php b/lib/Doctrine/DBAL/Schema/Table.php index 4a91b0f38..c514f8f8f 100644 --- a/lib/Doctrine/DBAL/Schema/Table.php +++ b/lib/Doctrine/DBAL/Schema/Table.php @@ -263,7 +263,7 @@ class Table extends AbstractAsset * @param array $options * @return Column */ - public function createColumn($columnName, $typeName, array $options=array()) + public function addColumn($columnName, $typeName, array $options=array()) { $column = new Column($columnName, Type::getType($typeName), $options); diff --git a/lib/Doctrine/ORM/Tools/SchemaTool.php b/lib/Doctrine/ORM/Tools/SchemaTool.php index 22633ac3e..87188c0af 100644 --- a/lib/Doctrine/ORM/Tools/SchemaTool.php +++ b/lib/Doctrine/ORM/Tools/SchemaTool.php @@ -244,7 +244,7 @@ class SchemaTool $discrColumn['length'] = 255; } - $table->createColumn( + $table->addColumn( $class->getQuotedDiscriminatorColumnName($this->_platform), $discrColumn['type'], array('length' => $discrColumn['length'], 'notnull' => true) @@ -324,7 +324,7 @@ class SchemaTool // required in some inheritence scenarios $table->changeColumn($columnName, $options); } else { - $table->createColumn($columnName, $columnType, $options); + $table->addColumn($columnName, $columnType, $options); } $isUnique = isset($mapping['unique']) ? $mapping['unique'] : false; @@ -433,7 +433,7 @@ class SchemaTool $columnOptions['notnull'] = !$joinColumn['nullable']; } - $theJoinTable->createColumn( + $theJoinTable->addColumn( $columnName, $class->getTypeOfColumn($joinColumn['referencedColumnName']), $columnOptions ); } diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php index 899711749..d663ea58d 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php @@ -91,13 +91,13 @@ class SchemaManagerFunctionalTestCase extends \Doctrine\Tests\DbalFunctionalTest public function testListTableColumns() { $table = new \Doctrine\DBAL\Schema\Table('list_table_columns'); - $table->createColumn('id', 'integer', array('notnull' => true)); - $table->createColumn('test', 'string', array('length' => 255, 'notnull' => false)); - $table->createColumn('foo', 'text', array('notnull' => true)); - $table->createColumn('bar', 'decimal', array('precision' => 10, 'scale' => 4, 'notnull' => false)); - $table->createColumn('baz1', 'datetime'); - $table->createColumn('baz2', 'time'); - $table->createColumn('baz3', 'date'); + $table->addColumn('id', 'integer', array('notnull' => true)); + $table->addColumn('test', 'string', array('length' => 255, 'notnull' => false)); + $table->addColumn('foo', 'text', array('notnull' => true)); + $table->addColumn('bar', 'decimal', array('precision' => 10, 'scale' => 4, 'notnull' => false)); + $table->addColumn('baz1', 'datetime'); + $table->addColumn('baz2', 'time'); + $table->addColumn('baz3', 'date'); $this->_sm->dropAndCreateTable($table); @@ -370,10 +370,10 @@ class SchemaManagerFunctionalTestCase extends \Doctrine\Tests\DbalFunctionalTest $table = new \Doctrine\DBAL\Schema\Table($name, array(), array(), array(), \Doctrine\DBAL\Schema\Table::ID_NONE, $options); $table->setSchemaConfig($this->_sm->createSchemaConfig()); $table->setIdGeneratorType(\Doctrine\DBAL\Schema\Table::ID_IDENTITY); - $table->createColumn('id', 'integer', array('notnull' => true)); + $table->addColumn('id', 'integer', array('notnull' => true)); $table->setPrimaryKey(array('id')); - $table->createColumn('test', 'string', array('length' => 255)); - $table->createColumn('foreign_key_test', 'integer'); + $table->addColumn('test', 'string', array('length' => 255)); + $table->addColumn('foreign_key_test', 'integer'); return $table; } diff --git a/tests/Doctrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php b/tests/Doctrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php index 6918254c9..c00b0257c 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php @@ -27,8 +27,8 @@ abstract class AbstractPlatformTestCase extends \Doctrine\Tests\DbalTestCase public function testGeneratesTableCreationSql() { $table = new \Doctrine\DBAL\Schema\Table('test'); - $table->createColumn('id', 'integer', array('notnull' => true)); - $table->createColumn('test', 'string', array('notnull' => false, 'length' => 255)); + $table->addColumn('id', 'integer', array('notnull' => true)); + $table->addColumn('test', 'string', array('notnull' => false, 'length' => 255)); $table->setPrimaryKey(array('id')); $table->setIdGeneratorType(\Doctrine\DBAL\Schema\Table::ID_IDENTITY); @@ -41,8 +41,8 @@ abstract class AbstractPlatformTestCase extends \Doctrine\Tests\DbalTestCase public function testGenerateTableWithMultiColumnUniqueIndex() { $table = new \Doctrine\DBAL\Schema\Table('test'); - $table->createColumn('foo', 'string', array('notnull' => false, 'length' => 255)); - $table->createColumn('bar', 'string', array('notnull' => false, 'length' => 255)); + $table->addColumn('foo', 'string', array('notnull' => false, 'length' => 255)); + $table->addColumn('bar', 'string', array('notnull' => false, 'length' => 255)); $table->addUniqueIndex(array("foo", "bar")); $sql = $this->_platform->getCreateTableSql($table); diff --git a/tests/Doctrine/Tests/DBAL/Platforms/MySqlPlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/MySqlPlatformTest.php index 60a48087f..94bdeaf67 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/MySqlPlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/MySqlPlatformTest.php @@ -17,7 +17,7 @@ class MySqlPlatformTest extends AbstractPlatformTestCase public function testGenerateMixedCaseTableCreate() { $table = new \Doctrine\DBAL\Schema\Table("Foo"); - $table->createColumn("Bar", "integer"); + $table->addColumn("Bar", "integer"); $sql = $this->_platform->getCreateTableSql($table); $this->assertEquals('CREATE TABLE Foo (Bar INT NOT NULL) ENGINE = InnoDB', array_shift($sql)); diff --git a/tests/Doctrine/Tests/DBAL/Schema/ComparatorTest.php b/tests/Doctrine/Tests/DBAL/Schema/ComparatorTest.php index f4c274531..8349ce520 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/ComparatorTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/ComparatorTest.php @@ -404,13 +404,13 @@ class ComparatorTest extends \PHPUnit_Framework_TestCase public function testTableAddForeignKey() { $tableForeign = new Table("bar"); - $tableForeign->createColumn('id', 'integer'); + $tableForeign->addColumn('id', 'integer'); $table1 = new Table("foo"); - $table1->createColumn('fk', 'integer'); + $table1->addColumn('fk', 'integer'); $table2 = new Table("foo"); - $table2->createColumn('fk', 'integer'); + $table2->addColumn('fk', 'integer'); $table2->addForeignKeyConstraint($tableForeign, array('fk'), array('id')); $c = new Comparator(); @@ -423,13 +423,13 @@ class ComparatorTest extends \PHPUnit_Framework_TestCase public function testTableRemoveForeignKey() { $tableForeign = new Table("bar"); - $tableForeign->createColumn('id', 'integer'); + $tableForeign->addColumn('id', 'integer'); $table1 = new Table("foo"); - $table1->createColumn('fk', 'integer'); + $table1->addColumn('fk', 'integer'); $table2 = new Table("foo"); - $table2->createColumn('fk', 'integer'); + $table2->addColumn('fk', 'integer'); $table2->addForeignKeyConstraint($tableForeign, array('fk'), array('id')); $c = new Comparator(); @@ -442,14 +442,14 @@ class ComparatorTest extends \PHPUnit_Framework_TestCase public function testTableUpdateForeignKey() { $tableForeign = new Table("bar"); - $tableForeign->createColumn('id', 'integer'); + $tableForeign->addColumn('id', 'integer'); $table1 = new Table("foo"); - $table1->createColumn('fk', 'integer'); + $table1->addColumn('fk', 'integer'); $table1->addForeignKeyConstraint($tableForeign, array('fk'), array('id')); $table2 = new Table("foo"); - $table2->createColumn('fk', 'integer'); + $table2->addColumn('fk', 'integer'); $table2->addForeignKeyConstraint($tableForeign, array('fk'), array('id'), array('onUpdate' => 'CASCADE')); $c = new Comparator(); @@ -502,10 +502,10 @@ class ComparatorTest extends \PHPUnit_Framework_TestCase public function testCompareColumnCompareCaseInsensitive() { $tableA = new Table("foo"); - $tableA->createColumn('id', 'integer'); + $tableA->addColumn('id', 'integer'); $tableB = new Table("foo"); - $tableB->createColumn('ID', 'integer'); + $tableB->addColumn('ID', 'integer'); $c = new Comparator(); $tableDiff = $c->diffTable($tableA, $tableB); @@ -516,11 +516,11 @@ class ComparatorTest extends \PHPUnit_Framework_TestCase public function testCompareIndexBasedOnPropertiesNotName() { $tableA = new Table("foo"); - $tableA->createColumn('id', 'integer'); + $tableA->addColumn('id', 'integer'); $tableA->addIndex(array("id"), "foo_bar_idx"); $tableB = new Table("foo"); - $tableB->createColumn('ID', 'integer'); + $tableB->addColumn('ID', 'integer'); $tableB->addIndex(array("id"), "bar_foo_idx"); $c = new Comparator(); @@ -532,11 +532,11 @@ class ComparatorTest extends \PHPUnit_Framework_TestCase public function testCompareForeignKeyBasedOnPropertiesNotName() { $tableA = new Table("foo"); - $tableA->createColumn('id', 'integer'); + $tableA->addColumn('id', 'integer'); $tableA->addNamedForeignKeyConstraint('foo_constraint', 'bar', array('id'), array('id')); $tableB = new Table("foo"); - $tableB->createColumn('ID', 'integer'); + $tableB->addColumn('ID', 'integer'); $tableB->addNamedForeignKeyConstraint('bar_constraint', 'bar', array('id'), array('id')); $c = new Comparator(); @@ -548,10 +548,10 @@ class ComparatorTest extends \PHPUnit_Framework_TestCase public function testDetectRenameColumn() { $tableA = new Table("foo"); - $tableA->createColumn('foo', 'integer'); + $tableA->addColumn('foo', 'integer'); $tableB = new Table("foo"); - $tableB->createColumn('bar', 'integer'); + $tableB->addColumn('bar', 'integer'); $c = new Comparator(); $tableDiff = $c->diffTable($tableA, $tableB); diff --git a/tests/Doctrine/Tests/DBAL/Schema/SchemaTest.php b/tests/Doctrine/Tests/DBAL/Schema/SchemaTest.php index 46648ef0d..fdf7a90cb 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/SchemaTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/SchemaTest.php @@ -171,11 +171,11 @@ class SchemaTest extends \PHPUnit_Framework_TestCase { $schema = new Schema(); $tableA = $schema->createTable('foo'); - $tableA->createColumn('id', 'integer'); + $tableA->addColumn('id', 'integer'); $tableB = $schema->createTable('bar'); - $tableB->createColumn('id', 'integer'); - $tableB->createcolumn('foo_id', 'integer'); + $tableB->addColumn('id', 'integer'); + $tableB->addColumn('foo_id', 'integer'); $tableB->addForeignKeyConstraint($tableA, array('foo_id'), array('id')); $this->assertEquals(0, count($tableB->getIndexes())); @@ -207,7 +207,7 @@ class SchemaTest extends \PHPUnit_Framework_TestCase $schema = new Schema(array(), array(), array(), array(), $schemaConfig); $table = $schema->createTable("smalltable"); - $table->createColumn('long_id', 'integer'); + $table->addColumn('long_id', 'integer'); $table->addIndex(array('long_id')); $this->assertTrue($table->hasIndex('le_id_idx')); @@ -219,11 +219,11 @@ class SchemaTest extends \PHPUnit_Framework_TestCase $sequence = $schema->createSequence('baz'); $tableA = $schema->createTable('foo'); - $tableA->createColumn('id', 'integer'); + $tableA->addColumn('id', 'integer'); $tableB = $schema->createTable('bar'); - $tableB->createColumn('id', 'integer'); - $tableB->createcolumn('foo_id', 'integer'); + $tableB->addColumn('id', 'integer'); + $tableB->addColumn('foo_id', 'integer'); $tableB->addForeignKeyConstraint($tableA, array('foo_id'), array('id')); $schemaNew = clone $schema; diff --git a/tests/Doctrine/Tests/DBAL/Schema/TableTest.php b/tests/Doctrine/Tests/DBAL/Schema/TableTest.php index cb70499f0..0de4aca17 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/TableTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/TableTest.php @@ -47,7 +47,7 @@ class TableTest extends \PHPUnit_Framework_TestCase public function testColumnsCaseInsensitive() { $table = new Table("foo"); - $column = $table->createColumn('Foo', 'integer'); + $column = $table->addColumn('Foo', 'integer'); $this->assertTrue($table->hasColumn('Foo')); $this->assertTrue($table->hasColumn('foo')); @@ -65,7 +65,7 @@ class TableTest extends \PHPUnit_Framework_TestCase $table = new Table("foo"); $this->assertFalse($table->hasColumn("bar")); - $table->createColumn("bar", 'integer'); + $table->addColumn("bar", 'integer'); $this->assertTrue($table->hasColumn("bar")); $this->assertSame($type, $table->getColumn("bar")->getType()); } @@ -223,7 +223,7 @@ class TableTest extends \PHPUnit_Framework_TestCase { $table = new Table("foo"); - $table->createColumn("bar", 'integer'); + $table->addColumn("bar", 'integer'); $table->setPrimaryKey(array("bar")); $this->assertTrue($table->hasIndex("primary")); @@ -236,7 +236,7 @@ class TableTest extends \PHPUnit_Framework_TestCase { $table = new Table("foo"); - $table->createColumn("bar", 'integer'); + $table->addColumn("bar", 'integer'); $table->addUniqueIndex(array("bar"), "my_idx"); $this->assertTrue($table->hasIndex("my_idx")); @@ -248,7 +248,7 @@ class TableTest extends \PHPUnit_Framework_TestCase { $table = new Table("foo"); - $table->createColumn("bar", 'integer'); + $table->addColumn("bar", 'integer'); $table->addIndex(array("bar"), "my_idx"); $this->assertTrue($table->hasIndex("my_idx")); @@ -261,7 +261,7 @@ class TableTest extends \PHPUnit_Framework_TestCase $this->setExpectedException("Doctrine\DBAL\Schema\SchemaException"); $table = new Table("foo"); - $table->createColumn("bar",'integer'); + $table->addColumn("bar",'integer'); $table->addIndex(array("bar"), "invalid name %&/"); } @@ -297,10 +297,10 @@ class TableTest extends \PHPUnit_Framework_TestCase $this->setExpectedException("Doctrine\DBAL\Schema\SchemaException"); $table = new Table("foo"); - $table->createColumn("id", 'int'); + $table->addColumn("id", 'int'); $foreignTable = new Table("bar"); - $foreignTable->createColumn("id", 'int'); + $foreignTable->addColumn("id", 'int'); $table->addForeignKeyConstraint($foreignTable, array("foo"), array("id")); } @@ -310,10 +310,10 @@ class TableTest extends \PHPUnit_Framework_TestCase $this->setExpectedException("Doctrine\DBAL\Schema\SchemaException"); $table = new Table("foo"); - $table->createColumn("id", 'integer'); + $table->addColumn("id", 'integer'); $foreignTable = new Table("bar"); - $foreignTable->createColumn("id", 'integer'); + $foreignTable->addColumn("id", 'integer'); $table->addForeignKeyConstraint($foreignTable, array("id"), array("foo")); } @@ -321,10 +321,10 @@ class TableTest extends \PHPUnit_Framework_TestCase public function testAddForeignKeyConstraint() { $table = new Table("foo"); - $table->createColumn("id", 'integer'); + $table->addColumn("id", 'integer'); $foreignTable = new Table("bar"); - $foreignTable->createColumn("id", 'integer'); + $foreignTable->addColumn("id", 'integer'); $table->addForeignKeyConstraint($foreignTable, array("id"), array("id"), array("foo" => "bar")); @@ -340,7 +340,7 @@ class TableTest extends \PHPUnit_Framework_TestCase public function testAddIndexWithCaseSensitiveColumnProblem() { $table = new Table("foo"); - $table->createColumn("id", 'integer'); + $table->addColumn("id", 'integer'); $table->addIndex(array("ID"), "my_idx"); @@ -351,7 +351,7 @@ class TableTest extends \PHPUnit_Framework_TestCase public function testAddPrimaryKey_ColumnsAreExplicitlySetToNotNull() { $table = new Table("foo"); - $column = $table->createColumn("id", 'integer', array('notnull' => false)); + $column = $table->addColumn("id", 'integer', array('notnull' => false)); $this->assertFalse($column->getNotnull()); diff --git a/tests/Doctrine/Tests/DBAL/Schema/Visitor/SchemaSqlCollectorTest.php b/tests/Doctrine/Tests/DBAL/Schema/Visitor/SchemaSqlCollectorTest.php index 99f12aacd..f38a609d1 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/Visitor/SchemaSqlCollectorTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/Visitor/SchemaSqlCollectorTest.php @@ -63,15 +63,15 @@ class SchemaSqlCollectorTest extends \PHPUnit_Framework_TestCase { $schema = new Schema(); $tableA = $schema->createTable("foo"); - $tableA->createColumn("id", 'integer'); - $tableA->createColumn("bar", 'string', array('length' => 255)); + $tableA->addColumn("id", 'integer'); + $tableA->addColumn("bar", 'string', array('length' => 255)); $tableA->setPrimaryKey(array("id")); $tableA->setIdGeneratorType(Table::ID_SEQUENCE); $schema->createSequence("foo_seq"); $tableB = $schema->createTable("bar"); - $tableB->createColumn("id", 'integer'); + $tableB->addColumn("id", 'integer'); $tableB->setPrimaryKey(array("id")); $tableA->addForeignKeyConstraint($tableB, array("bar"), array("id")); diff --git a/tests/Doctrine/Tests/ORM/Functional/DatabaseDriverTest.php b/tests/Doctrine/Tests/ORM/Functional/DatabaseDriverTest.php index 3368d5abe..2ab29e37d 100644 --- a/tests/Doctrine/Tests/ORM/Functional/DatabaseDriverTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/DatabaseDriverTest.php @@ -27,9 +27,9 @@ class DatabaseDriverTest extends \Doctrine\Tests\OrmFunctionalTestCase } $table = new \Doctrine\DBAL\Schema\Table("dbdriver_foo"); - $table->createColumn('id', 'integer'); + $table->addColumn('id', 'integer'); $table->setPrimaryKey(array('id')); - $table->createColumn('bar', 'string', array('length' => 200)); + $table->addColumn('bar', 'string', array('length' => 200)); $this->_sm->dropAndCreateTable($table); @@ -56,15 +56,15 @@ class DatabaseDriverTest extends \Doctrine\Tests\OrmFunctionalTestCase } $tableB = new \Doctrine\DBAL\Schema\Table("dbdriver_bar"); - $tableB->createColumn('id', 'integer'); + $tableB->addColumn('id', 'integer'); $tableB->setPrimaryKey(array('id')); $this->_sm->dropAndCreateTable($tableB); $tableA = new \Doctrine\DBAL\Schema\Table("dbdriver_baz"); - $tableA->createColumn('id', 'integer'); + $tableA->addColumn('id', 'integer'); $tableA->setPrimaryKey(array('id')); - $tableA->createColumn('bar_id', 'integer'); + $tableA->addColumn('bar_id', 'integer'); $tableA->addForeignKeyConstraint('dbdriver_bar', array('bar_id'), array('id')); $this->_sm->dropAndCreateTable($tableA);