diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php index 62bca42d9c7..cbd37b3433e 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php @@ -3225,6 +3225,14 @@ final public function getDiscriminatorColumn(): array */ public function setDiscriminatorMap(array $map) { + if (count(array_flip($map)) !== count($map)) { + Deprecation::trigger( + 'doctrine/orm', + 'https://github.com/doctrine/orm/issues/3519', + 'Mapping a class to multiple discriminator values is deprecated.' + ); + } + foreach ($map as $value => $className) { $this->addDiscriminatorMapClass($value, $className); } diff --git a/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataTest.php b/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataTest.php index 6776da4f85f..9c673ef4c77 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataTest.php @@ -5,6 +5,7 @@ namespace Doctrine\Tests\ORM\Mapping; use ArrayObject; +use Doctrine\Deprecations\PHPUnit\VerifyDeprecations; use Doctrine\ORM\Events; use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\ORM\Mapping\Column; @@ -45,6 +46,8 @@ class ClassMetadataTest extends OrmTestCase { + use VerifyDeprecations; + public function testClassMetadataInstanceSerialization(): void { $cm = new ClassMetadata(CMS\CmsUser::class); @@ -1366,6 +1369,14 @@ public function testInlineEmbeddable(): void self::assertTrue($classMetadata->hasField('test')); } + + public function testDiscriminatorMapWithSameClassMultipleTimesDeprecated(): void + { + $this->expectDeprecationWithIdentifier('https://github.com/doctrine/orm/issues/3519'); + + $cm = new ClassMetadata(CMS\CmsUser::class); + $cm->setDiscriminatorMap(['foo' => CMS\CmsUser::class, 'bar' => CMS\CmsUser::class]); + } } /**