@@ -142,6 +142,65 @@ public function testGetMarkingWithSameSubjectMultipleTimes()
142142 $ this ->assertSame (['third_place ' => 1 ], $ marking3 ->getPlaces ());
143143 }
144144
145+ public function testSetMarkingWithMultipleSubjectsSharingCachedSetter ()
146+ {
147+ $ subject1 = new Subject ();
148+ $ subject2 = new Subject ();
149+ $ subject3 = new Subject ();
150+
151+ $ markingStore = new MethodMarkingStore (true );
152+
153+ // First call caches the setter for Subject class
154+ $ marking1 = $ markingStore ->getMarking ($ subject1 );
155+ $ marking1 ->mark ('place1 ' );
156+ $ markingStore ->setMarking ($ subject1 , $ marking1 , ['context1 ' => 'value1 ' ]);
157+
158+ // Subsequent calls should use the cached setter but operate on different subjects
159+ $ marking2 = $ markingStore ->getMarking ($ subject2 );
160+ $ marking2 ->mark ('place2 ' );
161+ $ markingStore ->setMarking ($ subject2 , $ marking2 , ['context2 ' => 'value2 ' ]);
162+
163+ $ marking3 = $ markingStore ->getMarking ($ subject3 );
164+ $ marking3 ->mark ('place3 ' );
165+ $ markingStore ->setMarking ($ subject3 , $ marking3 , ['context3 ' => 'value3 ' ]);
166+
167+ // Each subject should have its own marking and context
168+ $ this ->assertSame ('place1 ' , $ subject1 ->getMarking ());
169+ $ this ->assertSame (['context1 ' => 'value1 ' ], $ subject1 ->getContext ());
170+
171+ $ this ->assertSame ('place2 ' , $ subject2 ->getMarking ());
172+ $ this ->assertSame (['context2 ' => 'value2 ' ], $ subject2 ->getContext ());
173+
174+ $ this ->assertSame ('place3 ' , $ subject3 ->getMarking ());
175+ $ this ->assertSame (['context3 ' => 'value3 ' ], $ subject3 ->getContext ());
176+ }
177+
178+ public function testSetMarkingWithMultipleSubjectsSharingCachedSetterMultipleState ()
179+ {
180+ $ subject1 = new Subject ();
181+ $ subject2 = new Subject ();
182+
183+ $ markingStore = new MethodMarkingStore (false );
184+
185+ // First call caches the setter for Subject class
186+ $ marking1 = $ markingStore ->getMarking ($ subject1 );
187+ $ marking1 ->mark ('place1 ' );
188+ $ marking1 ->mark ('place2 ' );
189+ $ markingStore ->setMarking ($ subject1 , $ marking1 , ['context1 ' => 'value1 ' ]);
190+
191+ // Second call should use the cached setter but operate on a different subject
192+ $ marking2 = $ markingStore ->getMarking ($ subject2 );
193+ $ marking2 ->mark ('place3 ' );
194+ $ markingStore ->setMarking ($ subject2 , $ marking2 , ['context2 ' => 'value2 ' ]);
195+
196+ // Each subject should have its own marking and context
197+ $ this ->assertSame (['place1 ' => 1 , 'place2 ' => 1 ], $ subject1 ->getMarking ());
198+ $ this ->assertSame (['context1 ' => 'value1 ' ], $ subject1 ->getContext ());
199+
200+ $ this ->assertSame (['place3 ' => 1 ], $ subject2 ->getMarking ());
201+ $ this ->assertSame (['context2 ' => 'value2 ' ], $ subject2 ->getContext ());
202+ }
203+
145204 private function createValueObject (string $ markingValue ): object
146205 {
147206 return new class ($ markingValue ) {
0 commit comments