Skip to content

Commit 8549925

Browse files
committed
Merge branch '4.4.x' into 5.0.x
2 parents f3d92b2 + 15c1c0a commit 8549925

File tree

5 files changed

+41
-15
lines changed

5 files changed

+41
-15
lines changed

UPGRADE.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,11 @@ all drivers and middleware.
404404

405405
# Upgrade to 4.4
406406

407+
## Deprecated `TableDiff::getDroppedForeignKeys()`
408+
409+
The `TableDiff::getDroppedForeignKeys()` method has been deprecated. Use
410+
`TableDiff::getDroppedForeignKeyConstraintNames()` instead.
411+
407412
## Deprecated `AbstractSchemaManager` methods
408413

409414
The following `AbstractSchemaManager` methods have been deprecated:

src/Schema/Exception/InvalidState.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,8 @@
99

1010
final class InvalidState extends LogicException implements SchemaException
1111
{
12+
public static function tableDiffContainsUnnamedDroppedForeignKeyConstraints(): self
13+
{
14+
return new self('Table diff contains unnamed dropped foreign key constraints');
15+
}
1216
}

src/Schema/TableDiff.php

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
namespace Doctrine\DBAL\Schema;
66

77
use Doctrine\DBAL\Exception\InvalidArgumentException;
8+
use Doctrine\DBAL\Schema\Exception\InvalidState;
9+
use Doctrine\DBAL\Schema\Name\UnqualifiedName;
810
use Doctrine\Deprecations\Deprecation;
911

1012
use function array_filter;
@@ -177,12 +179,33 @@ public function getAddedForeignKeys(): array
177179
return $this->addedForeignKeys;
178180
}
179181

180-
/** @return array<ForeignKeyConstraint> */
182+
/**
183+
* @deprecated Use {@see getDroppedForeignKeyConstraintNames()}.
184+
*
185+
* @return array<ForeignKeyConstraint>
186+
*/
181187
public function getDroppedForeignKeys(): array
182188
{
183189
return $this->droppedForeignKeys;
184190
}
185191

192+
/** @return array<UnqualifiedName> */
193+
public function getDroppedForeignKeyConstraintNames(): array
194+
{
195+
$names = [];
196+
foreach ($this->droppedForeignKeys as $constraint) {
197+
$name = $constraint->getObjectName();
198+
199+
if ($name === null) {
200+
throw InvalidState::tableDiffContainsUnnamedDroppedForeignKeyConstraints();
201+
}
202+
203+
$names[] = $name;
204+
}
205+
206+
return $names;
207+
}
208+
186209
public function getAddedPrimaryKeyConstraint(): ?PrimaryKeyConstraint
187210
{
188211
return $this->addedPrimaryKeyConstraint;

tests/Schema/AbstractComparatorTestCase.php

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -363,16 +363,6 @@ public function testTableAddForeignKey(): void
363363

364364
public function testTableDropForeignKey(): void
365365
{
366-
$tableForeign = Table::editor()
367-
->setUnquotedName('bar')
368-
->setColumns(
369-
Column::editor()
370-
->setUnquotedName('id')
371-
->setTypeName(Types::INTEGER)
372-
->create(),
373-
)
374-
->create();
375-
376366
$table1 = Table::editor()
377367
->setUnquotedName('foo')
378368
->setColumns(
@@ -403,7 +393,7 @@ public function testTableDropForeignKey(): void
403393

404394
$tableDiff = $this->comparator->compareTables($table2, $table1);
405395

406-
self::assertCount(1, $tableDiff->getDroppedForeignKeys());
396+
self::assertCount(1, $tableDiff->getDroppedForeignKeyConstraintNames());
407397
}
408398

409399
public function testTableUpdateForeignKey(): void
@@ -446,7 +436,7 @@ public function testTableUpdateForeignKey(): void
446436

447437
$tableDiff = $this->comparator->compareTables($table1, $table2);
448438

449-
self::assertCount(1, $tableDiff->getDroppedForeignKeys());
439+
self::assertCount(1, $tableDiff->getDroppedForeignKeyConstraintNames());
450440
self::assertCount(1, $tableDiff->getAddedForeignKeys());
451441
}
452442

@@ -489,7 +479,7 @@ public function testMovedForeignKeyForeignTable(): void
489479

490480
$tableDiff = $this->comparator->compareTables($table1, $table2);
491481

492-
self::assertCount(1, $tableDiff->getDroppedForeignKeys());
482+
self::assertCount(1, $tableDiff->getDroppedForeignKeyConstraintNames());
493483
self::assertCount(1, $tableDiff->getAddedForeignKeys());
494484
}
495485

tests/Schema/TableDiffTest.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use Doctrine\DBAL\Exception\InvalidArgumentException;
88
use Doctrine\DBAL\Schema\Column;
9+
use Doctrine\DBAL\Schema\Exception\InvalidState;
910
use Doctrine\DBAL\Schema\ForeignKeyConstraint;
1011
use Doctrine\DBAL\Schema\Table;
1112
use Doctrine\DBAL\Schema\TableDiff;
@@ -35,6 +36,9 @@ public function testCreateWithInvalidDroppedForeignKeyName(): void
3536
$this->expectException(InvalidArgumentException::class);
3637

3738
// @phpstan-ignore new.resultUnused
38-
new TableDiff($table, droppedForeignKeys: [$droppedForeignKeys]);
39+
$diff = new TableDiff($table, droppedForeignKeys: [$droppedForeignKeys]);
40+
41+
$this->expectException(InvalidState::class);
42+
$diff->getDroppedForeignKeyConstraintNames();
3943
}
4044
}

0 commit comments

Comments
 (0)