Skip to content

Commit

Permalink
Make missing inheritance declarations a failure in 3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mpdude committed Jan 26, 2023
1 parent 4d8cf26 commit ac4ac75
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 18 deletions.
10 changes: 1 addition & 9 deletions lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,15 +137,7 @@ protected function doLoadMetadata(

if (! $class->isMappedSuperclass) {
if ($rootEntityFound && $class->isInheritanceTypeNone()) {
Deprecation::trigger(
'doctrine/orm',
'https://github.com/doctrine/orm/pull/10431',
"Entity class '%s' is a subclass of the root entity class '%s', but no inheritance mapping type was declared. This is a misconfiguration and will be an error in Doctrine ORM 3.0.",
$class->name,
end($nonSuperclassParents),
);
// enable this in 3.0
// throw MappingException::missingInheritanceTypeDeclaration(end($nonSuperclassParents), $class->name);
throw MappingException::missingInheritanceTypeDeclaration(end($nonSuperclassParents), $class->name);
}

foreach ($class->embeddedClasses as $property => $embeddableClass) {
Expand Down
16 changes: 7 additions & 9 deletions tests/Doctrine/Tests/ORM/Mapping/BasicInheritanceMappingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

use function assert;
use function serialize;
use function sprintf;
use function unserialize;

class BasicInheritanceMappingTest extends OrmTestCase
Expand Down Expand Up @@ -225,15 +226,12 @@ public function testMappedSuperclassIndex(): void
/** @dataProvider invalidHierarchyDeclarationClasses */
public function testUndeclaredHierarchyRejection(string $rootEntity, string $childClass): void
{
$this->expectDeprecationWithIdentifier('https://github.com/doctrine/orm/pull/10431');

/* on 3.0, use this instead: */
// self::expectException(MappingException::class);
// self::expectExceptionMessage(\sprintf(
// "Entity class '%s' is a subclass of the root entity class '%s', but no inheritance mapping type was declared.",
// $childClass,
// $rootEntity
// ));
$this->expectException(MappingException::class);
$this->expectExceptionMessage(sprintf(
"Entity class '%s' is a subclass of the root entity class '%s', but no inheritance mapping type was declared.",
$childClass,
$rootEntity,
));

$this->cmf->getMetadataFor($childClass);
}
Expand Down

0 comments on commit ac4ac75

Please sign in to comment.