From c47cf1de34736738040978c7fab38624d9894398 Mon Sep 17 00:00:00 2001 From: stoccc Date: Fri, 21 Jul 2017 10:33:28 +0200 Subject: [PATCH 1/2] Added a test case for postLoad on fetch-joined entities see https://github.com/doctrine/doctrine2/issues/6568 --- .../ORM/Functional/LifecycleCallbackTest.php | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/tests/Doctrine/Tests/ORM/Functional/LifecycleCallbackTest.php b/tests/Doctrine/Tests/ORM/Functional/LifecycleCallbackTest.php index ca7f8c7d7..83836c662 100644 --- a/tests/Doctrine/Tests/ORM/Functional/LifecycleCallbackTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/LifecycleCallbackTest.php @@ -268,6 +268,47 @@ DQL; break; } } + + /** + * https://github.com/doctrine/doctrine2/issues/6568 + */ + public function testPostLoadIsInvokedOnFetchJoinedEntities() + { + $entA = new LifecycleCallbackCascader(); + $this->_em->persist($entA); + + $entB_1 = new LifecycleCallbackTestEntity(); + $entB_2 = new LifecycleCallbackTestEntity(); + + $entA->entities[] = $entB_1; + $entA->entities[] = $entB_2; + $entB_1->cascader = $entA; + $entB_2->cascader = $entA; + + $this->_em->flush(); + $this->_em->clear(); + + $dql = <<<'DQL' +SELECT + entA, entB +FROM + Doctrine\Tests\ORM\Functional\LifecycleCallbackCascader AS entA +LEFT JOIN + entA.entities AS entB +WHERE + entA.id = %s +DQL; + + $fetchedA = $this + ->_em + ->createQuery(sprintf($dql, $entA->getId())) + ->getOneOrNullResult(); + + $this->assertTrue($fetchedA->postLoadCallbackInvoked); + foreach ($fetchedA->entities as $fetchJoinedEntB) { + $this->assertTrue($fetchJoinedEntB->postLoadCallbackInvoked); + } + } public function testLifecycleCallbacksGetInherited() { From 17892bb32782f8901da3b636ca92681ef37b71b6 Mon Sep 17 00:00:00 2001 From: stoccc Date: Fri, 21 Jul 2017 10:47:32 +0200 Subject: [PATCH 2/2] added named parameter and LifecycleCallbackCascader::getId() --- .../Tests/ORM/Functional/LifecycleCallbackTest.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Functional/LifecycleCallbackTest.php b/tests/Doctrine/Tests/ORM/Functional/LifecycleCallbackTest.php index 83836c662..914acbecf 100644 --- a/tests/Doctrine/Tests/ORM/Functional/LifecycleCallbackTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/LifecycleCallbackTest.php @@ -296,12 +296,12 @@ FROM LEFT JOIN entA.entities AS entB WHERE - entA.id = %s + entA.id = :entA_id DQL; $fetchedA = $this ->_em - ->createQuery(sprintf($dql, $entA->getId())) + ->createQuery($dql)->setParameter('entA_id', $entA->getId()) ->getOneOrNullResult(); $this->assertTrue($fetchedA->postLoadCallbackInvoked); @@ -496,6 +496,10 @@ class LifecycleCallbackCascader $this->postLoadCallbackInvoked = true; $this->postLoadEntitiesCount = count($this->entities); } + + public function getId() { + return $this->id; + } } /** @MappedSuperclass @HasLifecycleCallbacks */