@@ -328,4 +328,50 @@ private function normalizePaginator($partial = false)
328
328
'resource_class ' => 'Foo ' ,
329
329
]);
330
330
}
331
+
332
+ public function testNormalizeIriOnlyResourceCollection (): void
333
+ {
334
+ $ fooOne = new Foo ();
335
+ $ fooOne ->id = 1 ;
336
+ $ fooOne ->bar = 'baz ' ;
337
+
338
+ $ fooThree = new Foo ();
339
+ $ fooThree ->id = 3 ;
340
+ $ fooThree ->bar = 'bzz ' ;
341
+
342
+ $ data = [$ fooOne , $ fooThree ];
343
+
344
+ $ contextBuilderProphecy = $ this ->prophesize (ContextBuilderInterface::class);
345
+ $ contextBuilderProphecy ->getResourceContextUri (Foo::class)->willReturn ('/contexts/Foo ' );
346
+
347
+ $ resourceClassResolverProphecy = $ this ->prophesize (ResourceClassResolverInterface::class);
348
+ $ resourceClassResolverProphecy ->getResourceClass ($ data , Foo::class)->willReturn (Foo::class);
349
+
350
+ $ iriConverterProphecy = $ this ->prophesize (IriConverterInterface::class);
351
+ $ iriConverterProphecy ->getIriFromResourceClass (Foo::class)->willReturn ('/foos ' );
352
+ $ iriConverterProphecy ->getIriFromItem ($ fooOne )->willReturn ('/foos/1 ' );
353
+ $ iriConverterProphecy ->getIriFromItem ($ fooThree )->willReturn ('/foos/3 ' );
354
+
355
+ $ delegateNormalizerProphecy = $ this ->prophesize (NormalizerInterface::class);
356
+
357
+ $ normalizer = new CollectionNormalizer ($ contextBuilderProphecy ->reveal (), $ resourceClassResolverProphecy ->reveal (), $ iriConverterProphecy ->reveal (), [CollectionNormalizer::IRI_ONLY => true ]);
358
+ $ normalizer ->setNormalizer ($ delegateNormalizerProphecy ->reveal ());
359
+
360
+ $ actual = $ normalizer ->normalize ($ data , CollectionNormalizer::FORMAT , [
361
+ 'collection_operation_name ' => 'get ' ,
362
+ 'operation_type ' => OperationType::COLLECTION ,
363
+ 'resource_class ' => Foo::class,
364
+ ]);
365
+
366
+ $ this ->assertSame ([
367
+ '@context ' => '/contexts/Foo ' ,
368
+ '@id ' => '/foos ' ,
369
+ '@type ' => 'hydra:Collection ' ,
370
+ 'hydra:member ' => [
371
+ ['@id ' => '/foos/1 ' ],
372
+ ['@id ' => '/foos/3 ' ],
373
+ ],
374
+ 'hydra:totalItems ' => 2 ,
375
+ ], $ actual );
376
+ }
331
377
}
0 commit comments