@@ -758,9 +758,10 @@ public function persistUntrackedEntityWithMatchingPkUpdates(): void
758758 /** @var SplObjectStorage<object, string> $pending */
759759 $ pending = $ pendingProp ->getValue ($ mapper );
760760
761- $ this ->assertSame ('update ' , $ pending [$ replacement ]);
762- $ this ->assertFalse ($ mapper ->isTracked ($ fetched ));
763- $ this ->assertTrue ($ mapper ->isTracked ($ replacement ));
761+ $ this ->assertSame ('update ' , $ pending [$ fetched ]);
762+ $ this ->assertTrue ($ mapper ->isTracked ($ fetched ));
763+ $ this ->assertFalse ($ mapper ->isTracked ($ replacement ));
764+ $ this ->assertSame ('Updated ' , $ fetched ->title );
764765 }
765766
766767 #[Test]
@@ -791,20 +792,23 @@ public function persistReadOnlyViaCollectionPkUpdates(): void
791792
792793 // Create new readonly entity (no PK) and persist via collection[pk]
793794 $ updated = $ mapper ->entityFactory ->create (Stubs \ReadOnlyAuthor::class, name: 'Updated ' , bio: 'new bio ' );
794- $ mapper ->read_only_author [1 ]->persist ($ updated );
795+ $ merged = $ mapper ->read_only_author [1 ]->persist ($ updated );
795796
796- // PK should have been set from collection condition
797- $ this ->assertSame (1 , $ updated ->id );
797+ // Merged entity should combine both: PK from fetched, changes from updated
798+ $ this ->assertSame (1 , $ merged ->id );
799+ $ this ->assertSame ('Updated ' , $ merged ->name );
800+ $ this ->assertSame ('new bio ' , $ merged ->bio );
798801
799- // Old entity should be evicted
802+ // Merged entity should be tracked, old fetched evicted
800803 $ this ->assertFalse ($ mapper ->isTracked ($ fetched ));
801- $ this ->assertTrue ($ mapper ->isTracked ($ updated ));
804+ $ this ->assertFalse ($ mapper ->isTracked ($ updated ));
805+ $ this ->assertTrue ($ mapper ->isTracked ($ merged ));
802806
803807 $ ref = new ReflectionObject ($ mapper );
804808 $ pendingProp = $ ref ->getProperty ('pending ' );
805809 /** @var SplObjectStorage<object, string> $pending */
806810 $ pending = $ pendingProp ->getValue ($ mapper );
807- $ this ->assertSame ('update ' , $ pending [$ updated ]);
811+ $ this ->assertSame ('update ' , $ pending [$ merged ]);
808812 }
809813
810814 #[Test]
@@ -1109,12 +1113,13 @@ public function readOnlyMultipleEntitiesFetchAllTracksAll(): void
11091113
11101114 // Replace one by identity map lookup
11111115 $ updated = $ mapper ->entityFactory ->create (Stubs \Immutable \Author::class, name: 'Alice Updated ' );
1112- $ mapper ->author [1 ]->persist ($ updated );
1116+ $ merged = $ mapper ->author [1 ]->persist ($ updated );
11131117
1114- // Original Alice should be evicted, updated Alice takes its place
1118+ // Original Alice should be evicted, merged entity takes its place
11151119 $ this ->assertSame (3 , $ mapper ->trackedCount ());
1116- $ this ->assertTrue ($ mapper ->isTracked ($ updated ));
1120+ $ this ->assertTrue ($ mapper ->isTracked ($ merged ));
11171121 $ this ->assertFalse ($ mapper ->isTracked ($ authors [0 ]));
1122+ $ this ->assertSame ('Alice Updated ' , $ merged ->name );
11181123 }
11191124
11201125 #[Test]
@@ -1129,11 +1134,12 @@ public function identityMapReplaceSkipsSetWhenPkAlreadyInitialized(): void
11291134
11301135 $ updated = new Stubs \Immutable \Author (id: 1 , name: 'Bob ' );
11311136
1132- // persist via collection[1] — PK already set, should NOT try set() again
1133- $ mapper ->author [1 ]->persist ($ updated );
1137+ // persist via collection[1] — PK already set, merge produces new entity
1138+ $ merged = $ mapper ->author [1 ]->persist ($ updated );
11341139
1135- $ this ->assertSame (1 , $ updated ->id );
1136- $ this ->assertTrue ($ mapper ->isTracked ($ updated ));
1140+ $ this ->assertSame (1 , $ merged ->id );
1141+ $ this ->assertSame ('Bob ' , $ merged ->name );
1142+ $ this ->assertTrue ($ mapper ->isTracked ($ merged ));
11371143 }
11381144
11391145 #[Test]
0 commit comments