From 3f229cfdb83fbc0b40c47ea72214a002d44d44bd Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Tue, 11 Oct 2022 18:35:45 -0700 Subject: [PATCH 1/4] Rename SQL Server platform unit test --- ...rPlatformTestCase.php => SQLServerPlatformTest.php} | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) rename tests/Platforms/{SQLServerPlatformTestCase.php => SQLServerPlatformTest.php} (99%) diff --git a/tests/Platforms/SQLServerPlatformTestCase.php b/tests/Platforms/SQLServerPlatformTest.php similarity index 99% rename from tests/Platforms/SQLServerPlatformTestCase.php rename to tests/Platforms/SQLServerPlatformTest.php index fcc73dffdd7..a3812dbef3c 100644 --- a/tests/Platforms/SQLServerPlatformTestCase.php +++ b/tests/Platforms/SQLServerPlatformTest.php @@ -18,7 +18,7 @@ use InvalidArgumentException; /** @extends AbstractPlatformTestCase */ -class SQLServerPlatformTestCase extends AbstractPlatformTestCase +class SQLServerPlatformTest extends AbstractPlatformTestCase { public function createPlatform(): AbstractPlatform { @@ -80,7 +80,7 @@ public function testGeneratesSqlSnippets(): void self::assertEquals('"', $this->platform->getIdentifierQuoteCharacter()); self::assertEquals( - '(column1 + column2 + column3)', + 'CONCAT(column1, column2, column3)', $this->platform->getConcatExpression('column1', 'column2', 'column3'), ); } @@ -659,6 +659,7 @@ protected function getQuotedColumnInForeignKeySQL(): array return [ 'CREATE TABLE [quoted] ([create] NVARCHAR(255) NOT NULL, ' . 'foo NVARCHAR(255) NOT NULL, [bar] NVARCHAR(255) NOT NULL)', + 'CREATE INDEX IDX_22660D028FD6E0FB8C736521D79164E3 ON [quoted] ([create], foo, [bar])', 'ALTER TABLE [quoted] ADD CONSTRAINT FK_WITH_RESERVED_KEYWORD' . ' FOREIGN KEY ([create], foo, [bar]) REFERENCES [foreign] ([create], bar, [foo-bar])', 'ALTER TABLE [quoted] ADD CONSTRAINT FK_WITH_NON_RESERVED_KEYWORD' @@ -1607,6 +1608,11 @@ protected function getGeneratesAlterTableRenameIndexUsedByForeignKeySQL(): array return ["EXEC sp_rename N'mytable.idx_foo', N'idx_foo_renamed', N'INDEX'"]; } + protected function getLimitOffsetCastToIntExpectedQuery(): string + { + return 'SELECT * FROM user ORDER BY (SELECT 0) OFFSET 2 ROWS FETCH NEXT 1 ROWS ONLY'; + } + public function testModifyLimitQueryWithTopNSubQueryWithOrderBy(): void { $query = 'SELECT * FROM test t WHERE t.id = (SELECT TOP 1 t2.id FROM test t2 ORDER BY t2.data DESC)'; From 95ecdbc8830f696ebcbee5bf40fed92edf761a40 Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Wed, 12 Oct 2022 12:46:21 +0200 Subject: [PATCH 2/4] Use the % operator instead of MOD() in SQLite --- src/Platforms/SqlitePlatform.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Platforms/SqlitePlatform.php b/src/Platforms/SqlitePlatform.php index a0fac3cef2b..71c29f38aeb 100644 --- a/src/Platforms/SqlitePlatform.php +++ b/src/Platforms/SqlitePlatform.php @@ -81,6 +81,14 @@ public function getNowExpression($type = 'timestamp') } } + /** + * {@inheritDoc} + */ + public function getModExpression($expression1, $expression2) + { + return $expression1 . ' % ' . $expression2; + } + /** * {@inheritDoc} */ From 876b8324e8a8f248a85e98e3261b552f7cdd7f54 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Wed, 12 Oct 2022 06:53:51 -0700 Subject: [PATCH 3/4] Remove unit tests that make assertions against complex SQL --- .../AbstractMySQLPlatformTestCase.php | 27 ------- tests/Platforms/AbstractPlatformTestCase.php | 80 ------------------- tests/Platforms/DB2PlatformTest.php | 40 ---------- tests/Platforms/OraclePlatformTest.php | 32 -------- tests/Platforms/PostgreSQLPlatformTest.php | 38 --------- tests/Platforms/SQLServerPlatformTestCase.php | 46 ----------- tests/Platforms/SqlitePlatformTest.php | 38 --------- 7 files changed, 301 deletions(-) diff --git a/tests/Platforms/AbstractMySQLPlatformTestCase.php b/tests/Platforms/AbstractMySQLPlatformTestCase.php index c2d0185bbc5..b84de6f6e99 100644 --- a/tests/Platforms/AbstractMySQLPlatformTestCase.php +++ b/tests/Platforms/AbstractMySQLPlatformTestCase.php @@ -52,18 +52,6 @@ public function getGenerateTableWithMultiColumnUniqueIndexSql(): array ]; } - /** - * {@inheritDoc} - */ - public function getGenerateAlterTableSql(): array - { - return [ - 'ALTER TABLE mytable RENAME TO userlist, ADD quota INT DEFAULT NULL, DROP foo, ' - . "CHANGE bar baz VARCHAR(255) DEFAULT 'def' NOT NULL, " - . 'CHANGE bloo bloo TINYINT(1) DEFAULT 0 NOT NULL', - ]; - } - public function testGeneratesSqlSnippets(): void { self::assertEquals('RLIKE', $this->platform->getRegexpExpression()); @@ -801,21 +789,6 @@ public function getAlterTableRenameColumnSQL(): array return ["ALTER TABLE foo CHANGE bar baz INT DEFAULT 666 NOT NULL COMMENT 'rename test'"]; } - /** - * {@inheritdoc} - */ - protected function getQuotesTableIdentifiersInAlterTableSQL(): array - { - return [ - 'ALTER TABLE `foo` DROP FOREIGN KEY fk1', - 'ALTER TABLE `foo` DROP FOREIGN KEY fk2', - 'ALTER TABLE `foo` RENAME TO `table`, ADD bloo INT NOT NULL, DROP baz, CHANGE bar bar INT DEFAULT NULL, ' . - 'CHANGE id war INT NOT NULL', - 'ALTER TABLE `table` ADD CONSTRAINT fk_add FOREIGN KEY (fk3) REFERENCES fk_table (id)', - 'ALTER TABLE `table` ADD CONSTRAINT fk2 FOREIGN KEY (fk2) REFERENCES fk_table2 (id)', - ]; - } - /** * {@inheritdoc} */ diff --git a/tests/Platforms/AbstractPlatformTestCase.php b/tests/Platforms/AbstractPlatformTestCase.php index d1b5b6c08d9..6741c818ab8 100644 --- a/tests/Platforms/AbstractPlatformTestCase.php +++ b/tests/Platforms/AbstractPlatformTestCase.php @@ -300,49 +300,6 @@ public function getGenerateConstraintForeignKeySql(ForeignKeyConstraint $fk): st ); } - /** @return string[] */ - abstract public function getGenerateAlterTableSql(): array; - - public function testGeneratesTableAlterationSql(): void - { - $expectedSql = $this->getGenerateAlterTableSql(); - - $table = new Table('mytable'); - $table->addColumn('id', 'integer', ['autoincrement' => true]); - $table->addColumn('foo', 'integer'); - $table->addColumn('bar', 'string'); - $table->addColumn('bloo', 'boolean'); - $table->setPrimaryKey(['id']); - - $tableDiff = new TableDiff('mytable'); - $tableDiff->fromTable = $table; - $tableDiff->newName = 'userlist'; - $tableDiff->addedColumns['quota'] = new Column('quota', Type::getType('integer'), ['notnull' => false]); - $tableDiff->removedColumns['foo'] = new Column('foo', Type::getType('integer')); - $tableDiff->changedColumns['bar'] = new ColumnDiff( - 'bar', - new Column( - 'baz', - Type::getType('string'), - ['default' => 'def'], - ), - ['type', 'notnull', 'default'], - ); - $tableDiff->changedColumns['bloo'] = new ColumnDiff( - 'bloo', - new Column( - 'bloo', - Type::getType('boolean'), - ['default' => false], - ), - ['type', 'notnull', 'default'], - ); - - $sql = $this->platform->getAlterTableSQL($tableDiff); - - self::assertEquals($expectedSql, $sql); - } - public function testGetCustomColumnDeclarationSql(): void { self::assertEquals( @@ -1247,43 +1204,6 @@ public function testGeneratesAlterTableRenameColumnSQL(): void /** @return string[] */ abstract public function getAlterTableRenameColumnSQL(): array; - public function testQuotesTableIdentifiersInAlterTableSQL(): void - { - $table = new Table('"foo"'); - $table->addColumn('id', 'integer'); - $table->addColumn('fk', 'integer'); - $table->addColumn('fk2', 'integer'); - $table->addColumn('fk3', 'integer'); - $table->addColumn('bar', 'integer'); - $table->addColumn('baz', 'integer'); - $table->addForeignKeyConstraint('fk_table', ['fk'], ['id'], [], 'fk1'); - $table->addForeignKeyConstraint('fk_table', ['fk2'], ['id'], [], 'fk2'); - - $tableDiff = new TableDiff('"foo"'); - $tableDiff->fromTable = $table; - $tableDiff->newName = 'table'; - $tableDiff->addedColumns['bloo'] = new Column('bloo', Type::getType('integer')); - $tableDiff->changedColumns['bar'] = new ColumnDiff( - 'bar', - new Column('bar', Type::getType('integer'), ['notnull' => false]), - ['notnull'], - $table->getColumn('bar'), - ); - $tableDiff->renamedColumns['id'] = new Column('war', Type::getType('integer')); - $tableDiff->removedColumns['baz'] = new Column('baz', Type::getType('integer')); - $tableDiff->addedForeignKeys[] = new ForeignKeyConstraint(['fk3'], 'fk_table', ['id'], 'fk_add'); - $tableDiff->changedForeignKeys[] = new ForeignKeyConstraint(['fk2'], 'fk_table2', ['id'], 'fk2'); - $tableDiff->removedForeignKeys[] = new ForeignKeyConstraint(['fk'], 'fk_table', ['id'], 'fk1'); - - self::assertSame( - $this->getQuotesTableIdentifiersInAlterTableSQL(), - $this->platform->getAlterTableSQL($tableDiff), - ); - } - - /** @return string[] */ - abstract protected function getQuotesTableIdentifiersInAlterTableSQL(): array; - public function testAlterStringToFixedString(): void { $table = new Table('mytable'); diff --git a/tests/Platforms/DB2PlatformTest.php b/tests/Platforms/DB2PlatformTest.php index 436d87b0402..2e4611e4097 100644 --- a/tests/Platforms/DB2PlatformTest.php +++ b/tests/Platforms/DB2PlatformTest.php @@ -20,26 +20,6 @@ public function createPlatform(): AbstractPlatform return new DB2Platform(); } - /** - * {@inheritDoc} - */ - public function getGenerateAlterTableSql(): array - { - return [ - 'ALTER TABLE mytable ALTER COLUMN baz SET DATA TYPE VARCHAR(255)', - 'ALTER TABLE mytable ALTER COLUMN baz SET NOT NULL', - "ALTER TABLE mytable ALTER COLUMN baz SET DEFAULT 'def'", - 'ALTER TABLE mytable ALTER COLUMN bloo SET DATA TYPE SMALLINT', - 'ALTER TABLE mytable ALTER COLUMN bloo SET NOT NULL', - 'ALTER TABLE mytable ALTER COLUMN bloo SET DEFAULT 0', - 'ALTER TABLE mytable ' . - 'ADD COLUMN quota INTEGER DEFAULT NULL ' . - 'DROP COLUMN foo', - "CALL SYSPROC.ADMIN_CMD ('REORG TABLE mytable')", - 'RENAME TABLE mytable TO userlist', - ]; - } - protected function getGenerateForeignKeySql(): string { return 'ALTER TABLE test ADD FOREIGN KEY (fk_name_id) REFERENCES other_table (id)'; @@ -545,26 +525,6 @@ public function getAlterTableRenameColumnSQL(): array return ['ALTER TABLE foo RENAME COLUMN bar TO baz']; } - /** - * {@inheritdoc} - */ - protected function getQuotesTableIdentifiersInAlterTableSQL(): array - { - return [ - 'ALTER TABLE "foo" DROP FOREIGN KEY fk1', - 'ALTER TABLE "foo" DROP FOREIGN KEY fk2', - 'ALTER TABLE "foo" ' . - 'ADD COLUMN bloo INTEGER NOT NULL WITH DEFAULT ' . - 'DROP COLUMN baz ' . - 'ALTER COLUMN bar DROP NOT NULL ' . - 'RENAME COLUMN id TO war', - 'CALL SYSPROC.ADMIN_CMD (\'REORG TABLE "foo"\')', - 'RENAME TABLE "foo" TO "table"', - 'ALTER TABLE "table" ADD CONSTRAINT fk_add FOREIGN KEY (fk3) REFERENCES fk_table (id)', - 'ALTER TABLE "table" ADD CONSTRAINT fk2 FOREIGN KEY (fk2) REFERENCES fk_table2 (id)', - ]; - } - /** * {@inheritdoc} */ diff --git a/tests/Platforms/OraclePlatformTest.php b/tests/Platforms/OraclePlatformTest.php index 5d4759410c6..de2f04f29a8 100644 --- a/tests/Platforms/OraclePlatformTest.php +++ b/tests/Platforms/OraclePlatformTest.php @@ -89,20 +89,6 @@ public function getGenerateTableWithMultiColumnUniqueIndexSql(): array ]; } - /** - * {@inheritDoc} - */ - public function getGenerateAlterTableSql(): array - { - return [ - 'ALTER TABLE mytable ADD (quota NUMBER(10) DEFAULT NULL NULL)', - "ALTER TABLE mytable MODIFY (baz VARCHAR2(255) DEFAULT 'def' NOT NULL, " - . 'bloo NUMBER(1) DEFAULT 0 NOT NULL)', - 'ALTER TABLE mytable DROP (foo)', - 'ALTER TABLE mytable RENAME TO userlist', - ]; - } - public function testRLike(): void { $this->expectException(Exception::class); @@ -720,24 +706,6 @@ public static function getReturnsDropAutoincrementSQL(): iterable ]; } - /** - * {@inheritdoc} - */ - protected function getQuotesTableIdentifiersInAlterTableSQL(): array - { - return [ - 'ALTER TABLE "foo" DROP CONSTRAINT fk1', - 'ALTER TABLE "foo" DROP CONSTRAINT fk2', - 'ALTER TABLE "foo" ADD (bloo NUMBER(10) NOT NULL)', - 'ALTER TABLE "foo" MODIFY (bar NUMBER(10) DEFAULT NULL NULL)', - 'ALTER TABLE "foo" RENAME COLUMN id TO war', - 'ALTER TABLE "foo" DROP (baz)', - 'ALTER TABLE "foo" RENAME TO "table"', - 'ALTER TABLE "table" ADD CONSTRAINT fk_add FOREIGN KEY (fk3) REFERENCES fk_table (id)', - 'ALTER TABLE "table" ADD CONSTRAINT fk2 FOREIGN KEY (fk2) REFERENCES fk_table2 (id)', - ]; - } - /** * {@inheritdoc} */ diff --git a/tests/Platforms/PostgreSQLPlatformTest.php b/tests/Platforms/PostgreSQLPlatformTest.php index d0e76969d86..4810eb951ef 100644 --- a/tests/Platforms/PostgreSQLPlatformTest.php +++ b/tests/Platforms/PostgreSQLPlatformTest.php @@ -42,24 +42,6 @@ public function getGenerateTableWithMultiColumnUniqueIndexSql(): array ]; } - /** - * {@inheritDoc} - */ - public function getGenerateAlterTableSql(): array - { - return [ - 'ALTER TABLE mytable ADD quota INT DEFAULT NULL', - 'ALTER TABLE mytable DROP foo', - 'ALTER TABLE mytable ALTER bar TYPE VARCHAR(255)', - "ALTER TABLE mytable ALTER bar SET DEFAULT 'def'", - 'ALTER TABLE mytable ALTER bar SET NOT NULL', - 'ALTER TABLE mytable ALTER bloo TYPE BOOLEAN', - 'ALTER TABLE mytable ALTER bloo SET DEFAULT false', - 'ALTER TABLE mytable ALTER bloo SET NOT NULL', - 'ALTER TABLE mytable RENAME TO userlist', - ]; - } - public function getGenerateIndexSql(): string { return 'CREATE INDEX my_idx ON mytable (user_name, last_login)'; @@ -817,26 +799,6 @@ public function getAlterTableRenameColumnSQL(): array return ['ALTER TABLE foo RENAME COLUMN bar TO baz']; } - /** - * {@inheritdoc} - */ - protected function getQuotesTableIdentifiersInAlterTableSQL(): array - { - return [ - 'ALTER TABLE "foo" DROP CONSTRAINT fk1', - 'ALTER TABLE "foo" DROP CONSTRAINT fk2', - 'ALTER TABLE "foo" ADD bloo INT NOT NULL', - 'ALTER TABLE "foo" DROP baz', - 'ALTER TABLE "foo" ALTER bar DROP NOT NULL', - 'ALTER TABLE "foo" RENAME COLUMN id TO war', - 'ALTER TABLE "foo" RENAME TO "table"', - 'ALTER TABLE "table" ADD CONSTRAINT fk_add FOREIGN KEY (fk3) REFERENCES fk_table (id) NOT DEFERRABLE ' . - 'INITIALLY IMMEDIATE', - 'ALTER TABLE "table" ADD CONSTRAINT fk2 FOREIGN KEY (fk2) REFERENCES fk_table2 (id) NOT DEFERRABLE ' . - 'INITIALLY IMMEDIATE', - ]; - } - /** * {@inheritdoc} */ diff --git a/tests/Platforms/SQLServerPlatformTestCase.php b/tests/Platforms/SQLServerPlatformTestCase.php index fcc73dffdd7..7af33a7d0cd 100644 --- a/tests/Platforms/SQLServerPlatformTestCase.php +++ b/tests/Platforms/SQLServerPlatformTestCase.php @@ -42,29 +42,6 @@ public function getGenerateTableWithMultiColumnUniqueIndexSql(): array ]; } - /** - * {@inheritDoc} - */ - public function getGenerateAlterTableSql(): array - { - return [ - 'ALTER TABLE mytable ADD quota INT', - 'ALTER TABLE mytable DROP COLUMN foo', - 'ALTER TABLE mytable ALTER COLUMN baz NVARCHAR(255) NOT NULL', - "ALTER TABLE mytable ADD CONSTRAINT DF_6B2BD609_78240498 DEFAULT 'def' FOR baz", - 'ALTER TABLE mytable ALTER COLUMN bloo BIT NOT NULL', - 'ALTER TABLE mytable ADD CONSTRAINT DF_6B2BD609_CECED971 DEFAULT 0 FOR bloo', - "sp_rename 'mytable', 'userlist'", - "DECLARE @sql NVARCHAR(MAX) = N''; " . - "SELECT @sql += N'EXEC sp_rename N''' + dc.name + ''', N''' " . - "+ REPLACE(dc.name, '6B2BD609', 'E2B58069') + ''', ''OBJECT'';' " . - 'FROM sys.default_constraints dc ' . - 'JOIN sys.tables tbl ON dc.parent_object_id = tbl.object_id ' . - "WHERE tbl.name = 'userlist';" . - 'EXEC sp_executesql @sql', - ]; - } - public function testDoesNotSupportRegexp(): void { $this->expectException(Exception::class); @@ -1526,29 +1503,6 @@ public function getAlterTableRenameColumnSQL(): array ]; } - /** - * {@inheritdoc} - */ - protected function getQuotesTableIdentifiersInAlterTableSQL(): array - { - return [ - 'ALTER TABLE [foo] DROP CONSTRAINT fk1', - 'ALTER TABLE [foo] DROP CONSTRAINT fk2', - "sp_rename '[foo].id', 'war', 'COLUMN'", - 'ALTER TABLE [foo] ADD bloo INT NOT NULL', - 'ALTER TABLE [foo] DROP COLUMN baz', - 'ALTER TABLE [foo] ALTER COLUMN bar INT', - "sp_rename '[foo]', 'table'", - "DECLARE @sql NVARCHAR(MAX) = N''; " . - "SELECT @sql += N'EXEC sp_rename N''' + dc.name + ''', " . - "N''' + REPLACE(dc.name, '8C736521', 'F6298F46') + ''', ''OBJECT'';' " . - 'FROM sys.default_constraints dc JOIN sys.tables tbl ON dc.parent_object_id = tbl.object_id ' . - "WHERE tbl.name = 'table';EXEC sp_executesql @sql", - 'ALTER TABLE [table] ADD CONSTRAINT fk_add FOREIGN KEY (fk3) REFERENCES fk_table (id)', - 'ALTER TABLE [table] ADD CONSTRAINT fk2 FOREIGN KEY (fk2) REFERENCES fk_table2 (id)', - ]; - } - /** * {@inheritdoc} */ diff --git a/tests/Platforms/SqlitePlatformTest.php b/tests/Platforms/SqlitePlatformTest.php index 2afa523a16d..c713cdc51c3 100644 --- a/tests/Platforms/SqlitePlatformTest.php +++ b/tests/Platforms/SqlitePlatformTest.php @@ -286,24 +286,6 @@ public function testModifyLimitQueryWithOffsetAndEmptyLimit(): void self::assertEquals('SELECT * FROM user LIMIT -1 OFFSET 10', $sql); } - /** - * {@inheritDoc} - */ - public function getGenerateAlterTableSql(): array - { - return [ - 'CREATE TEMPORARY TABLE __temp__mytable AS SELECT id, bar, bloo FROM mytable', - 'DROP TABLE mytable', - 'CREATE TABLE mytable (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, ' - . "baz VARCHAR(255) DEFAULT 'def' NOT NULL, " - . 'bloo BOOLEAN DEFAULT 0 NOT NULL, ' - . 'quota INTEGER DEFAULT NULL)', - 'INSERT INTO mytable (id, baz, bloo) SELECT id, bar, bloo FROM __temp__mytable', - 'DROP TABLE __temp__mytable', - 'ALTER TABLE mytable RENAME TO userlist', - ]; - } - public function testGenerateTableSqlShouldNotAutoQuotePrimaryKey(): void { $table = new Table('test'); @@ -628,26 +610,6 @@ public function getAlterTableRenameColumnSQL(): array ]; } - /** - * {@inheritdoc} - */ - protected function getQuotesTableIdentifiersInAlterTableSQL(): array - { - return [ - 'CREATE TEMPORARY TABLE __temp__foo AS SELECT fk, fk2, id, fk3, bar FROM "foo"', - 'DROP TABLE "foo"', - 'CREATE TABLE "foo" (fk2 INTEGER NOT NULL, fk3 INTEGER NOT NULL, fk INTEGER NOT NULL, ' . - 'war INTEGER NOT NULL, bar INTEGER DEFAULT NULL, bloo INTEGER NOT NULL, ' . - 'CONSTRAINT fk2 FOREIGN KEY (fk2) REFERENCES fk_table2 (id) NOT DEFERRABLE INITIALLY IMMEDIATE, ' . - 'CONSTRAINT fk_add FOREIGN KEY (fk3) REFERENCES fk_table (id) NOT DEFERRABLE INITIALLY IMMEDIATE)', - 'INSERT INTO "foo" (fk, fk2, war, fk3, bar) SELECT fk, fk2, id, fk3, bar FROM __temp__foo', - 'DROP TABLE __temp__foo', - 'ALTER TABLE "foo" RENAME TO "table"', - 'CREATE INDEX IDX_8C736521A81E660E ON "table" (fk)', - 'CREATE INDEX IDX_8C736521FDC58D6C ON "table" (fk2)', - ]; - } - /** * {@inheritdoc} */ From 0a0cd8a1e4620bbf93f5dd68af4ea0c9e1687387 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Wed, 12 Oct 2022 13:15:09 -0700 Subject: [PATCH 4/4] Remove unit tests that make assertions against complex SQL --- .../AbstractMySQLPlatformTestCase.php | 41 -- tests/Platforms/AbstractPlatformTestCase.php | 124 ---- tests/Platforms/DB2PlatformTest.php | 34 -- tests/Platforms/OraclePlatformTest.php | 34 -- tests/Platforms/PostgreSQLPlatformTest.php | 41 -- tests/Platforms/SQLServerPlatformTest.php | 533 ------------------ tests/Platforms/SQLitePlatformTest.php | 63 --- 7 files changed, 870 deletions(-) diff --git a/tests/Platforms/AbstractMySQLPlatformTestCase.php b/tests/Platforms/AbstractMySQLPlatformTestCase.php index 16f3489fa1b..7d05698eb90 100644 --- a/tests/Platforms/AbstractMySQLPlatformTestCase.php +++ b/tests/Platforms/AbstractMySQLPlatformTestCase.php @@ -546,52 +546,11 @@ public function testIgnoresDifferenceInDefaultValuesForUnsupportedColumnTypes(): self::assertNull($this->createComparator()->diffTable($table, $diffTable)); } - /** - * {@inheritdoc} - */ - protected function getQuotedAlterTableRenameColumnSQL(): array - { - return ['ALTER TABLE mytable ' . - "CHANGE unquoted1 unquoted INT NOT NULL COMMENT 'Unquoted 1', " . - "CHANGE unquoted2 `where` INT NOT NULL COMMENT 'Unquoted 2', " . - "CHANGE unquoted3 `foo` INT NOT NULL COMMENT 'Unquoted 3', " . - "CHANGE `create` reserved_keyword INT NOT NULL COMMENT 'Reserved keyword 1', " . - "CHANGE `table` `from` INT NOT NULL COMMENT 'Reserved keyword 2', " . - "CHANGE `select` `bar` INT NOT NULL COMMENT 'Reserved keyword 3', " . - "CHANGE quoted1 quoted INT NOT NULL COMMENT 'Quoted 1', " . - "CHANGE quoted2 `and` INT NOT NULL COMMENT 'Quoted 2', " . - "CHANGE quoted3 `baz` INT NOT NULL COMMENT 'Quoted 3'", - ]; - } - - /** - * {@inheritdoc} - */ - protected function getQuotedAlterTableChangeColumnLengthSQL(): array - { - return ['ALTER TABLE mytable ' . - "CHANGE unquoted1 unquoted1 VARCHAR(255) NOT NULL COMMENT 'Unquoted 1', " . - "CHANGE unquoted2 unquoted2 VARCHAR(255) NOT NULL COMMENT 'Unquoted 2', " . - "CHANGE unquoted3 unquoted3 VARCHAR(255) NOT NULL COMMENT 'Unquoted 3', " . - "CHANGE `create` `create` VARCHAR(255) NOT NULL COMMENT 'Reserved keyword 1', " . - "CHANGE `table` `table` VARCHAR(255) NOT NULL COMMENT 'Reserved keyword 2', " . - "CHANGE `select` `select` VARCHAR(255) NOT NULL COMMENT 'Reserved keyword 3'", - ]; - } - public function testReturnsGuidTypeDeclarationSQL(): void { self::assertSame('CHAR(36)', $this->platform->getGuidTypeDeclarationSQL([])); } - /** - * {@inheritdoc} - */ - public function getAlterTableRenameColumnSQL(): array - { - return ["ALTER TABLE foo CHANGE bar baz INT DEFAULT 666 NOT NULL COMMENT 'rename test'"]; - } - /** * {@inheritdoc} */ diff --git a/tests/Platforms/AbstractPlatformTestCase.php b/tests/Platforms/AbstractPlatformTestCase.php index 03a3d454d32..eb964c5af63 100644 --- a/tests/Platforms/AbstractPlatformTestCase.php +++ b/tests/Platforms/AbstractPlatformTestCase.php @@ -769,107 +769,6 @@ protected function getQuotedAlterTableRenameIndexSQL(): array ]; } - public function testQuotesAlterTableRenameColumn(): void - { - $fromTable = new Table('mytable'); - - $fromTable->addColumn('unquoted1', 'integer', ['comment' => 'Unquoted 1']); - $fromTable->addColumn('unquoted2', 'integer', ['comment' => 'Unquoted 2']); - $fromTable->addColumn('unquoted3', 'integer', ['comment' => 'Unquoted 3']); - - $fromTable->addColumn('create', 'integer', ['comment' => 'Reserved keyword 1']); - $fromTable->addColumn('table', 'integer', ['comment' => 'Reserved keyword 2']); - $fromTable->addColumn('select', 'integer', ['comment' => 'Reserved keyword 3']); - - $fromTable->addColumn('`quoted1`', 'integer', ['comment' => 'Quoted 1']); - $fromTable->addColumn('`quoted2`', 'integer', ['comment' => 'Quoted 2']); - $fromTable->addColumn('`quoted3`', 'integer', ['comment' => 'Quoted 3']); - - $toTable = new Table('mytable'); - - // unquoted -> unquoted - $toTable->addColumn('unquoted', 'integer', ['comment' => 'Unquoted 1']); - - // unquoted -> reserved keyword - $toTable->addColumn('where', 'integer', ['comment' => 'Unquoted 2']); - - // unquoted -> quoted - $toTable->addColumn('`foo`', 'integer', ['comment' => 'Unquoted 3']); - - // reserved keyword -> unquoted - $toTable->addColumn('reserved_keyword', 'integer', ['comment' => 'Reserved keyword 1']); - - // reserved keyword -> reserved keyword - $toTable->addColumn('from', 'integer', ['comment' => 'Reserved keyword 2']); - - // reserved keyword -> quoted - $toTable->addColumn('`bar`', 'integer', ['comment' => 'Reserved keyword 3']); - - // quoted -> unquoted - $toTable->addColumn('quoted', 'integer', ['comment' => 'Quoted 1']); - - // quoted -> reserved keyword - $toTable->addColumn('and', 'integer', ['comment' => 'Quoted 2']); - - // quoted -> quoted - $toTable->addColumn('`baz`', 'integer', ['comment' => 'Quoted 3']); - - $diff = $this->createComparator() - ->diffTable($fromTable, $toTable); - self::assertNotNull($diff); - - self::assertEquals( - $this->getQuotedAlterTableRenameColumnSQL(), - $this->platform->getAlterTableSQL($diff), - ); - } - - /** - * Returns SQL statements for {@link testQuotesAlterTableRenameColumn}. - * - * @return string[] - */ - abstract protected function getQuotedAlterTableRenameColumnSQL(): array; - - public function testQuotesAlterTableChangeColumnLength(): void - { - $fromTable = new Table('mytable'); - - $fromTable->addColumn('unquoted1', 'string', ['comment' => 'Unquoted 1', 'length' => 10]); - $fromTable->addColumn('unquoted2', 'string', ['comment' => 'Unquoted 2', 'length' => 10]); - $fromTable->addColumn('unquoted3', 'string', ['comment' => 'Unquoted 3', 'length' => 10]); - - $fromTable->addColumn('create', 'string', ['comment' => 'Reserved keyword 1', 'length' => 10]); - $fromTable->addColumn('table', 'string', ['comment' => 'Reserved keyword 2', 'length' => 10]); - $fromTable->addColumn('select', 'string', ['comment' => 'Reserved keyword 3', 'length' => 10]); - - $toTable = new Table('mytable'); - - $toTable->addColumn('unquoted1', 'string', ['comment' => 'Unquoted 1', 'length' => 255]); - $toTable->addColumn('unquoted2', 'string', ['comment' => 'Unquoted 2', 'length' => 255]); - $toTable->addColumn('unquoted3', 'string', ['comment' => 'Unquoted 3', 'length' => 255]); - - $toTable->addColumn('create', 'string', ['comment' => 'Reserved keyword 1', 'length' => 255]); - $toTable->addColumn('table', 'string', ['comment' => 'Reserved keyword 2', 'length' => 255]); - $toTable->addColumn('select', 'string', ['comment' => 'Reserved keyword 3', 'length' => 255]); - - $diff = $this->createComparator() - ->diffTable($fromTable, $toTable); - self::assertNotNull($diff); - - self::assertEquals( - $this->getQuotedAlterTableChangeColumnLengthSQL(), - $this->platform->getAlterTableSQL($diff), - ); - } - - /** - * Returns SQL statements for {@link testQuotesAlterTableChangeColumnLength}. - * - * @return string[] - */ - abstract protected function getQuotedAlterTableChangeColumnLengthSQL(): array; - public function testAlterTableRenameIndexInSchema(): void { $table = new Table('myschema.mytable'); @@ -1043,29 +942,6 @@ public function testReturnsGuidTypeDeclarationSQL(): void $this->platform->getGuidTypeDeclarationSQL([]); } - public function testGeneratesAlterTableRenameColumnSQL(): void - { - $table = new Table('foo'); - $table->addColumn( - 'bar', - 'integer', - ['notnull' => true, 'default' => 666, 'comment' => 'rename test'], - ); - - $tableDiff = new TableDiff($table, [], [], [], [ - 'bar' => new Column('baz', Type::getType('integer'), [ - 'notnull' => true, - 'default' => 666, - 'comment' => 'rename test', - ]), - ], [], [], [], [], [], [], []); - - self::assertSame($this->getAlterTableRenameColumnSQL(), $this->platform->getAlterTableSQL($tableDiff)); - } - - /** @return string[] */ - abstract public function getAlterTableRenameColumnSQL(): array; - public function testAlterStringToFixedString(): void { $table = new Table('mytable'); diff --git a/tests/Platforms/DB2PlatformTest.php b/tests/Platforms/DB2PlatformTest.php index 3d79e3e77aa..810622b341a 100644 --- a/tests/Platforms/DB2PlatformTest.php +++ b/tests/Platforms/DB2PlatformTest.php @@ -405,32 +405,6 @@ protected function getQuotedAlterTableRenameIndexSQL(): array ]; } - /** - * {@inheritdoc} - */ - protected function getQuotedAlterTableRenameColumnSQL(): array - { - return ['ALTER TABLE mytable ' . - 'RENAME COLUMN unquoted1 TO unquoted ' . - 'RENAME COLUMN unquoted2 TO "where" ' . - 'RENAME COLUMN unquoted3 TO "foo" ' . - 'RENAME COLUMN "create" TO reserved_keyword ' . - 'RENAME COLUMN "table" TO "from" ' . - 'RENAME COLUMN "select" TO "bar" ' . - 'RENAME COLUMN quoted1 TO quoted ' . - 'RENAME COLUMN quoted2 TO "and" ' . - 'RENAME COLUMN quoted3 TO "baz"', - ]; - } - - /** - * {@inheritdoc} - */ - protected function getQuotedAlterTableChangeColumnLengthSQL(): array - { - self::markTestIncomplete('Not implemented yet'); - } - /** * {@inheritDoc} */ @@ -455,14 +429,6 @@ public function testReturnsGuidTypeDeclarationSQL(): void self::assertSame('CHAR(36)', $this->platform->getGuidTypeDeclarationSQL([])); } - /** - * {@inheritdoc} - */ - public function getAlterTableRenameColumnSQL(): array - { - return ['ALTER TABLE foo RENAME COLUMN bar TO baz']; - } - /** * {@inheritdoc} */ diff --git a/tests/Platforms/OraclePlatformTest.php b/tests/Platforms/OraclePlatformTest.php index 80811db3f32..fb13c380564 100644 --- a/tests/Platforms/OraclePlatformTest.php +++ b/tests/Platforms/OraclePlatformTest.php @@ -417,32 +417,6 @@ protected function getQuotedAlterTableRenameIndexSQL(): array ]; } - /** - * {@inheritdoc} - */ - protected function getQuotedAlterTableRenameColumnSQL(): array - { - return [ - 'ALTER TABLE mytable RENAME COLUMN unquoted1 TO unquoted', - 'ALTER TABLE mytable RENAME COLUMN unquoted2 TO "where"', - 'ALTER TABLE mytable RENAME COLUMN unquoted3 TO "foo"', - 'ALTER TABLE mytable RENAME COLUMN "create" TO reserved_keyword', - 'ALTER TABLE mytable RENAME COLUMN "table" TO "from"', - 'ALTER TABLE mytable RENAME COLUMN "select" TO "bar"', - 'ALTER TABLE mytable RENAME COLUMN quoted1 TO quoted', - 'ALTER TABLE mytable RENAME COLUMN quoted2 TO "and"', - 'ALTER TABLE mytable RENAME COLUMN quoted3 TO "baz"', - ]; - } - - /** - * {@inheritdoc} - */ - protected function getQuotedAlterTableChangeColumnLengthSQL(): array - { - self::markTestIncomplete('Not implemented yet'); - } - /** * {@inheritDoc} */ @@ -467,14 +441,6 @@ public function testReturnsGuidTypeDeclarationSQL(): void self::assertSame('CHAR(36)', $this->platform->getGuidTypeDeclarationSQL([])); } - /** - * {@inheritdoc} - */ - public function getAlterTableRenameColumnSQL(): array - { - return ['ALTER TABLE foo RENAME COLUMN bar TO baz']; - } - /** * @param string[] $expectedSql * diff --git a/tests/Platforms/PostgreSQLPlatformTest.php b/tests/Platforms/PostgreSQLPlatformTest.php index 8c5a335fcbc..5d0e291bcca 100644 --- a/tests/Platforms/PostgreSQLPlatformTest.php +++ b/tests/Platforms/PostgreSQLPlatformTest.php @@ -569,39 +569,6 @@ public static function pgBooleanProvider(): iterable ]; } - /** - * {@inheritdoc} - */ - protected function getQuotedAlterTableRenameColumnSQL(): array - { - return [ - 'ALTER TABLE mytable RENAME COLUMN unquoted1 TO unquoted', - 'ALTER TABLE mytable RENAME COLUMN unquoted2 TO "where"', - 'ALTER TABLE mytable RENAME COLUMN unquoted3 TO "foo"', - 'ALTER TABLE mytable RENAME COLUMN "create" TO reserved_keyword', - 'ALTER TABLE mytable RENAME COLUMN "table" TO "from"', - 'ALTER TABLE mytable RENAME COLUMN "select" TO "bar"', - 'ALTER TABLE mytable RENAME COLUMN quoted1 TO quoted', - 'ALTER TABLE mytable RENAME COLUMN quoted2 TO "and"', - 'ALTER TABLE mytable RENAME COLUMN quoted3 TO "baz"', - ]; - } - - /** - * {@inheritdoc} - */ - protected function getQuotedAlterTableChangeColumnLengthSQL(): array - { - return [ - 'ALTER TABLE mytable ALTER unquoted1 TYPE VARCHAR(255)', - 'ALTER TABLE mytable ALTER unquoted2 TYPE VARCHAR(255)', - 'ALTER TABLE mytable ALTER unquoted3 TYPE VARCHAR(255)', - 'ALTER TABLE mytable ALTER "create" TYPE VARCHAR(255)', - 'ALTER TABLE mytable ALTER "table" TYPE VARCHAR(255)', - 'ALTER TABLE mytable ALTER "select" TYPE VARCHAR(255)', - ]; - } - /** * {@inheritDoc} */ @@ -626,14 +593,6 @@ public function testReturnsGuidTypeDeclarationSQL(): void self::assertSame('UUID', $this->platform->getGuidTypeDeclarationSQL([])); } - /** - * {@inheritdoc} - */ - public function getAlterTableRenameColumnSQL(): array - { - return ['ALTER TABLE foo RENAME COLUMN bar TO baz']; - } - /** * {@inheritdoc} */ diff --git a/tests/Platforms/SQLServerPlatformTest.php b/tests/Platforms/SQLServerPlatformTest.php index 0412d3fb8b1..fffc745da3b 100644 --- a/tests/Platforms/SQLServerPlatformTest.php +++ b/tests/Platforms/SQLServerPlatformTest.php @@ -693,195 +693,6 @@ public function testAlterTableWithSchemaUpdateColumnComments(): void self::assertEquals($expectedSql, $this->platform->getAlterTableSQL($tableDiff)); } - public function testGeneratesCreateTableSQLWithColumnComments(): void - { - $table = new Table('mytable'); - $table->addColumn('id', 'integer', ['autoincrement' => true]); - $table->addColumn('comment_empty_string', 'integer', ['comment' => '']); - $table->addColumn('comment_string_0', 'integer', ['comment' => '0']); - $table->addColumn('comment', 'integer', ['comment' => 'Doctrine 0wnz you!']); - $table->addColumn( - '`comment_quoted`', - 'integer', - ['comment' => 'Doctrine 0wnz comments for explicitly quoted columns!'], - ); - $table->addColumn('create', 'integer', ['comment' => 'Doctrine 0wnz comments for reserved keyword columns!']); - $table->addColumn('commented_type', 'json'); - $table->addColumn('commented_type_with_comment', 'json', ['comment' => 'Doctrine JSON type.']); - $table->addColumn('comment_with_string_literal_char', 'string', [ - 'length' => 255, - 'comment' => "O'Reilly", - ]); - $table->setPrimaryKey(['id']); - - self::assertEquals( - [ - 'CREATE TABLE mytable (id INT IDENTITY NOT NULL, ' - . 'comment_empty_string INT NOT NULL, ' - . 'comment_string_0 INT NOT NULL, ' - . 'comment INT NOT NULL, ' - . '[comment_quoted] INT NOT NULL, ' - . '[create] INT NOT NULL, ' - . 'commented_type VARCHAR(MAX) NOT NULL, ' - . 'commented_type_with_comment VARCHAR(MAX) NOT NULL, ' - . 'comment_with_string_literal_char NVARCHAR(255) NOT NULL, ' - . 'PRIMARY KEY (id))', - "EXEC sp_addextendedproperty N'MS_Description', " - . "N'0', N'SCHEMA', 'dbo', N'TABLE', 'mytable', N'COLUMN', comment_string_0", - "EXEC sp_addextendedproperty N'MS_Description', " - . "N'Doctrine 0wnz you!', N'SCHEMA', 'dbo', N'TABLE', 'mytable', N'COLUMN', comment", - "EXEC sp_addextendedproperty N'MS_Description', " - . "N'Doctrine 0wnz comments for explicitly quoted columns!', " - . "N'SCHEMA', 'dbo', N'TABLE', 'mytable', N'COLUMN', [comment_quoted]", - "EXEC sp_addextendedproperty N'MS_Description', " - . "N'Doctrine 0wnz comments for reserved keyword columns!', " - . "N'SCHEMA', 'dbo', N'TABLE', 'mytable', N'COLUMN', [create]", - "EXEC sp_addextendedproperty N'MS_Description', N'O''Reilly', " - . "N'SCHEMA', 'dbo', N'TABLE', 'mytable', N'COLUMN', comment_with_string_literal_char", - ], - $this->platform->getCreateTableSQL($table), - ); - } - - public function testGeneratesAlterTableSQLWithColumnComments(): void - { - $table = new Table('mytable'); - $table->addColumn('id', 'integer', ['autoincrement' => true]); - $table->addColumn('comment_empty_string', 'integer', ['comment' => '']); - $table->addColumn('comment_string_0', 'integer', ['comment' => '0']); - $table->addColumn('comment', 'integer', ['comment' => 'Doctrine 0wnz you!']); - $table->addColumn( - '`comment_quoted`', - 'integer', - ['comment' => 'Doctrine 0wnz comments for explicitly quoted columns!'], - ); - $table->addColumn('create', 'integer', ['comment' => 'Doctrine 0wnz comments for reserved keyword columns!']); - $table->addColumn('commented_type', 'json'); - $table->addColumn('commented_type_with_comment', 'json', ['comment' => 'Doctrine JSON type.']); - $table->addColumn('comment_with_string_literal_quote_char', 'json', [ - 'length' => 255, - 'comment' => "O'Reilly", - ]); - $table->setPrimaryKey(['id']); - - $tableDiff = new TableDiff($table, [ - new Column('added_comment_none', Type::getType('integer')), - new Column('added_comment_empty_string', Type::getType('integer'), ['comment' => '']), - new Column('added_comment_string_0', Type::getType('integer'), ['comment' => '0']), - new Column('added_comment', Type::getType('integer'), ['comment' => 'Doctrine']), - new Column('`added_comment_quoted`', Type::getType('integer'), ['comment' => 'rulez']), - new Column('select', Type::getType('integer'), ['comment' => '666']), - new Column('added_commented_type', Type::getType('json')), - new Column('added_commented_type_with_comment', Type::getType('json'), ['comment' => '666']), - new Column('added_comment_with_string_literal_char', Type::getType('string'), [ - 'length' => 255, - 'comment' => "''", - ]), - ], [ - // Add comment to non-commented column. - new ColumnDiff( - new Column('id', Type::getType('integer'), ['autoincrement' => true]), - new Column('id', Type::getType('integer'), ['autoincrement' => true, 'comment' => 'primary']), - ), - - // Change type to custom type from empty string commented column. - new ColumnDiff( - new Column('comment_empty_string', Type::getType('integer'), ['comment' => '']), - new Column('comment_empty_string', Type::getType('json')), - ), - - // Change comment to empty comment from zero-string commented column. - new ColumnDiff( - new Column('comment_string_0', Type::getType('integer'), ['comment' => '0']), - new Column('comment_string_0', Type::getType('integer'), ['comment' => '']), - ), - - // Remove comment from regular commented column. - new ColumnDiff( - new Column('comment', Type::getType('integer'), ['comment' => 'Doctrine 0wnz you!']), - new Column('comment', Type::getType('integer')), - ), - - // Change comment and change type to custom type from regular commented column. - new ColumnDiff( - new Column('`comment_quoted`', Type::getType('integer'), ['comment' => 'Doctrine 0wnz you!']), - new Column('`comment_quoted`', Type::getType('json'), ['comment' => 'Doctrine JSON.']), - ), - - // Remove comment and change type to custom type from regular commented column. - new ColumnDiff( - new Column( - 'create', - Type::getType('integer'), - ['comment' => 'Doctrine 0wnz comments for reserved keyword columns!'], - ), - new Column('create', Type::getType('json')), - ), - - // Add comment and change custom type to regular type from non-commented column. - new ColumnDiff( - new Column('commented_type', Type::getType('json')), - new Column('commented_type', Type::getType('integer'), ['comment' => 'foo']), - ), - - // Remove comment from commented custom type column. - new ColumnDiff( - new Column('commented_type_with_comment', Type::getType('json'), ['comment' => 'Doctrine JSON type.']), - new Column('commented_type_with_comment', Type::getType('json')), - ), - - // Change comment from comment with string literal char column. - new ColumnDiff( - new Column('comment_with_string_literal_char', Type::getType('json'), ['comment' => "O'Reilly"]), - new Column('comment_with_string_literal_char', Type::getType('string'), ['comment' => "'"]), - ), - ], [], [], [], [], [], [], [], [], []); - - self::assertEquals( - [ - // Added columns. - 'ALTER TABLE mytable ADD added_comment_none INT NOT NULL', - 'ALTER TABLE mytable ADD added_comment_empty_string INT NOT NULL', - 'ALTER TABLE mytable ADD added_comment_string_0 INT NOT NULL', - 'ALTER TABLE mytable ADD added_comment INT NOT NULL', - 'ALTER TABLE mytable ADD [added_comment_quoted] INT NOT NULL', - 'ALTER TABLE mytable ADD [select] INT NOT NULL', - 'ALTER TABLE mytable ADD added_commented_type VARCHAR(MAX) NOT NULL', - 'ALTER TABLE mytable ADD added_commented_type_with_comment VARCHAR(MAX) NOT NULL', - 'ALTER TABLE mytable ADD added_comment_with_string_literal_char NVARCHAR(255) NOT NULL', - 'ALTER TABLE mytable ALTER COLUMN comment_empty_string VARCHAR(MAX) NOT NULL', - 'ALTER TABLE mytable ALTER COLUMN [comment_quoted] VARCHAR(MAX) NOT NULL', - 'ALTER TABLE mytable ALTER COLUMN [create] VARCHAR(MAX) NOT NULL', - 'ALTER TABLE mytable ALTER COLUMN commented_type INT NOT NULL', - - // Added columns. - "EXEC sp_addextendedproperty N'MS_Description', N'0', " - . "N'SCHEMA', 'dbo', N'TABLE', 'mytable', N'COLUMN', added_comment_string_0", - "EXEC sp_addextendedproperty N'MS_Description', N'Doctrine', " - . "N'SCHEMA', 'dbo', N'TABLE', 'mytable', N'COLUMN', added_comment", - "EXEC sp_addextendedproperty N'MS_Description', N'rulez', " - . "N'SCHEMA', 'dbo', N'TABLE', 'mytable', N'COLUMN', [added_comment_quoted]", - "EXEC sp_addextendedproperty N'MS_Description', N'666', " - . "N'SCHEMA', 'dbo', N'TABLE', 'mytable', N'COLUMN', [select]", - "EXEC sp_addextendedproperty N'MS_Description', N'''''', " - . "N'SCHEMA', 'dbo', N'TABLE', 'mytable', N'COLUMN', added_comment_with_string_literal_char", - - // Changed columns. - "EXEC sp_addextendedproperty N'MS_Description', N'primary', " - . "N'SCHEMA', 'dbo', N'TABLE', 'mytable', N'COLUMN', id", - "EXEC sp_dropextendedproperty N'MS_Description', " - . "N'SCHEMA', 'dbo', N'TABLE', 'mytable', N'COLUMN', comment_string_0", - "EXEC sp_dropextendedproperty N'MS_Description', " - . "N'SCHEMA', 'dbo', N'TABLE', 'mytable', N'COLUMN', comment", - "EXEC sp_updateextendedproperty N'MS_Description', N'foo', " - . "N'SCHEMA', 'dbo', N'TABLE', 'mytable', N'COLUMN', commented_type", - "EXEC sp_updateextendedproperty N'MS_Description', N'''', " - . "N'SCHEMA', 'dbo', N'TABLE', 'mytable', N'COLUMN', comment_with_string_literal_char", - ], - $this->platform->getAlterTableSQL($tableDiff), - ); - } - public function testInitializesDoctrineTypeMappings(): void { self::assertTrue($this->platform->hasDoctrineTypeMappingFor('bigint')); @@ -1008,68 +819,6 @@ protected function getQuotedAlterTableRenameIndexSQL(): array ]; } - public function testChangeColumnsTypeWithDefaultValue(): void - { - $tableName = 'column_def_change_type'; - $table = new Table($tableName); - - $table->addColumn('col_int', 'smallint', ['default' => 666]); - $table->addColumn('col_string', 'string', ['default' => 'foo']); - - $tableDiff = new TableDiff($table, [], [ - new ColumnDiff( - new Column('col_int', Type::getType('smallint'), ['default' => 666]), - new Column('col_int', Type::getType('integer'), ['default' => 666]), - ), - new ColumnDiff( - new Column('col_string', Type::getType('string'), ['default' => 'foo']), - new Column('col_string', Type::getType('string'), [ - 'length' => 255, - 'fixed' => true, - 'default' => 'foo', - ]), - ), - ], [], [], [], [], [], [], [], [], []); - - self::assertSame( - [ - 'ALTER TABLE column_def_change_type DROP CONSTRAINT DF_829302E0_FA2CB292', - 'ALTER TABLE column_def_change_type ALTER COLUMN col_int INT NOT NULL', - 'ALTER TABLE column_def_change_type ADD CONSTRAINT DF_829302E0_FA2CB292 DEFAULT 666 FOR col_int', - 'ALTER TABLE column_def_change_type DROP CONSTRAINT DF_829302E0_2725A6D0', - 'ALTER TABLE column_def_change_type ALTER COLUMN col_string NCHAR(255) NOT NULL', - "ALTER TABLE column_def_change_type ADD CONSTRAINT DF_829302E0_2725A6D0 DEFAULT 'foo' FOR col_string", - ], - $this->platform->getAlterTableSQL($tableDiff), - ); - } - - /** - * {@inheritdoc} - */ - protected function getQuotedAlterTableRenameColumnSQL(): array - { - return [ - "sp_rename 'mytable.unquoted1', 'unquoted', 'COLUMN'", - "sp_rename 'mytable.unquoted2', '[where]', 'COLUMN'", - "sp_rename 'mytable.unquoted3', '[foo]', 'COLUMN'", - "sp_rename 'mytable.[create]', 'reserved_keyword', 'COLUMN'", - "sp_rename 'mytable.[table]', '[from]', 'COLUMN'", - "sp_rename 'mytable.[select]', '[bar]', 'COLUMN'", - "sp_rename 'mytable.quoted1', 'quoted', 'COLUMN'", - "sp_rename 'mytable.quoted2', '[and]', 'COLUMN'", - "sp_rename 'mytable.quoted3', '[baz]', 'COLUMN'", - ]; - } - - /** - * {@inheritdoc} - */ - protected function getQuotedAlterTableChangeColumnLengthSQL(): array - { - self::markTestIncomplete('Not implemented yet'); - } - /** * {@inheritDoc} */ @@ -1089,293 +838,11 @@ protected function getQuotedAlterTableRenameIndexInSchemaSQL(): array ]; } - /** - * @param string[] $expectedSql - * - * @dataProvider getGeneratesIdentifierNamesInCreateTableSQL - */ - public function testGeneratesIdentifierNamesInCreateTableSQL(Table $table, array $expectedSql): void - { - self::assertSame($expectedSql, $this->platform->getCreateTableSQL($table)); - } - - /** @return mixed[][] */ - public static function getGeneratesIdentifierNamesInCreateTableSQL(): iterable - { - return [ - // Unquoted identifiers non-reserved keywords. - [ - new Table('mytable', [ - new Column('mycolumn', Type::getType('string'), [ - 'length' => 255, - 'default' => 'foo', - ]), - ]), - [ - 'CREATE TABLE mytable (mycolumn NVARCHAR(255) NOT NULL)', - "ALTER TABLE mytable ADD CONSTRAINT DF_6B2BD609_9BADD926 DEFAULT 'foo' FOR mycolumn", - ], - ], - // Quoted identifiers reserved keywords. - [ - new Table('`mytable`', [ - new Column('`mycolumn`', Type::getType('string'), [ - 'length' => 255, - 'default' => 'foo', - ]), - ]), - [ - 'CREATE TABLE [mytable] ([mycolumn] NVARCHAR(255) NOT NULL)', - "ALTER TABLE [mytable] ADD CONSTRAINT DF_6B2BD609_9BADD926 DEFAULT 'foo' FOR [mycolumn]", - ], - ], - // Unquoted identifiers reserved keywords. - [ - new Table('table', [ - new Column('select', Type::getType('string'), [ - 'length' => 255, - 'default' => 'foo', - ]), - ]), - [ - 'CREATE TABLE [table] ([select] NVARCHAR(255) NOT NULL)', - "ALTER TABLE [table] ADD CONSTRAINT DF_F6298F46_4BF2EAC0 DEFAULT 'foo' FOR [select]", - ], - ], - // Quoted identifiers reserved keywords. - [ - new Table('`table`', [ - new Column('`select`', Type::getType('string'), [ - 'length' => 255, - 'default' => 'foo', - ]), - ]), - [ - 'CREATE TABLE [table] ([select] NVARCHAR(255) NOT NULL)', - "ALTER TABLE [table] ADD CONSTRAINT DF_F6298F46_4BF2EAC0 DEFAULT 'foo' FOR [select]", - ], - ], - ]; - } - - /** - * @param string[] $expectedSql - * - * @dataProvider getGeneratesIdentifierNamesInAlterTableSQL - */ - public function testGeneratesIdentifierNamesInAlterTableSQL(TableDiff $tableDiff, array $expectedSql): void - { - self::assertSame($expectedSql, $this->platform->getAlterTableSQL($tableDiff)); - } - - /** @return mixed[][] */ - public static function getGeneratesIdentifierNamesInAlterTableSQL(): iterable - { - return [ - // Unquoted identifiers non-reserved keywords. - [ - new TableDiff( - new Table('mytable'), - [ - new Column('addcolumn', Type::getType('string'), [ - 'length' => 255, - 'default' => 'foo', - ]), - ], - [ - new ColumnDiff( - new Column('mycolumn', Type::getType('string'), [ - 'length' => 255, - 'default' => 'foo', - ]), - new Column('mycolumn', Type::getType('string'), [ - 'length' => 255, - 'default' => 'bar', - ]), - ), - ], - [ - new Column('removecolumn', Type::getType('string'), [ - 'length' => 255, - 'default' => 'foo', - ]), - ], - [], - [], - [], - [], - [], - [], - [], - [], - ), - [ - 'ALTER TABLE mytable ADD addcolumn NVARCHAR(255) NOT NULL ' . - "CONSTRAINT DF_6B2BD609_4AD86123 DEFAULT 'foo'", - 'ALTER TABLE mytable DROP COLUMN removecolumn', - 'ALTER TABLE mytable DROP CONSTRAINT DF_6B2BD609_9BADD926', - 'ALTER TABLE mytable ALTER COLUMN mycolumn NVARCHAR(255) NOT NULL', - "ALTER TABLE mytable ADD CONSTRAINT DF_6B2BD609_9BADD926 DEFAULT 'bar' FOR mycolumn", - ], - ], - // Quoted identifiers non-reserved keywords. - [ - new TableDiff( - new Table('`mytable`'), - [ - new Column('`addcolumn`', Type::getType('string'), [ - 'length' => 255, - 'default' => 'foo', - ]), - ], - [ - new ColumnDiff( - new Column('`mycolumn`', Type::getType('string'), [ - 'length' => 255, - 'default' => 'foo', - ]), - new Column('`mycolumn`', Type::getType('string'), [ - 'length' => 255, - 'default' => 'bar', - ]), - ), - ], - [ - new Column('`removecolumn`', Type::getType('string'), [ - 'length' => 255, - 'default' => 'foo', - ]), - ], - [], - [], - [], - [], - [], - [], - [], - [], - ), - [ - 'ALTER TABLE [mytable] ADD [addcolumn] NVARCHAR(255) NOT NULL ' . - "CONSTRAINT DF_6B2BD609_4AD86123 DEFAULT 'foo'", - 'ALTER TABLE [mytable] DROP COLUMN [removecolumn]', - 'ALTER TABLE [mytable] DROP CONSTRAINT DF_6B2BD609_9BADD926', - 'ALTER TABLE [mytable] ALTER COLUMN [mycolumn] NVARCHAR(255) NOT NULL', - "ALTER TABLE [mytable] ADD CONSTRAINT DF_6B2BD609_9BADD926 DEFAULT 'bar' FOR [mycolumn]", - ], - ], - // Unquoted identifiers reserved keywords. - [ - new TableDiff( - new Table('`mytable`'), - [ - new Column('add', Type::getType('string'), [ - 'length' => 255, - 'default' => 'foo', - ]), - ], - [ - new ColumnDiff( - new Column('select', Type::getType('string'), [ - 'length' => 255, - 'default' => 'foo', - ]), - new Column('select', Type::getType('string'), [ - 'length' => 255, - 'default' => 'bar', - ]), - ), - ], - [ - new Column('drop', Type::getType('string'), [ - 'length' => 255, - 'default' => 'foo', - ]), - ], - [], - [], - [], - [], - [], - [], - [], - [], - ), - [ - 'ALTER TABLE [table] ADD [add] NVARCHAR(255) NOT NULL ' . - "CONSTRAINT DF_F6298F46_FD1A73E7 DEFAULT 'foo'", - 'ALTER TABLE [table] DROP COLUMN [drop]', - 'ALTER TABLE [table] DROP CONSTRAINT DF_F6298F46_4BF2EAC0', - 'ALTER TABLE [table] ALTER COLUMN [select] NVARCHAR(255) NOT NULL', - "ALTER TABLE [table] ADD CONSTRAINT DF_F6298F46_4BF2EAC0 DEFAULT 'bar' FOR [select]", - ], - ], - // Quoted identifiers reserved keywords. - [ - new TableDiff( - new Table('`table`'), - [ - new Column('`add`', Type::getType('string'), [ - 'length' => 255, - 'default' => 'foo', - ]), - ], - [ - new ColumnDiff( - new Column('`select`', Type::getType('string'), [ - 'length' => 255, - 'default' => 'foo', - ]), - new Column('`select`', Type::getType('string'), [ - 'length' => 255, - 'default' => 'bar', - ]), - ), - ], - [ - new Column('`drop`', Type::getType('string'), [ - 'length' => 255, - 'default' => 'foo', - ]), - ], - [], - [], - [], - [], - [], - [], - [], - [], - ), - [ - 'ALTER TABLE [table] ADD [add] NVARCHAR(255) NOT NULL ' . - "CONSTRAINT DF_F6298F46_FD1A73E7 DEFAULT 'foo'", - 'ALTER TABLE [table] DROP COLUMN [drop]', - 'ALTER TABLE [table] DROP CONSTRAINT DF_F6298F46_4BF2EAC0', - 'ALTER TABLE [table] ALTER COLUMN [select] NVARCHAR(255) NOT NULL', - "ALTER TABLE [table] ADD CONSTRAINT DF_F6298F46_4BF2EAC0 DEFAULT 'bar' FOR [select]", - ], - ], - ]; - } - public function testReturnsGuidTypeDeclarationSQL(): void { self::assertSame('UNIQUEIDENTIFIER', $this->platform->getGuidTypeDeclarationSQL([])); } - /** - * {@inheritdoc} - */ - public function getAlterTableRenameColumnSQL(): array - { - return [ - "sp_rename 'foo.bar', 'baz', 'COLUMN'", - 'ALTER TABLE foo DROP CONSTRAINT DF_8C736521_76FF8CAA', - 'ALTER TABLE foo ADD CONSTRAINT DF_8C736521_78240498 DEFAULT 666 FOR baz', - ]; - } - /** * {@inheritdoc} */ diff --git a/tests/Platforms/SQLitePlatformTest.php b/tests/Platforms/SQLitePlatformTest.php index 8e67a259ffe..170da31a01d 100644 --- a/tests/Platforms/SQLitePlatformTest.php +++ b/tests/Platforms/SQLitePlatformTest.php @@ -423,54 +423,6 @@ protected function getQuotedAlterTableRenameIndexSQL(): array ]; } - /** - * {@inheritdoc} - */ - protected function getQuotedAlterTableRenameColumnSQL(): array - { - return [ - 'CREATE TEMPORARY TABLE __temp__mytable AS SELECT unquoted1, unquoted2, unquoted3, ' - . '"create", "table", "select", "quoted1", "quoted2", "quoted3" FROM mytable', - 'DROP TABLE mytable', - 'CREATE TABLE mytable (unquoted INTEGER NOT NULL --Unquoted 1 -, "where" INTEGER NOT NULL --Unquoted 2 -, "foo" INTEGER NOT NULL --Unquoted 3 -, reserved_keyword INTEGER NOT NULL --Reserved keyword 1 -, "from" INTEGER NOT NULL --Reserved keyword 2 -, "bar" INTEGER NOT NULL --Reserved keyword 3 -, quoted INTEGER NOT NULL --Quoted 1 -, "and" INTEGER NOT NULL --Quoted 2 -, "baz" INTEGER NOT NULL --Quoted 3 -)', - 'INSERT INTO mytable (unquoted, "where", "foo", reserved_keyword, "from", "bar", quoted, "and", "baz") ' - . 'SELECT unquoted1, unquoted2, unquoted3, "create", "table", "select", ' - . '"quoted1", "quoted2", "quoted3" FROM __temp__mytable', - 'DROP TABLE __temp__mytable', - ]; - } - - /** - * {@inheritdoc} - */ - protected function getQuotedAlterTableChangeColumnLengthSQL(): array - { - return [ - 'CREATE TEMPORARY TABLE __temp__mytable AS SELECT unquoted1, unquoted2, unquoted3, ' - . '"create", "table", "select" FROM mytable', - 'DROP TABLE mytable', - 'CREATE TABLE mytable (unquoted1 VARCHAR(255) NOT NULL --Unquoted 1 -, unquoted2 VARCHAR(255) NOT NULL --Unquoted 2 -, unquoted3 VARCHAR(255) NOT NULL --Unquoted 3 -, "create" VARCHAR(255) NOT NULL --Reserved keyword 1 -, "table" VARCHAR(255) NOT NULL --Reserved keyword 2 -, "select" VARCHAR(255) NOT NULL --Reserved keyword 3 -)', - 'INSERT INTO mytable (unquoted1, unquoted2, unquoted3, "create", "table", "select") ' - . 'SELECT unquoted1, unquoted2, unquoted3, "create", "table", "select" FROM __temp__mytable', - 'DROP TABLE __temp__mytable', - ]; - } - public function testAlterTableRenameIndexInSchema(): void { self::markTestIncomplete( @@ -492,21 +444,6 @@ public function testReturnsGuidTypeDeclarationSQL(): void self::assertSame('CHAR(36)', $this->platform->getGuidTypeDeclarationSQL([])); } - /** - * {@inheritdoc} - */ - public function getAlterTableRenameColumnSQL(): array - { - return [ - 'CREATE TEMPORARY TABLE __temp__foo AS SELECT bar FROM foo', - 'DROP TABLE foo', - 'CREATE TABLE foo (baz INTEGER DEFAULT 666 NOT NULL --rename test -)', - 'INSERT INTO foo (baz) SELECT bar FROM __temp__foo', - 'DROP TABLE __temp__foo', - ]; - } - /** * {@inheritdoc} */