From 7e2eb61deb80091bafb601d9e154080c4ac5f465 Mon Sep 17 00:00:00 2001 From: Matthias Pigulla Date: Wed, 8 Feb 2023 08:56:21 +0100 Subject: [PATCH] Make missing inheritance declarations a failure (#10463) This follows up on #10431: This kind of misconfiguration triggered a deprecation warning since 2.15.x. Now let's make it an exception. --- UPGRADE.md | 5 +++++ lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php | 8 +------- .../Tests/ORM/Mapping/BasicInheritanceMappingTest.php | 8 +++++++- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/UPGRADE.md b/UPGRADE.md index d3c054a6dae..2a13864c760 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -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. diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php b/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php index 9d79bf95a1e..96457670d5a 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php @@ -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) { diff --git a/tests/Doctrine/Tests/ORM/Mapping/BasicInheritanceMappingTest.php b/tests/Doctrine/Tests/ORM/Mapping/BasicInheritanceMappingTest.php index 18a025d1e40..f19bcdcd2bf 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/BasicInheritanceMappingTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/BasicInheritanceMappingTest.php @@ -34,6 +34,7 @@ use function assert; use function serialize; +use function sprintf; use function unserialize; class BasicInheritanceMappingTest extends OrmTestCase @@ -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); }