From d6dc8fb58a9eb876e58093f1af93656aed102287 Mon Sep 17 00:00:00 2001 From: Matthias Pigulla Date: Thu, 12 Jan 2023 11:28:00 +0000 Subject: [PATCH 1/2] Add a functional test covering #8127 --- .../ORM/Functional/Ticket/GH8127Test.php | 102 ++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 tests/Doctrine/Tests/ORM/Functional/Ticket/GH8127Test.php diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH8127Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH8127Test.php new file mode 100644 index 00000000000..a75e92df497 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH8127Test.php @@ -0,0 +1,102 @@ +createSchemaForModels( + GH8127Root::class, + GH8127Middle::class, + GH8127Leaf::class + ); + } + + /** + * @dataProvider queryClasses + */ + public function testLoadFieldsFromAllClassesInHierarchy(string $queryClass): void + { + $entity = new GH8127Leaf(); + $entity->root = 'root'; + $entity->middle = 'middle'; + $entity->leaf = 'leaf'; + + $this->_em->persist($entity); + $this->_em->flush(); + $this->_em->clear(); + + $loadedEntity = $this->_em->find(GH8127Root::class, $entity->id); + + self::assertSame('root', $loadedEntity->root); + self::assertSame('middle', $loadedEntity->middle); + self::assertSame('leaf', $loadedEntity->leaf); + } + + public function queryClasses(): array + { + return [ + 'query via root entity' => [GH8127Root::class], + 'query via leaf entity' => [GH8127Leaf::class], + ]; + } +} + +/** + * @ORM\Entity + * @ORM\Table(name="root") + * @ORM\InheritanceType("JOINED") + * @ORM\DiscriminatorMap({ "root": "GH8127Root", "middle": "GH8127Middle", "leaf": "GH8127Leaf"}) + */ +abstract class GH8127Root +{ + /** + * @ORM\Id + * @ORM\GeneratedValue(strategy="AUTO") + * @ORM\Column(type="integer") + * + * @var int + */ + public $id; + + /** + * @ORM\Column + * + * @var string + */ + public $root; +} + +/** + * @ORM\Entity + */ +abstract class GH8127Middle extends GH8127Root +{ + /** + * @ORM\Column + * + * @var string + */ + public $middle; +} + +/** + * @ORM\Entity + */ +class GH8127Leaf extends GH8127Middle +{ + /** + * @ORM\Column + * + * @var string + */ + public $leaf; +} From 4e59dc13836ad6b2720cff1fa3369642431ebb7e Mon Sep 17 00:00:00 2001 From: Matthias Pigulla Date: Thu, 12 Jan 2023 11:34:04 +0000 Subject: [PATCH 2/2] Fix PHPCS complaints --- tests/Doctrine/Tests/ORM/Functional/Ticket/GH8127Test.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH8127Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH8127Test.php index a75e92df497..8f47bd853d0 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH8127Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH8127Test.php @@ -25,10 +25,10 @@ protected function setUp(): void */ public function testLoadFieldsFromAllClassesInHierarchy(string $queryClass): void { - $entity = new GH8127Leaf(); - $entity->root = 'root'; + $entity = new GH8127Leaf(); + $entity->root = 'root'; $entity->middle = 'middle'; - $entity->leaf = 'leaf'; + $entity->leaf = 'leaf'; $this->_em->persist($entity); $this->_em->flush();