1
0
mirror of synced 2025-02-02 21:41:45 +03:00

Merge pull request #6569 from stoccc/patch-1

Added a test case for postLoad on fetch-joined entities - fetch joined entities should have lifecycle events fired as well
This commit is contained in:
Marco Pivetta 2017-07-21 18:30:38 +02:00 committed by GitHub
commit fb3ec7648d

View File

@ -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 = :entA_id
DQL;
$fetchedA = $this
->_em
->createQuery($dql)->setParameter('entA_id', $entA->getId())
->getOneOrNullResult();
$this->assertTrue($fetchedA->postLoadCallbackInvoked);
foreach ($fetchedA->entities as $fetchJoinedEntB) {
$this->assertTrue($fetchJoinedEntB->postLoadCallbackInvoked);
}
}
public function testLifecycleCallbacksGetInherited()
{
@ -455,6 +496,10 @@ class LifecycleCallbackCascader
$this->postLoadCallbackInvoked = true;
$this->postLoadEntitiesCount = count($this->entities);
}
public function getId() {
return $this->id;
}
}
/** @MappedSuperclass @HasLifecycleCallbacks */