diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php b/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php index d36ea308464..7a7c2bc6d1a 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php @@ -31,6 +31,7 @@ use Doctrine\Persistence\Mapping\ClassMetadata as ClassMetadataInterface; use Doctrine\Persistence\Mapping\Driver\MappingDriver; use Doctrine\Persistence\Mapping\ReflectionService; +use ReflectionClass; use ReflectionException; use function assert; use function interface_exists; @@ -278,6 +279,11 @@ protected function validateRuntimeMetadata($class, $parent) if ( ! $class->discriminatorColumn) { throw MappingException::missingDiscriminatorColumn($class->name); } + foreach ($class->subClasses as $subClass) { + if ((new ReflectionClass($subClass))->name !== $subClass) { + throw MappingException::invalidClassInDiscriminatorMap($subClass, $class->name); + } + } } } else if ($class->isMappedSuperclass && $class->name == $class->rootEntityName && (count($class->discriminatorMap) || $class->discriminatorColumn)) { // second condition is necessary for mapped superclasses in the middle of an inheritance hierarchy diff --git a/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php b/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php index 3104cf58d0e..eb2388b9e52 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php @@ -38,6 +38,7 @@ use Doctrine\Tests\Models\DDC964\DDC964Admin; use Doctrine\Tests\Models\DDC964\DDC964Guest; use Doctrine\Tests\OrmTestCase; +use function class_exists; abstract class AbstractMappingDriverTest extends OrmTestCase { @@ -1087,7 +1088,7 @@ class_exists(CaseSensitiveDiscriminatorMap\Cube::class); $this->expectException(MappingException::class); $this->expectExceptionMessage('Entity class \'Doctrine\Tests\Models\CaseSensitiveDiscriminatorMap\cube\' used in the discriminator map of class \'Doctrine\Tests\Models\CaseSensitiveDiscriminatorMap\Shape\' does not exist.'); - $em = $this->_getTestEntityManager(); + $em = $this->_getTestEntityManager(); $factory = $this->createClassMetadataFactory($em); $factory->getMetadataFor(CaseSensitiveDiscriminatorMap\Shape::class); }