Skip to content

Commit 31fc090

Browse files
committed
Merge branch '4.0.x' into 4.1.x
* 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"
2 parents 9cc0c0c + 0b66bc8 commit 31fc090

File tree

6 files changed

+45
-18
lines changed

6 files changed

+45
-18
lines changed

composer.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@
4040
"doctrine/coding-standard": "12.0.0",
4141
"fig/log-test": "^1",
4242
"jetbrains/phpstorm-stubs": "2023.2",
43-
"phpstan/phpstan": "1.11.1",
43+
"phpstan/phpstan": "1.11.5",
4444
"phpstan/phpstan-phpunit": "1.4.0",
4545
"phpstan/phpstan-strict-rules": "^1.6",
46-
"phpunit/phpunit": "10.5.20",
46+
"phpunit/phpunit": "10.5.21",
4747
"psalm/plugin-phpunit": "0.19.0",
4848
"slevomat/coding-standard": "8.13.1",
4949
"squizlabs/php_codesniffer": "3.9.2",

phpstan.neon.dist

+6
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,12 @@ parameters:
103103

104104
# Required for Psalm compatibility
105105
- '~^Property Doctrine\\DBAL\\Tests\\Types\\BaseDateTypeTestCase\:\:\$currentTimezone \(non-empty-string\) does not accept string\.$~'
106+
107+
# This is a rather complicated closure setup. We understand this, so PHPStan doesn't have to.
108+
-
109+
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\.$#'
110+
path: src/Portability/Converter.php
111+
106112
includes:
107113
- vendor/phpstan/phpstan-phpunit/extension.neon
108114
- vendor/phpstan/phpstan-phpunit/rules.neon

src/Platforms/SQLitePlatform.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -548,11 +548,6 @@ public function getCreateIndexSQL(Index $index, string $table): string
548548
$name = $index->getQuotedName($this);
549549
$columns = $index->getColumns();
550550

551-
if (strpos($table, '.') !== false) {
552-
[$schema, $table] = explode('.', $table);
553-
$name = $schema . '.' . $name;
554-
}
555-
556551
if (count($columns) === 0) {
557552
throw new InvalidArgumentException(sprintf(
558553
'Incomplete or invalid index definition %s on table %s',
@@ -565,6 +560,11 @@ public function getCreateIndexSQL(Index $index, string $table): string
565560
return $this->getCreatePrimaryKeySQL($index, $table);
566561
}
567562

563+
if (strpos($table, '.') !== false) {
564+
[$schema, $table] = explode('.', $table);
565+
$name = $schema . '.' . $name;
566+
}
567+
568568
$query = 'CREATE ' . $this->getCreateIndexSQLFlags($index) . 'INDEX ' . $name . ' ON ' . $table;
569569
$query .= ' (' . implode(', ', $index->getQuotedColumns($this)) . ')' . $this->getPartialIndexSQL($index);
570570

src/Schema/Comparator.php

-4
Original file line numberDiff line numberDiff line change
@@ -371,10 +371,6 @@ private function detectRenamedIndexes(array &$addedIndexes, array &$removedIndex
371371

372372
protected function diffForeignKey(ForeignKeyConstraint $key1, ForeignKeyConstraint $key2): bool
373373
{
374-
if (strtolower($key1->getName()) !== strtolower($key2->getName())) {
375-
return true;
376-
}
377-
378374
if (
379375
array_map('strtolower', $key1->getUnquotedLocalColumns())
380376
!== array_map('strtolower', $key2->getUnquotedLocalColumns())

tests/Platforms/SQLitePlatformTest.php

+29
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,15 @@
1010
use Doctrine\DBAL\Platforms\SQLitePlatform;
1111
use Doctrine\DBAL\Schema\Column;
1212
use Doctrine\DBAL\Schema\Comparator;
13+
use Doctrine\DBAL\Schema\Index;
1314
use Doctrine\DBAL\Schema\Table;
1415
use Doctrine\DBAL\Schema\TableDiff;
1516
use Doctrine\DBAL\TransactionIsolationLevel;
1617
use Doctrine\DBAL\Types\Type;
1718
use Doctrine\DBAL\Types\Types;
1819

20+
use function implode;
21+
1922
/** @extends AbstractPlatformTestCase<SQLitePlatform> */
2023
class SQLitePlatformTest extends AbstractPlatformTestCase
2124
{
@@ -176,6 +179,32 @@ public function getGenerateUniqueIndexSql(): string
176179
return 'CREATE UNIQUE INDEX index_name ON test (test, test2)';
177180
}
178181

182+
public function testGeneratesIndexCreationSqlWithSchema(): void
183+
{
184+
$indexDef = new Index('i', ['a', 'b']);
185+
186+
self::assertSame(
187+
'CREATE INDEX main.i ON mytable (a, b)',
188+
$this->platform->getCreateIndexSQL($indexDef, 'main.mytable'),
189+
);
190+
}
191+
192+
public function testGeneratesPrimaryIndexCreationSqlWithSchema(): void
193+
{
194+
$primaryIndexDef = new Index('i2', ['a', 'b'], false, true);
195+
196+
self::assertSame(
197+
'TEST: main.mytable, i2 - a, b',
198+
(new class () extends SqlitePlatform {
199+
public function getCreatePrimaryKeySQL(Index $index, string $table): string
200+
{
201+
return 'TEST: ' . $table . ', ' . $index->getName()
202+
. ' - ' . implode(', ', $index->getColumns());
203+
}
204+
})->getCreateIndexSQL($primaryIndexDef, 'main.mytable'),
205+
);
206+
}
207+
179208
public function testGeneratesForeignKeyCreationSql(): void
180209
{
181210
$this->expectException(Exception::class);

tests/Schema/AbstractComparatorTestCase.php

+3-7
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ public function testCompareColumnCompareCaseInsensitive(): void
345345
self::assertTrue($tableDiff->isEmpty());
346346
}
347347

348-
public function testDetectIndexNameChange(): void
348+
public function testCompareIndexBasedOnPropertiesNotName(): void
349349
{
350350
$tableA = new Table('foo');
351351
$tableA->addColumn('id', Types::INTEGER);
@@ -363,7 +363,7 @@ public function testDetectIndexNameChange(): void
363363
);
364364
}
365365

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

376376
self::assertEquals(
377-
new TableDiff($tableA, [], [], [], [], [], [], [], [], [
378-
new ForeignKeyConstraint(['id'], 'bar', ['id'], 'bar_constraint'),
379-
], [], [
380-
new ForeignKeyConstraint(['id'], 'bar', ['id'], 'foo_constraint'),
381-
]),
377+
new TableDiff($tableA, [], [], [], [], [], [], [], [], [], [], []),
382378
$this->comparator->compareTables($tableA, $tableB),
383379
);
384380
}

0 commit comments

Comments
 (0)