Skip to content

Commit

Permalink
[GH-3519] Deprecate passing the same class with different discriminat…
Browse files Browse the repository at this point in the history
…or values.
  • Loading branch information
beberlei committed May 12, 2022
1 parent 7008778 commit 94b96c6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
11 changes: 11 additions & 0 deletions tests/Doctrine/Tests/ORM/Mapping/ClassMetadataTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -45,6 +46,8 @@

class ClassMetadataTest extends OrmTestCase
{
use VerifyDeprecations;

public function testClassMetadataInstanceSerialization(): void
{
$cm = new ClassMetadata(CMS\CmsUser::class);
Expand Down Expand Up @@ -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]);
}
}

/**
Expand Down

0 comments on commit 94b96c6

Please sign in to comment.