Skip to content

Commit

Permalink
Merge pull request #5629 from morozov/issues/5627
Browse files Browse the repository at this point in the history
Clean up test scenarios related to altering columns
  • Loading branch information
morozov authored Aug 29, 2022
2 parents 5d01655 + 2749156 commit 035b4a8
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 146 deletions.
49 changes: 49 additions & 0 deletions tests/Functional/Platform/AlterDecimalColumnTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

declare(strict_types=1);

namespace Doctrine\DBAL\Tests\Functional\Platform;

use Doctrine\DBAL\Schema\Table;
use Doctrine\DBAL\Tests\FunctionalTestCase;
use Doctrine\DBAL\Types\Types;

class AlterDecimalColumnTest extends FunctionalTestCase
{
/**
* @dataProvider scaleAndPrecisionProvider
*/
public function testAlterPrecisionAndScale(int $newPrecision, int $newScale): void
{
$table = new Table('decimal_table');
$column = $table->addColumn('val', Types::DECIMAL, ['precision' => 16, 'scale' => 6]);

$this->dropAndCreateTable($table);

$column->setPrecision($newPrecision);
$column->setScale($newScale);

$schemaManager = $this->connection->createSchemaManager();

$diff = $schemaManager->createComparator()
->diffTable($schemaManager->introspectTable('decimal_table'), $table);
self::assertNotNull($diff);
$schemaManager->alterTable($diff);

$table = $schemaManager->introspectTable('decimal_table');
$column = $table->getColumn('val');

self::assertSame($newPrecision, $column->getPrecision());
self::assertSame($newScale, $column->getScale());
}

/**
* @return iterable<string,array{int,int}>
*/
public function scaleAndPrecisionProvider(): iterable
{
yield 'Precision' => [12, 6];
yield 'Scale' => [16, 8];
yield 'Precision and scale' => [10, 4];
}
}
23 changes: 0 additions & 23 deletions tests/Platforms/AbstractMySQLPlatformTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,29 +194,6 @@ public function testGetDateTimeTypeDeclarationSql(): void
self::assertEquals('DATETIME', $this->platform->getDateTimeTypeDeclarationSQL([]));
}

/**
* {@inheritDoc}
*/
public function getCreateTableColumnCommentsSQL(): array
{
return [
"CREATE TABLE test (id INT NOT NULL COMMENT 'This is a comment', "
. 'PRIMARY KEY(id))',
];
}

/**
* {@inheritDoc}
*/
public function getAlterTableColumnCommentsSQL(): array
{
return [
"ALTER TABLE mytable ADD quota INT NOT NULL COMMENT 'A comment', "
. 'CHANGE foo foo VARCHAR(255) NOT NULL, '
. "CHANGE bar baz VARCHAR(255) NOT NULL COMMENT 'B comment'",
];
}

public function testChangeIndexWithForeignKeys(): void
{
$index = new Index('idx', ['col'], false);
Expand Down
25 changes: 0 additions & 25 deletions tests/Platforms/AbstractPlatformTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -387,31 +387,6 @@ public function testGetAlterTableSqlDispatchEvent(): void
$this->platform->getAlterTableSQL($tableDiff);
}

public function testCreateTableColumnComments(): void
{
$table = new Table('test');
$table->addColumn('id', 'integer', ['comment' => 'This is a comment']);
$table->setPrimaryKey(['id']);

self::assertEquals($this->getCreateTableColumnCommentsSQL(), $this->platform->getCreateTableSQL($table));
}

/**
* @return string[]
*/
public function getCreateTableColumnCommentsSQL(): array
{
self::markTestSkipped('Platform does not support Column comments.');
}

/**
* @return string[]
*/
public function getAlterTableColumnCommentsSQL(): array
{
self::markTestSkipped('Platform does not support Column comments.');
}

public function testGetDefaultValueDeclarationSQL(): void
{
// non-timestamp value will get single quotes
Expand Down
26 changes: 0 additions & 26 deletions tests/Platforms/DB2PlatformTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,32 +134,6 @@ protected function getBitOrComparisonExpressionSql(string $value1, string $value
return 'BITOR(' . $value1 . ', ' . $value2 . ')';
}

/**
* {@inheritDoc}
*/
public function getCreateTableColumnCommentsSQL(): array
{
return [
'CREATE TABLE test (id INTEGER NOT NULL, PRIMARY KEY(id))',
"COMMENT ON COLUMN test.id IS 'This is a comment'",
];
}

/**
* {@inheritDoc}
*/
public function getAlterTableColumnCommentsSQL(): array
{
return [
'ALTER TABLE mytable ' .
'ADD COLUMN quota INTEGER NOT NULL WITH DEFAULT',
"CALL SYSPROC.ADMIN_CMD ('REORG TABLE mytable')",
"COMMENT ON COLUMN mytable.quota IS 'A comment'",
"COMMENT ON COLUMN mytable.foo IS ''",
"COMMENT ON COLUMN mytable.baz IS 'B comment'",
];
}

public function testGeneratesCreateTableSQLWithCommonIndexes(): void
{
$table = new Table('test');
Expand Down
24 changes: 0 additions & 24 deletions tests/Platforms/OraclePlatformTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -269,30 +269,6 @@ public function testGenerateTableWithAutoincrement(): void
], $this->platform->getCreateTableSQL($table));
}

/**
* {@inheritDoc}
*/
public function getCreateTableColumnCommentsSQL(): array
{
return [
'CREATE TABLE test (id NUMBER(10) NOT NULL, PRIMARY KEY(id))',
"COMMENT ON COLUMN test.id IS 'This is a comment'",
];
}

/**
* {@inheritDoc}
*/
public function getAlterTableColumnCommentsSQL(): array
{
return [
'ALTER TABLE mytable ADD (quota NUMBER(10) NOT NULL)',
"COMMENT ON COLUMN mytable.quota IS 'A comment'",
"COMMENT ON COLUMN mytable.foo IS ''",
"COMMENT ON COLUMN mytable.baz IS 'B comment'",
];
}

public function getBitAndComparisonExpressionSql(string $value1, string $value2): string
{
return 'BITAND(' . $value1 . ', ' . $value2 . ')';
Expand Down
24 changes: 0 additions & 24 deletions tests/Platforms/PostgreSQLPlatformTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -340,30 +340,6 @@ public function testModifyLimitQueryWithEmptyOffset(): void
self::assertEquals('SELECT * FROM user LIMIT 10', $sql);
}

/**
* {@inheritDoc}
*/
public function getCreateTableColumnCommentsSQL(): array
{
return [
'CREATE TABLE test (id INT NOT NULL, PRIMARY KEY(id))',
"COMMENT ON COLUMN test.id IS 'This is a comment'",
];
}

/**
* {@inheritDoc}
*/
public function getAlterTableColumnCommentsSQL(): array
{
return [
'ALTER TABLE mytable ADD quota INT NOT NULL',
"COMMENT ON COLUMN mytable.quota IS 'A comment'",
"COMMENT ON COLUMN mytable.foo IS ''",
"COMMENT ON COLUMN mytable.baz IS 'B comment'",
];
}

/**
* {@inheritDoc}
*/
Expand Down
24 changes: 0 additions & 24 deletions tests/Platforms/SQLServerPlatformTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -714,30 +714,6 @@ public function testAlterTableWithSchemaUpdateColumnComments(): void
self::assertEquals($expectedSql, $this->platform->getAlterTableSQL($tableDiff));
}

/**
* {@inheritDoc}
*/
public function getCreateTableColumnCommentsSQL(): array
{
return [
'CREATE TABLE test (id INT NOT NULL, PRIMARY KEY (id))',
"EXEC sp_addextendedproperty N'MS_Description', N'This is a comment', "
. "N'SCHEMA', 'dbo', N'TABLE', 'test', N'COLUMN', id",
];
}

/**
* {@inheritDoc}
*/
public function getAlterTableColumnCommentsSQL(): array
{
return [
'ALTER TABLE mytable ADD quota INT NOT NULL',
"EXEC sp_addextendedproperty N'MS_Description', N'A comment', "
. "N'SCHEMA', 'dbo', N'TABLE', 'mytable', N'COLUMN', quota",
];
}

public function testGeneratesCreateTableSQLWithColumnComments(): void
{
$table = new Table('mytable');
Expand Down

0 comments on commit 035b4a8

Please sign in to comment.