Skip to content

Commit

Permalink
Merge branch '4.0.x' into 4.1.x
Browse files Browse the repository at this point in the history
* 4.0.x:
  PHPUnit 10.5.21 (doctrine#6447)
  Move schema split for SQLite CREATE INDEX only (doctrine#6352)
  PHPStan 1.11.5 (doctrine#6446)
  Revert "Merge pull request doctrine#6413 from achterin/bugfix/foreign_key_name_change_detection"
  • Loading branch information
derrabus committed Jun 19, 2024
2 parents 9cc0c0c + 0b66bc8 commit 31fc090
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 18 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@
"doctrine/coding-standard": "12.0.0",
"fig/log-test": "^1",
"jetbrains/phpstorm-stubs": "2023.2",
"phpstan/phpstan": "1.11.1",
"phpstan/phpstan": "1.11.5",
"phpstan/phpstan-phpunit": "1.4.0",
"phpstan/phpstan-strict-rules": "^1.6",
"phpunit/phpunit": "10.5.20",
"phpunit/phpunit": "10.5.21",
"psalm/plugin-phpunit": "0.19.0",
"slevomat/coding-standard": "8.13.1",
"squizlabs/php_codesniffer": "3.9.2",
Expand Down
6 changes: 6 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@ parameters:

# Required for Psalm compatibility
- '~^Property Doctrine\\DBAL\\Tests\\Types\\BaseDateTypeTestCase\:\:\$currentTimezone \(non-empty-string\) does not accept string\.$~'

# This is a rather complicated closure setup. We understand this, so PHPStan doesn't have to.
-
message: '#^Parameter \#2 \$callback of function array_reduce expects callable\(\(callable&TIn\)\|Closure\(mixed \$value\)\: mixed\|null, callable\(T\)\: T\)\: \(\(callable&TIn\)\|Closure\(mixed \$value\)\: mixed\|null\), Closure\(callable\|null, callable\)\: \(callable\(T\)\: T\) given\.$#'
path: src/Portability/Converter.php

includes:
- vendor/phpstan/phpstan-phpunit/extension.neon
- vendor/phpstan/phpstan-phpunit/rules.neon
Expand Down
10 changes: 5 additions & 5 deletions src/Platforms/SQLitePlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -548,11 +548,6 @@ public function getCreateIndexSQL(Index $index, string $table): string
$name = $index->getQuotedName($this);
$columns = $index->getColumns();

if (strpos($table, '.') !== false) {
[$schema, $table] = explode('.', $table);
$name = $schema . '.' . $name;
}

if (count($columns) === 0) {
throw new InvalidArgumentException(sprintf(
'Incomplete or invalid index definition %s on table %s',
Expand All @@ -565,6 +560,11 @@ public function getCreateIndexSQL(Index $index, string $table): string
return $this->getCreatePrimaryKeySQL($index, $table);
}

if (strpos($table, '.') !== false) {
[$schema, $table] = explode('.', $table);
$name = $schema . '.' . $name;
}

$query = 'CREATE ' . $this->getCreateIndexSQLFlags($index) . 'INDEX ' . $name . ' ON ' . $table;
$query .= ' (' . implode(', ', $index->getQuotedColumns($this)) . ')' . $this->getPartialIndexSQL($index);

Expand Down
4 changes: 0 additions & 4 deletions src/Schema/Comparator.php
Original file line number Diff line number Diff line change
Expand Up @@ -371,10 +371,6 @@ private function detectRenamedIndexes(array &$addedIndexes, array &$removedIndex

protected function diffForeignKey(ForeignKeyConstraint $key1, ForeignKeyConstraint $key2): bool
{
if (strtolower($key1->getName()) !== strtolower($key2->getName())) {
return true;
}

if (
array_map('strtolower', $key1->getUnquotedLocalColumns())
!== array_map('strtolower', $key2->getUnquotedLocalColumns())
Expand Down
29 changes: 29 additions & 0 deletions tests/Platforms/SQLitePlatformTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@
use Doctrine\DBAL\Platforms\SQLitePlatform;
use Doctrine\DBAL\Schema\Column;
use Doctrine\DBAL\Schema\Comparator;
use Doctrine\DBAL\Schema\Index;
use Doctrine\DBAL\Schema\Table;
use Doctrine\DBAL\Schema\TableDiff;
use Doctrine\DBAL\TransactionIsolationLevel;
use Doctrine\DBAL\Types\Type;
use Doctrine\DBAL\Types\Types;

use function implode;

/** @extends AbstractPlatformTestCase<SQLitePlatform> */
class SQLitePlatformTest extends AbstractPlatformTestCase
{
Expand Down Expand Up @@ -176,6 +179,32 @@ public function getGenerateUniqueIndexSql(): string
return 'CREATE UNIQUE INDEX index_name ON test (test, test2)';
}

public function testGeneratesIndexCreationSqlWithSchema(): void
{
$indexDef = new Index('i', ['a', 'b']);

self::assertSame(
'CREATE INDEX main.i ON mytable (a, b)',
$this->platform->getCreateIndexSQL($indexDef, 'main.mytable'),
);
}

public function testGeneratesPrimaryIndexCreationSqlWithSchema(): void
{
$primaryIndexDef = new Index('i2', ['a', 'b'], false, true);

self::assertSame(
'TEST: main.mytable, i2 - a, b',
(new class () extends SqlitePlatform {
public function getCreatePrimaryKeySQL(Index $index, string $table): string
{
return 'TEST: ' . $table . ', ' . $index->getName()
. ' - ' . implode(', ', $index->getColumns());
}
})->getCreateIndexSQL($primaryIndexDef, 'main.mytable'),
);
}

public function testGeneratesForeignKeyCreationSql(): void
{
$this->expectException(Exception::class);
Expand Down
10 changes: 3 additions & 7 deletions tests/Schema/AbstractComparatorTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ public function testCompareColumnCompareCaseInsensitive(): void
self::assertTrue($tableDiff->isEmpty());
}

public function testDetectIndexNameChange(): void
public function testCompareIndexBasedOnPropertiesNotName(): void
{
$tableA = new Table('foo');
$tableA->addColumn('id', Types::INTEGER);
Expand All @@ -363,7 +363,7 @@ public function testDetectIndexNameChange(): void
);
}

public function testDetectForeignKeyNameChange(): void
public function testCompareForeignKeyBasedOnPropertiesNotName(): void
{
$tableA = new Table('foo');
$tableA->addColumn('id', Types::INTEGER);
Expand All @@ -374,11 +374,7 @@ public function testDetectForeignKeyNameChange(): void
$tableB->addForeignKeyConstraint('bar', ['id'], ['id'], [], 'bar_constraint');

self::assertEquals(
new TableDiff($tableA, [], [], [], [], [], [], [], [], [
new ForeignKeyConstraint(['id'], 'bar', ['id'], 'bar_constraint'),
], [], [
new ForeignKeyConstraint(['id'], 'bar', ['id'], 'foo_constraint'),
]),
new TableDiff($tableA, [], [], [], [], [], [], [], [], [], [], []),
$this->comparator->compareTables($tableA, $tableB),
);
}
Expand Down

0 comments on commit 31fc090

Please sign in to comment.