Skip to content

Commit

Permalink
Ensures discriminator map is case sensitive
Browse files Browse the repository at this point in the history
  • Loading branch information
gquemener committed May 15, 2020
1 parent a758d75 commit 2daee11
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
6 changes: 6 additions & 0 deletions lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit 2daee11

Please sign in to comment.