@@ -183,6 +183,60 @@ public function testCacheKeyIsFalseWhenAPropertyHasSecurity(): void
183183 $ this ->assertSame ([], $ componentsCacheRef ->getValue ($ normalizer ), 'componentsCache must not be populated when a property has security set ' );
184184 }
185185
186+ public function testUriTemplateLinkIsNotCachedAcrossObjects (): void
187+ {
188+ $ first = new Dummy ();
189+ $ first ->setId (1 );
190+ $ second = new Dummy ();
191+ $ second ->setId (2 );
192+
193+ $ propertyNameCollectionFactory = $ this ->createStub (PropertyNameCollectionFactoryInterface::class);
194+ $ propertyNameCollectionFactory ->method ('create ' )->willReturn (new PropertyNameCollection (['relatedDummy ' ]));
195+
196+ $ propertyMetadataFactory = $ this ->createStub (PropertyMetadataFactoryInterface::class);
197+ $ propertyMetadataFactory ->method ('create ' )->willReturn (
198+ (new ApiProperty ())
199+ ->withNativeType (Type ::object (RelatedDummy::class))
200+ ->withReadable (true )
201+ ->withUriTemplate ('/related_dummies/{id} ' )
202+ );
203+
204+ $ iriConverter = $ this ->createStub (IriConverterInterface::class);
205+ $ iriConverter ->method ('getIriFromResource ' )->willReturnCallback (static fn (object $ resource ): string => \sprintf ('/dummies/%d/related ' , $ resource ->getId ()));
206+
207+ $ resourceClassResolver = $ this ->createStub (ResourceClassResolverInterface::class);
208+ $ resourceClassResolver ->method ('isResourceClass ' )->willReturn (true );
209+ $ resourceClassResolver ->method ('getResourceClass ' )->willReturn (RelatedDummy::class);
210+
211+ $ propertyAccessor = $ this ->createStub (PropertyAccessorInterface::class);
212+ $ propertyAccessor ->method ('getValue ' )->willReturn (new RelatedDummy ());
213+
214+ $ resourceMetadataCollectionFactory = $ this ->createStub (ResourceMetadataCollectionFactoryInterface::class);
215+ $ resourceMetadataCollectionFactory ->method ('create ' )->willReturn (new ResourceMetadataCollection (RelatedDummy::class, [
216+ (new ApiResource ())->withOperations (new Operations ([
217+ new Get (name: '/related_dummies/{id} ' , uriTemplate: '/related_dummies/{id} ' , shortName: 'RelatedDummy ' ),
218+ ])),
219+ ]));
220+
221+ $ normalizer = new ItemNormalizer (
222+ $ propertyNameCollectionFactory ,
223+ $ propertyMetadataFactory ,
224+ $ iriConverter ,
225+ $ resourceClassResolver ,
226+ $ propertyAccessor ,
227+ new ReservedAttributeNameConverter (),
228+ null ,
229+ [],
230+ $ resourceMetadataCollectionFactory ,
231+ );
232+
233+ $ getComponents = new \ReflectionMethod (ItemNormalizer::class, 'getComponents ' );
234+ $ context = ['resource_class ' => Dummy::class, 'cache_key ' => 'shared ' , 'api_normalize ' => true ];
235+
236+ $ this ->assertSame (['relatedDummy ' => '/dummies/1/related ' ], $ getComponents ->invoke ($ normalizer , $ first , ItemNormalizer::FORMAT , $ context )['links ' ]);
237+ $ this ->assertSame (['relatedDummy ' => '/dummies/2/related ' ], $ getComponents ->invoke ($ normalizer , $ second , ItemNormalizer::FORMAT , $ context )['links ' ]);
238+ }
239+
186240 public function testNormalizeCircularReference (): void
187241 {
188242 $ circularReferenceEntity = new CircularReference ();
0 commit comments