@@ -256,4 +256,77 @@ public function testNormalizeWithHydraOperationsMultipleApiResource(): void
256256 ];
257257 $ this ->assertEquals ($ expected , $ normalizer ->normalize ($ dummy ));
258258 }
259+
260+ public function testNormalizeWithHydraOperationsMultipleApiResourceWithOperationInDuplicate (): void
261+ {
262+ $ dummy = new Dummy ();
263+ $ dummy ->setName ('hello ' );
264+
265+ $ resourceMetadataCollectionFactoryProphecy = $ this ->prophesize (ResourceMetadataCollectionFactoryInterface::class);
266+ $ resourceMetadataCollectionFactoryProphecy ->create (Dummy::class)->willReturn (new ResourceMetadataCollection ('Dummy ' , [
267+ (new ApiResource ())
268+ ->withShortName ('Dummy ' )
269+ ->withOperations (new Operations (['get ' => (new Get ())->withShortName ('Dummy ' )])),
270+ (new ApiResource ())
271+ ->withShortName ('Dummy ' )
272+ ->withOperations (new Operations (['get ' => (new Get ())->withShortName ('Dummy ' )])),
273+ ]));
274+ $ propertyNameCollection = new PropertyNameCollection (['name ' ]);
275+ $ propertyNameCollectionFactoryProphecy = $ this ->prophesize (PropertyNameCollectionFactoryInterface::class);
276+ $ propertyNameCollectionFactoryProphecy ->create (Dummy::class, Argument::any ())->willReturn ($ propertyNameCollection );
277+
278+ $ propertyMetadata = (new ApiProperty ())->withReadable (true );
279+ $ propertyMetadataFactoryProphecy = $ this ->prophesize (PropertyMetadataFactoryInterface::class);
280+ $ propertyMetadataFactoryProphecy ->create (Dummy::class, 'name ' , Argument::type ('array ' ))->willReturn ($ propertyMetadata );
281+
282+ $ iriConverterProphecy = $ this ->prophesize (IriConverterInterface::class);
283+ $ iriConverterProphecy ->getIriFromResource ($ dummy , UrlGeneratorInterface::ABS_PATH , null , Argument::any ())->willReturn ('/dummies/1990 ' );
284+
285+ $ resourceClassResolverProphecy = $ this ->prophesize (ResourceClassResolverInterface::class);
286+ $ resourceClassResolverProphecy ->getResourceClass ($ dummy , null )->willReturn (Dummy::class);
287+ $ resourceClassResolverProphecy ->getResourceClass (null , Dummy::class)->willReturn (Dummy::class);
288+ $ resourceClassResolverProphecy ->getResourceClass ($ dummy , Dummy::class)->willReturn (Dummy::class);
289+ $ resourceClassResolverProphecy ->getResourceClass (null , Dummy::class)->willReturn (Dummy::class);
290+ $ resourceClassResolverProphecy ->isResourceClass (Dummy::class)->willReturn (true );
291+
292+ $ serializerProphecy = $ this ->prophesize (SerializerInterface::class);
293+ $ serializerProphecy ->willImplement (NormalizerInterface::class);
294+ $ serializerProphecy ->normalize ('hello ' , null , Argument::type ('array ' ))->willReturn ('hello ' );
295+ $ contextBuilderProphecy = $ this ->prophesize (ContextBuilderInterface::class);
296+ $ contextBuilderProphecy ->getResourceContextUri (Dummy::class)->willReturn ('/contexts/Dummy ' );
297+
298+ $ normalizer = new ItemNormalizer (
299+ $ resourceMetadataCollectionFactoryProphecy ->reveal (),
300+ $ propertyNameCollectionFactoryProphecy ->reveal (),
301+ $ propertyMetadataFactoryProphecy ->reveal (),
302+ $ iriConverterProphecy ->reveal (),
303+ $ resourceClassResolverProphecy ->reveal (),
304+ $ contextBuilderProphecy ->reveal (),
305+ null ,
306+ null ,
307+ null ,
308+ ['hydra_prefix ' => false , 'hydra_operations ' => true ]
309+ );
310+ $ normalizer ->setSerializer ($ serializerProphecy ->reveal ());
311+
312+ $ expected = [
313+ '@context ' => '/contexts/Dummy ' ,
314+ '@id ' => '/dummies/1990 ' ,
315+ '@type ' => 'Dummy ' ,
316+ 'operation ' => [
317+ [
318+ '@type ' => [
319+ 'Operation ' ,
320+ 'schema:FindAction ' ,
321+ ],
322+ 'description ' => 'Retrieves a Dummy resource. ' ,
323+ 'method ' => 'GET ' ,
324+ 'returns ' => 'Dummy ' ,
325+ 'title ' => 'getDummy ' ,
326+ ],
327+ ],
328+ 'name ' => 'hello ' ,
329+ ];
330+ $ this ->assertEquals ($ expected , $ normalizer ->normalize ($ dummy ));
331+ }
259332}
0 commit comments