Skip to content

Commit 4e041e2

Browse files
committed
Make missing inheritance declarations a failure
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.
1 parent 642a20b commit 4e041e2

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

UPGRADE.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Upgrade to 3.0
22

3+
## BC BREAK: Undeclared entity inheritance now throws a `MappingException`
4+
5+
As soon as an entity class inherits from another entity class, inheritance has to
6+
be declared by adding the appropriate configuration for the root entity.
7+
38
## Removed `getEntityManager()` in `Doctrine\ORM\Event\OnClearEventArgs` and `Doctrine\ORM\Event\*FlushEventArgs`
49

510
Use `getObjectManager()` instead.

lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -137,13 +137,7 @@ protected function doLoadMetadata(
137137

138138
if (! $class->isMappedSuperclass) {
139139
if ($rootEntityFound && $class->isInheritanceTypeNone()) {
140-
Deprecation::trigger(
141-
'doctrine/orm',
142-
'https://github.com/doctrine/orm/pull/10431',
143-
"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.",
144-
$class->name,
145-
end($nonSuperclassParents),
146-
);
140+
throw MappingException::missingInheritanceTypeDeclaration(end($nonSuperclassParents), $class->name);
147141
}
148142

149143
foreach ($class->embeddedClasses as $property => $embeddableClass) {

tests/Doctrine/Tests/ORM/Mapping/BasicInheritanceMappingTest.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434

3535
use function assert;
3636
use function serialize;
37+
use function sprintf;
3738
use function unserialize;
3839

3940
class BasicInheritanceMappingTest extends OrmTestCase
@@ -225,7 +226,12 @@ public function testMappedSuperclassIndex(): void
225226
/** @dataProvider invalidHierarchyDeclarationClasses */
226227
public function testUndeclaredHierarchyRejection(string $rootEntity, string $childClass): void
227228
{
228-
$this->expectDeprecationWithIdentifier('https://github.com/doctrine/orm/pull/10431');
229+
$this->expectException(MappingException::class);
230+
$this->expectExceptionMessage(sprintf(
231+
"Entity class '%s' is a subclass of the root entity class '%s', but no inheritance mapping type was declared.",
232+
$childClass,
233+
$rootEntity,
234+
));
229235

230236
$this->cmf->getMetadataFor($childClass);
231237
}

0 commit comments

Comments
 (0)