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 doctrine#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 7147b3e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 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
10 changes: 8 additions & 2 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,9 +226,14 @@ 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);
$this->cmf->getMetadataFor($childClass);
}

public function invalidHierarchyDeclarationClasses(): Generator
Expand Down

0 comments on commit 7147b3e

Please sign in to comment.