Skip to content

Commit

Permalink
Merge pull request doctrine#5757 from morozov/4.0.x
Browse files Browse the repository at this point in the history
Merge 3.5.x into 4.0.x
  • Loading branch information
morozov committed Oct 12, 2022
2 parents d2c74da + 0a0cd8a commit d8a5b7c
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 1,018 deletions.
5 changes: 5 additions & 0 deletions src/Platforms/SQLitePlatform.php
Expand Up @@ -54,6 +54,11 @@ public function getRegexpExpression(): string
return 'REGEXP';
}

public function getModExpression(string $dividend, string $divisor): string
{
return $dividend . ' % ' . $divisor;
}

public function getTrimExpression(
string $str,
TrimMode $mode = TrimMode::UNSPECIFIED,
Expand Down
56 changes: 0 additions & 56 deletions tests/Platforms/AbstractMySQLPlatformTestCase.php
Expand Up @@ -546,67 +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}
*/
protected function getQuotesTableIdentifiersInAlterTableSQL(): array
{
return [
'ALTER TABLE `foo` DROP FOREIGN KEY fk1',
'ALTER TABLE `foo` DROP FOREIGN KEY fk2',
'ALTER TABLE `foo` ADD bloo INT NOT NULL, DROP baz, CHANGE bar bar INT DEFAULT NULL, ' .
'CHANGE id war INT NOT NULL',
'ALTER TABLE `foo` ADD CONSTRAINT fk_add FOREIGN KEY (fk3) REFERENCES fk_table (id)',
'ALTER TABLE `foo` ADD CONSTRAINT fk2 FOREIGN KEY (fk2) REFERENCES fk_table2 (id)',
];
}

/**
* {@inheritdoc}
*/
Expand Down
164 changes: 0 additions & 164 deletions tests/Platforms/AbstractPlatformTestCase.php
Expand Up @@ -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');
Expand Down Expand Up @@ -1043,69 +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 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($table, [
new Column('bloo', Type::getType('integer')),
], [
new ColumnDiff(
$table->getColumn('bar'),
new Column('bar', Type::getType('integer'), ['notnull' => false]),
),
], [
new Column('baz', Type::getType('integer')),
], [
'id' => new Column('war', Type::getType('integer')),
], [], [], [], [], [
new ForeignKeyConstraint(['fk3'], 'fk_table', ['id'], 'fk_add'),
], [
new ForeignKeyConstraint(['fk2'], 'fk_table2', ['id'], 'fk2'),
], [
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');
Expand Down
53 changes: 0 additions & 53 deletions tests/Platforms/DB2PlatformTest.php
Expand Up @@ -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}
*/
Expand All @@ -455,33 +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}
*/
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"\')',
'ALTER TABLE "foo" ADD CONSTRAINT fk_add FOREIGN KEY (fk3) REFERENCES fk_table (id)',
'ALTER TABLE "foo" ADD CONSTRAINT fk2 FOREIGN KEY (fk2) REFERENCES fk_table2 (id)',
];
}

/**
* {@inheritdoc}
*/
Expand Down
51 changes: 0 additions & 51 deletions tests/Platforms/OraclePlatformTest.php
Expand Up @@ -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}
*/
Expand All @@ -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
*
Expand Down Expand Up @@ -516,23 +482,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" ADD CONSTRAINT fk_add FOREIGN KEY (fk3) REFERENCES fk_table (id)',
'ALTER TABLE "foo" ADD CONSTRAINT fk2 FOREIGN KEY (fk2) REFERENCES fk_table2 (id)',
];
}

/**
* {@inheritdoc}
*/
Expand Down

0 comments on commit d8a5b7c

Please sign in to comment.