diff --git a/composer.json b/composer.json index 2ee601aedbe..9df784abf53 100644 --- a/composer.json +++ b/composer.json @@ -40,7 +40,7 @@ "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.21", diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 7649943adf0..2dc11d8e184 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -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 diff --git a/src/Platforms/SQLitePlatform.php b/src/Platforms/SQLitePlatform.php index 8ba836406d0..acec163172f 100644 --- a/src/Platforms/SQLitePlatform.php +++ b/src/Platforms/SQLitePlatform.php @@ -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', @@ -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); diff --git a/src/Schema/Comparator.php b/src/Schema/Comparator.php index d349af07fcf..4c60c0770a3 100644 --- a/src/Schema/Comparator.php +++ b/src/Schema/Comparator.php @@ -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()) diff --git a/tests/Platforms/SQLitePlatformTest.php b/tests/Platforms/SQLitePlatformTest.php index d9d421c47fa..545733660a7 100644 --- a/tests/Platforms/SQLitePlatformTest.php +++ b/tests/Platforms/SQLitePlatformTest.php @@ -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 */ class SQLitePlatformTest extends AbstractPlatformTestCase { @@ -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); diff --git a/tests/Schema/AbstractComparatorTestCase.php b/tests/Schema/AbstractComparatorTestCase.php index 925f1c517f8..1202444c037 100644 --- a/tests/Schema/AbstractComparatorTestCase.php +++ b/tests/Schema/AbstractComparatorTestCase.php @@ -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); @@ -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); @@ -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), ); }