diff --git a/UPGRADE.md b/UPGRADE.md index 7d49322ca8e..d80970a7056 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -4,6 +4,12 @@ That option behaves as a no-op, and is deprecated. It will be removed in 4.0. +## Deprecate properties `$indexes` and `$uniqueConstraints` of `Doctrine\ORM\Mapping\Table` + +The properties `$indexes` and `$uniqueConstraints` have been deprecated since they had no effect at all. +The preferred way of defining indices and unique constraints is by +using the `\Doctrine\ORM\Mapping\UniqueConstraint` and `\Doctrine\ORM\Mapping\Index` attributes. + # Upgrade to 3.1 ## Deprecate `Doctrine\ORM\Mapping\ReflectionEnumProperty` diff --git a/src/Mapping/Table.php b/src/Mapping/Table.php index 8a06deebc42..ac036b8bca3 100644 --- a/src/Mapping/Table.php +++ b/src/Mapping/Table.php @@ -5,6 +5,7 @@ namespace Doctrine\ORM\Mapping; use Attribute; +use Doctrine\Deprecations\Deprecation; #[Attribute(Attribute::TARGET_CLASS)] final class Table implements MappingAttribute @@ -21,5 +22,24 @@ public function __construct( public readonly array|null $uniqueConstraints = null, public readonly array $options = [], ) { + if ($this->indexes !== null) { + Deprecation::trigger( + 'doctrine/orm', + 'https://github.com/doctrine/orm/pull/11353', + 'Providing the property $indexes on %s does not have any effect and will be removed in Doctrine ORM 4.0. Please use the %s attribute instead.', + self::class, + Index::class, + ); + } + + if ($this->uniqueConstraints !== null) { + Deprecation::trigger( + 'doctrine/orm', + 'https://github.com/doctrine/orm/pull/11353', + 'Providing the property $uniqueConstraints on %s does not have any effect and will be removed in Doctrine ORM 4.0. Please use the %s attribute instead.', + self::class, + UniqueConstraint::class, + ); + } } } diff --git a/tests/Tests/ORM/Mapping/TableMappingTest.php b/tests/Tests/ORM/Mapping/TableMappingTest.php new file mode 100644 index 00000000000..24031eafa41 --- /dev/null +++ b/tests/Tests/ORM/Mapping/TableMappingTest.php @@ -0,0 +1,28 @@ +expectDeprecationWithIdentifier('https://github.com/doctrine/orm/pull/11357'); + + new Table(indexes: []); + } + + public function testDeprecationOnUniqueConstraintsPropertyIsTriggered(): void + { + $this->expectDeprecationWithIdentifier('https://github.com/doctrine/orm/pull/11357'); + + new Table(uniqueConstraints: []); + } +}