Skip to content

Commit

Permalink
Merge pull request #6569 from stoccc/patch-1
Browse files Browse the repository at this point in the history
Added a test case for postLoad on fetch-joined entities - fetch joined entities should have lifecycle events fired as well
  • Loading branch information
Ocramius authored Jul 21, 2017
2 parents 39572a8 + 17892bb commit fb3ec76
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions tests/Doctrine/Tests/ORM/Functional/LifecycleCallbackTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,47 @@ public function testCascadedEntitiesNotLoadedInPostLoadDuringIterationWithSimple
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()
{
Expand Down Expand Up @@ -455,6 +496,10 @@ public function doStuffOnPostLoad() {
$this->postLoadCallbackInvoked = true;
$this->postLoadEntitiesCount = count($this->entities);
}

public function getId() {
return $this->id;
}
}

/** @MappedSuperclass @HasLifecycleCallbacks */
Expand Down

0 comments on commit fb3ec76

Please sign in to comment.