From 4736f5ee504e5fac06079e31df2e8548d8a8ab36 Mon Sep 17 00:00:00 2001 From: beberlei Date: Sat, 5 Dec 2009 23:06:29 +0000 Subject: [PATCH] [2.0] DDC-169 - Refactored Parts of the Platform Tests into an Abstract Test Case --- .../Platforms/AbstractPlatformTestCase.php | 23 +++++++++++++++++++ .../DBAL/Platforms/MsSqlPlatformTest.php | 17 +++----------- .../DBAL/Platforms/MySqlPlatformTest.php | 17 +++----------- .../DBAL/Platforms/OraclePlatformTest.php | 20 ++-------------- .../DBAL/Platforms/PostgreSqlPlatformTest.php | 18 ++------------- .../DBAL/Platforms/SqlitePlatformTest.php | 5 ++++ 6 files changed, 38 insertions(+), 62 deletions(-) diff --git a/tests/Doctrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php b/tests/Doctrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php index 43589aa7a..7e3e671cc 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php @@ -88,4 +88,27 @@ abstract class AbstractPlatformTestCase extends \Doctrine\Tests\DbalTestCase { return 'ALTER TABLE test ADD CONSTRAINT constraint_fk FOREIGN KEY (fk_name) REFERENCES foreign (id)'; } + + abstract public function getGenerateAlterTableSql(); + + public function testGeneratesTableAlterationSqlForAddingAndRenaming() + { + $expectedSql = $this->getGenerateAlterTableSql(); + + $changes = array( + 'name' => 'userlist', + 'add' => array( + 'quota' => array( + 'type' => \Doctrine\DBAL\Types\Type::getType('integer'), + 'notnull' => false, + ) + )); + + $sql = $this->_platform->getAlterTableSql('mytable', $changes); + + $this->assertEquals(count($sql), count($expectedSql), "Expecting the same number of sql queries for alter table failed."); + for ($i = 0; $i < count($expectedSql); $i++) { + $this->assertEquals($expectedSql[$i], $sql[$i], $i."th query of alter table does not match."); + } + } } diff --git a/tests/Doctrine/Tests/DBAL/Platforms/MsSqlPlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/MsSqlPlatformTest.php index 2e9a7c32a..3cf8f4afe 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/MsSqlPlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/MsSqlPlatformTest.php @@ -19,21 +19,10 @@ class MsSqlPlatformTest extends AbstractPlatformTestCase return 'CREATE TABLE test (id INT AUTO_INCREMENT NOT NULL, test VARCHAR(255) DEFAULT NULL, PRIMARY KEY(id))'; } - public function testGeneratesTableAlterationSql() + public function getGenerateAlterTableSql() { - $changes = array( - 'name' => 'userlist', - 'add' => array( - 'quota' => array( - 'type' => Type::getType('integer'), - 'unsigned' => 1 - ) - )); - - $sql = $this->_platform->getAlterTableSql('mytable', $changes); - $this->assertEquals( - 'ALTER TABLE mytable RENAME TO userlist, ADD quota INT UNSIGNED DEFAULT NULL', - $sql[0] + return array( + 'ALTER TABLE mytable RENAME TO userlist, ADD quota INT DEFAULT NULL', ); } diff --git a/tests/Doctrine/Tests/DBAL/Platforms/MySqlPlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/MySqlPlatformTest.php index 667192100..64cfa9b59 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/MySqlPlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/MySqlPlatformTest.php @@ -28,21 +28,10 @@ class MySqlPlatformTest extends AbstractPlatformTestCase return 'CREATE TABLE test (id INT AUTO_INCREMENT NOT NULL, test VARCHAR(255) DEFAULT NULL, PRIMARY KEY(id)) ENGINE = InnoDB'; } - public function testGeneratesTableAlterationSql() + public function getGenerateAlterTableSql() { - $changes = array( - 'name' => 'userlist', - 'add' => array( - 'quota' => array( - 'type' => Type::getType('integer'), - 'unsigned' => 1 - ) - )); - - $sql = $this->_platform->getAlterTableSql('mytable', $changes); - $this->assertEquals( - 'ALTER TABLE mytable RENAME TO userlist, ADD quota INT UNSIGNED DEFAULT NULL', - $sql[0] + return array( + 'ALTER TABLE mytable RENAME TO userlist, ADD quota INT DEFAULT NULL', ); } diff --git a/tests/Doctrine/Tests/DBAL/Platforms/OraclePlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/OraclePlatformTest.php index 3dc59090f..73008aef3 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/OraclePlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/OraclePlatformTest.php @@ -19,27 +19,11 @@ class OraclePlatformTest extends AbstractPlatformTestCase return 'CREATE TABLE test (id NUMBER(10) NOT NULL, test VARCHAR2(255) DEFAULT NULL, PRIMARY KEY(id))'; } - public function testGeneratesTableAlterationSql() + public function getGenerateAlterTableSql() { - $changes = array( - 'name' => 'userlist', - 'add' => array( - 'quota' => array( - 'type' => Type::getType('integer'), - 'unsigned' => 1 - ) - )); - - $sql = $this->_platform->getAlterTableSql('mytable', $changes); - - $this->assertEquals( + return array( 'ALTER TABLE mytable ADD (quota NUMBER(10) DEFAULT NULL)', - $sql[0] - ); - - $this->assertEquals( 'ALTER TABLE mytable RENAME TO userlist', - $sql[1] ); } diff --git a/tests/Doctrine/Tests/DBAL/Platforms/PostgreSqlPlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/PostgreSqlPlatformTest.php index 197a14ac3..f1aa28197 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/PostgreSqlPlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/PostgreSqlPlatformTest.php @@ -20,25 +20,11 @@ class PostgreSqlPlatformTest extends AbstractPlatformTestCase return 'CREATE TABLE test (id SERIAL NOT NULL, test VARCHAR(255) DEFAULT NULL, PRIMARY KEY(id))'; } - public function testGeneratesTableAlterationSqlForAddingAndRenaming() + public function getGenerateAlterTableSql() { - $changes = array( - 'name' => 'userlist', - 'add' => array( - 'quota' => array( - 'type' => Type::getType('integer') - ) - )); - - $sql = $this->_platform->getAlterTableSql('mytable', $changes); - - $this->assertEquals( + return array( 'ALTER TABLE mytable ADD quota INT DEFAULT NULL', - $sql[0] - ); - $this->assertEquals( 'ALTER TABLE mytable RENAME TO userlist', - $sql[1] ); } diff --git a/tests/Doctrine/Tests/DBAL/Platforms/SqlitePlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/SqlitePlatformTest.php index 3f9b3700a..04f52ea0d 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/SqlitePlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/SqlitePlatformTest.php @@ -101,4 +101,9 @@ class SqlitePlatformTest extends AbstractPlatformTestCase $sql = $this->_platform->modifyLimitQuery('SELECT * FROM user', 10); $this->assertEquals('SELECT * FROM user LIMIT 10', $sql); } + + public function getGenerateAlterTableSql() + { + $this->markTestSkipped('SQlite does not support ALTER Table.'); + } } \ No newline at end of file