Skip to content

Commit 9bafedb

Browse files
committed
Drop deprecation in TableDiff and throw exception instead
The TableDiff constructor no longer allows dropped foreign keys without names. A deprecation warning was triggered since 4.4. This patch removes the trigger and replaces it with an immediate Exception if an unnamed dropped foreign key is passed.
1 parent 0dd4797 commit 9bafedb

File tree

5 files changed

+16
-9
lines changed

5 files changed

+16
-9
lines changed

UPGRADE.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ awareness about deprecated code.
88

99
# Upgrade to 5.0
1010

11+
## BC BREAK: changes in `TableDiff` constructor
12+
13+
The `TableDiff` class constructor no longer accepts `droppedForeignKeys`
14+
without a name.
15+
1116
## BC BREAK: Changes in `Table` method return types
1217

1318
The following `Table` methods no longer return associative arrays of objects. Instead, they return lists:

src/Schema/TableDiff.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Doctrine\DBAL\Schema;
66

7+
use Doctrine\DBAL\Exception\InvalidArgumentException;
78
use Doctrine\Deprecations\Deprecation;
89

910
use function array_filter;
@@ -44,12 +45,9 @@ public function __construct(
4445
) {
4546
foreach ($droppedForeignKeys as $droppedForeignKey) {
4647
if ($droppedForeignKey->getObjectName() === null) {
47-
Deprecation::trigger(
48-
'doctrine/dbal',
49-
'https://github.com/doctrine/dbal/pull/7143',
50-
'Dropping a foreign key constraints without specifying its name is deprecated.',
48+
throw new InvalidArgumentException(
49+
'Dropping a foreign key constraints without specifying its name is not allowed.',
5150
);
52-
break;
5351
}
5452
}
5553
}

tests/Functional/Schema/SchemaManagerFunctionalTestCase.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -859,6 +859,7 @@ public function testUpdateSchemaWithForeignKeyRenaming(): void
859859
)
860860
->setForeignKeyConstraints(
861861
ForeignKeyConstraint::editor()
862+
->setUnquotedName('fk_rename_name')
862863
->setUnquotedReferencingColumnNames('fk_id')
863864
->setUnquotedReferencedTableName('test_fk_base')
864865
->setUnquotedReferencedColumnNames('id')
@@ -902,6 +903,7 @@ public function testUpdateSchemaWithForeignKeyRenaming(): void
902903
)
903904
->setForeignKeyConstraints(
904905
ForeignKeyConstraint::editor()
906+
->setUnquotedName('fk_rename_name')
905907
->setUnquotedReferencingColumnNames('rename_fk_id')
906908
->setUnquotedReferencedTableName('test_fk_base')
907909
->setUnquotedReferencedColumnNames('id')

tests/Schema/AbstractComparatorTestCase.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,7 @@ public function testTableDropForeignKey(): void
393393
)
394394
->setForeignKeyConstraints(
395395
ForeignKeyConstraint::editor()
396+
->setUnquotedName('fk_foo')
396397
->setUnquotedReferencingColumnNames('fk')
397398
->setUnquotedReferencedTableName('bar')
398399
->setUnquotedReferencedColumnNames('id')
@@ -417,6 +418,7 @@ public function testTableUpdateForeignKey(): void
417418
)
418419
->setForeignKeyConstraints(
419420
ForeignKeyConstraint::editor()
421+
->setUnquotedName('fk_foo')
420422
->setUnquotedReferencingColumnNames('fk')
421423
->setUnquotedReferencedTableName('bar')
422424
->setUnquotedReferencedColumnNames('id')
@@ -460,6 +462,7 @@ public function testMovedForeignKeyForeignTable(): void
460462
)
461463
->setForeignKeyConstraints(
462464
ForeignKeyConstraint::editor()
465+
->setUnquotedName('fk_foo')
463466
->setUnquotedReferencingColumnNames('fk')
464467
->setUnquotedReferencedTableName('bar')
465468
->setUnquotedReferencedColumnNames('id')
@@ -1116,6 +1119,7 @@ public function testForeignKeyRemovalWithRenamedLocalColumn(): void
11161119
)
11171120
->setForeignKeyConstraints(
11181121
ForeignKeyConstraint::editor()
1122+
->setUnquotedName('fk_table2')
11191123
->setUnquotedReferencingColumnNames('id_table1')
11201124
->setUnquotedReferencedTableName('table1')
11211125
->setUnquotedReferencedColumnNames('fk_table2_table1')

tests/Schema/TableDiffTest.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,16 @@
44

55
namespace Doctrine\DBAL\Tests\Schema;
66

7+
use Doctrine\DBAL\Exception\InvalidArgumentException;
78
use Doctrine\DBAL\Schema\Column;
89
use Doctrine\DBAL\Schema\ForeignKeyConstraint;
910
use Doctrine\DBAL\Schema\Table;
1011
use Doctrine\DBAL\Schema\TableDiff;
1112
use Doctrine\DBAL\Types\Types;
12-
use Doctrine\Deprecations\PHPUnit\VerifyDeprecations;
1313
use PHPUnit\Framework\TestCase;
1414

1515
class TableDiffTest extends TestCase
1616
{
17-
use VerifyDeprecations;
18-
1917
public function testCreateWithInvalidDroppedForeignKeyName(): void
2018
{
2119
$table = Table::editor()
@@ -34,7 +32,7 @@ public function testCreateWithInvalidDroppedForeignKeyName(): void
3432
->setUnquotedReferencedColumnNames('c1')
3533
->create();
3634

37-
$this->expectDeprecationWithIdentifier('https://github.com/doctrine/dbal/pull/7143');
35+
$this->expectException(InvalidArgumentException::class);
3836

3937
// @phpstan-ignore new.resultUnused
4038
new TableDiff($table, droppedForeignKeys: [$droppedForeignKeys]);

0 commit comments

Comments
 (0)