Skip to content

Commit

Permalink
Make missing inheritance declarations a failure
Browse files Browse the repository at this point in the history
This follows up on #10431: This kind of misconfiguration triggered a deprecation warning since 2.15.x. Now let's make it an exception.
  • Loading branch information
mpdude committed Jan 27, 2023
1 parent 642a20b commit 4e041e2
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
5 changes: 5 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Upgrade to 3.0

## BC BREAK: Undeclared entity inheritance now throws a `MappingException`

As soon as an entity class inherits from another entity class, inheritance has to
be declared by adding the appropriate configuration for the root entity.

## Removed `getEntityManager()` in `Doctrine\ORM\Event\OnClearEventArgs` and `Doctrine\ORM\Event\*FlushEventArgs`

Use `getObjectManager()` instead.
Expand Down
8 changes: 1 addition & 7 deletions lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +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),
);
throw MappingException::missingInheritanceTypeDeclaration(end($nonSuperclassParents), $class->name);
}

foreach ($class->embeddedClasses as $property => $embeddableClass) {
Expand Down
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,7 +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');
$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 4e041e2

Please sign in to comment.