@@ -66,10 +66,11 @@ public function testPreSavePostSaveCallbacksAreInvoked(): void
6666 self ::assertTrue ($ entity ->postPersistCallbackInvoked );
6767
6868 $ this ->_em ->clear ();
69+ LifecycleCallbackTestEntity::$ postLoadCallbackInvoked = false ; // Reset the tracking of the postLoad invocation
6970
7071 $ query = $ this ->_em ->createQuery ('select e from Doctrine\Tests\ORM\Functional\LifecycleCallbackTestEntity e ' );
7172 $ result = $ query ->getResult ();
72- self ::assertTrue ($ result [0 ]-> postLoadCallbackInvoked );
73+ self ::assertTrue ($ result [0 ]:: $ postLoadCallbackInvoked );
7374
7475 $ result [0 ]->value = 'hello again ' ;
7576
@@ -130,12 +131,14 @@ public function testGetReferenceWithPostLoadEventIsDelayedUntilProxyTrigger(): v
130131 $ id = $ entity ->getId ();
131132
132133 $ this ->_em ->clear ();
134+ LifecycleCallbackTestEntity::$ postLoadCallbackInvoked = false ; // Reset the tracking of the postLoad invocation
133135
134136 $ reference = $ this ->_em ->getReference (LifecycleCallbackTestEntity::class, $ id );
135- self ::assertFalse ($ reference ->postLoadCallbackInvoked );
137+ self ::assertFalse ($ reference ::$ postLoadCallbackInvoked );
138+ $ this ->assertTrue ($ this ->isUninitializedObject ($ reference ));
136139
137140 $ reference ->getValue (); // trigger proxy load
138- self ::assertTrue ($ reference-> postLoadCallbackInvoked );
141+ self ::assertTrue ($ reference:: $ postLoadCallbackInvoked );
139142 }
140143
141144 /** @group DDC-958 */
@@ -148,13 +151,14 @@ public function testPostLoadTriggeredOnRefresh(): void
148151 $ id = $ entity ->getId ();
149152
150153 $ this ->_em ->clear ();
154+ LifecycleCallbackTestEntity::$ postLoadCallbackInvoked = false ; // Reset the tracking of the postLoad invocation
151155
152156 $ reference = $ this ->_em ->find (LifecycleCallbackTestEntity::class, $ id );
153- self ::assertTrue ($ reference-> postLoadCallbackInvoked );
154- $ reference-> postLoadCallbackInvoked = false ;
157+ self ::assertTrue ($ reference:: $ postLoadCallbackInvoked );
158+ $ reference:: $ postLoadCallbackInvoked = false ;
155159
156160 $ this ->_em ->refresh ($ reference );
157- self ::assertTrue ($ reference-> postLoadCallbackInvoked , 'postLoad should be invoked when refresh() is called. ' );
161+ self ::assertTrue ($ reference:: $ postLoadCallbackInvoked , 'postLoad should be invoked when refresh() is called. ' );
158162 }
159163
160164 /** @group DDC-113 */
@@ -197,6 +201,7 @@ public function testCascadedEntitiesLoadedInPostLoad(): void
197201
198202 $ this ->_em ->flush ();
199203 $ this ->_em ->clear ();
204+ LifecycleCallbackTestEntity::$ postLoadCallbackInvoked = false ; // Reset the tracking of the postLoad invocation
200205
201206 $ dql = <<<'DQL'
202207SELECT
@@ -214,9 +219,9 @@ public function testCascadedEntitiesLoadedInPostLoad(): void
214219 ->createQuery (sprintf ($ dql , $ e1 ->getId (), $ e2 ->getId ()))
215220 ->getResult ();
216221
217- self ::assertTrue (current ($ entities )-> postLoadCallbackInvoked );
222+ self ::assertTrue (current ($ entities ):: $ postLoadCallbackInvoked );
218223 self ::assertTrue (current ($ entities )->postLoadCascaderNotNull );
219- self ::assertTrue (current ($ entities )->cascader -> postLoadCallbackInvoked );
224+ self ::assertTrue (current ($ entities )->cascader :: $ postLoadCallbackInvoked );
220225 self ::assertEquals (current ($ entities )->cascader ->postLoadEntitiesCount , 2 );
221226 }
222227
@@ -239,6 +244,8 @@ public function testCascadedEntitiesNotLoadedInPostLoadDuringIteration(): void
239244
240245 $ this ->_em ->flush ();
241246 $ this ->_em ->clear ();
247+ LifecycleCallbackTestEntity::$ postLoadCallbackInvoked = false ; // Reset the tracking of the postLoad invocation
248+ LifecycleCallbackCascader::$ postLoadCallbackInvoked = false ;
242249
243250 $ dql = <<<'DQL'
244251SELECT
@@ -256,7 +263,7 @@ public function testCascadedEntitiesNotLoadedInPostLoadDuringIteration(): void
256263 $ result = iterator_to_array ($ query ->iterate ());
257264
258265 foreach ($ result as $ entity ) {
259- self ::assertTrue ($ entity [0 ]-> postLoadCallbackInvoked );
266+ self ::assertTrue ($ entity [0 ]:: $ postLoadCallbackInvoked );
260267 self ::assertFalse ($ entity [0 ]->postLoadCascaderNotNull );
261268
262269 break ;
@@ -265,7 +272,7 @@ public function testCascadedEntitiesNotLoadedInPostLoadDuringIteration(): void
265272 $ iterableResult = iterator_to_array ($ query ->toIterable ());
266273
267274 foreach ($ iterableResult as $ entity ) {
268- self ::assertTrue ($ entity-> postLoadCallbackInvoked );
275+ self ::assertTrue ($ entity:: $ postLoadCallbackInvoked );
269276 self ::assertFalse ($ entity ->postLoadCascaderNotNull );
270277
271278 break ;
@@ -283,6 +290,7 @@ public function testCascadedEntitiesNotLoadedInPostLoadDuringIterationWithSimple
283290
284291 $ this ->_em ->flush ();
285292 $ this ->_em ->clear ();
293+ LifecycleCallbackTestEntity::$ postLoadCallbackInvoked = false ; // Reset the tracking of the postLoad invocation
286294
287295 $ query = $ this ->_em ->createQuery (
288296 'SELECT e FROM Doctrine\Tests\ORM\Functional\LifecycleCallbackTestEntity AS e '
@@ -291,7 +299,7 @@ public function testCascadedEntitiesNotLoadedInPostLoadDuringIterationWithSimple
291299 $ result = iterator_to_array ($ query ->iterate (null , Query::HYDRATE_SIMPLEOBJECT ));
292300
293301 foreach ($ result as $ entity ) {
294- self ::assertTrue ($ entity [0 ]-> postLoadCallbackInvoked );
302+ self ::assertTrue ($ entity [0 ]:: $ postLoadCallbackInvoked );
295303 self ::assertFalse ($ entity [0 ]->postLoadCascaderNotNull );
296304
297305 break ;
@@ -300,7 +308,7 @@ public function testCascadedEntitiesNotLoadedInPostLoadDuringIterationWithSimple
300308 $ result = iterator_to_array ($ query ->toIterable ([], Query::HYDRATE_SIMPLEOBJECT ));
301309
302310 foreach ($ result as $ entity ) {
303- self ::assertTrue ($ entity-> postLoadCallbackInvoked );
311+ self ::assertTrue ($ entity:: $ postLoadCallbackInvoked );
304312 self ::assertFalse ($ entity ->postLoadCascaderNotNull );
305313
306314 break ;
@@ -325,6 +333,8 @@ public function testPostLoadIsInvokedOnFetchJoinedEntities(): void
325333
326334 $ this ->_em ->flush ();
327335 $ this ->_em ->clear ();
336+ LifecycleCallbackTestEntity::$ postLoadCallbackInvoked = false ; // Reset the tracking of the postLoad invocation
337+ LifecycleCallbackCascader::$ postLoadCallbackInvoked = false ;
328338
329339 $ dql = <<<'DQL'
330340SELECT
@@ -342,9 +352,9 @@ public function testPostLoadIsInvokedOnFetchJoinedEntities(): void
342352 ->createQuery ($ dql )->setParameter ('entA_id ' , $ entA ->getId ())
343353 ->getOneOrNullResult ();
344354
345- self ::assertTrue ($ fetchedA-> postLoadCallbackInvoked );
355+ self ::assertTrue ($ fetchedA:: $ postLoadCallbackInvoked );
346356 foreach ($ fetchedA ->entities as $ fetchJoinedEntB ) {
347- self ::assertTrue ($ fetchJoinedEntB-> postLoadCallbackInvoked );
357+ self ::assertTrue ($ fetchJoinedEntB:: $ postLoadCallbackInvoked );
348358 }
349359 }
350360
@@ -492,7 +502,7 @@ class LifecycleCallbackTestEntity
492502 public $ postPersistCallbackInvoked = false ;
493503
494504 /** @var bool */
495- public $ postLoadCallbackInvoked = false ;
505+ public static $ postLoadCallbackInvoked = false ;
496506
497507 /** @var bool */
498508 public $ postLoadCascaderNotNull = false ;
@@ -546,7 +556,7 @@ public function doStuffOnPostPersist(): void
546556 /** @PostLoad */
547557 public function doStuffOnPostLoad (): void
548558 {
549- $ this -> postLoadCallbackInvoked = true ;
559+ self :: $ postLoadCallbackInvoked = true ;
550560 $ this ->postLoadCascaderNotNull = isset ($ this ->cascader );
551561 }
552562
@@ -572,7 +582,7 @@ class LifecycleCallbackCascader
572582{
573583 /* test stuff */
574584 /** @var bool */
575- public $ postLoadCallbackInvoked = false ;
585+ public static $ postLoadCallbackInvoked = false ;
576586
577587 /** @var int */
578588 public $ postLoadEntitiesCount = 0 ;
@@ -599,7 +609,7 @@ public function __construct()
599609 /** @PostLoad */
600610 public function doStuffOnPostLoad (): void
601611 {
602- $ this -> postLoadCallbackInvoked = true ;
612+ self :: $ postLoadCallbackInvoked = true ;
603613 $ this ->postLoadEntitiesCount = count ($ this ->entities );
604614 }
605615
0 commit comments