Skip to content

Commit

Permalink
Merge pull request #11357 from DaDeather/11351-add-deprecation-for-ob…
Browse files Browse the repository at this point in the history
…solete-indexes-and-unique-constraint-properties-of-table-attribute

Deprecate obsolete and unnecessary properties from Table attribute (#11351)
  • Loading branch information
greg0ire authored Mar 16, 2024
2 parents ab616f1 + 7d1444e commit cb05f1a
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
6 changes: 6 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
20 changes: 20 additions & 0 deletions src/Mapping/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Doctrine\ORM\Mapping;

use Attribute;
use Doctrine\Deprecations\Deprecation;

#[Attribute(Attribute::TARGET_CLASS)]
final class Table implements MappingAttribute
Expand All @@ -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/11357',
'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/11357',
'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,
);
}
}
}
28 changes: 28 additions & 0 deletions tests/Tests/ORM/Mapping/TableMappingTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

namespace Doctrine\Tests\ORM\Mapping;

use Doctrine\Deprecations\PHPUnit\VerifyDeprecations;
use Doctrine\ORM\Mapping\Table;
use PHPUnit\Framework\TestCase;

final class TableMappingTest extends TestCase
{
use VerifyDeprecations;

public function testDeprecationOnIndexesPropertyIsTriggered(): void
{
$this->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: []);
}
}

0 comments on commit cb05f1a

Please sign in to comment.