3333use PHPUnit \Framework \TestCase ;
3434use Prophecy \Argument ;
3535use Prophecy \PhpUnit \ProphecyTrait ;
36- use Symfony \Component \HttpFoundation \EventStreamResponse ;
3736use Symfony \Component \PropertyAccess \Exception \NoSuchPropertyException ;
3837use Symfony \Component \PropertyAccess \PropertyAccessorInterface ;
3938use Symfony \Component \PropertyInfo \Type ;
@@ -133,14 +132,16 @@ public function testNormalizeCircularReference(): void
133132 $ resourceClassResolverProphecy = $ this ->prophesize (ResourceClassResolverInterface::class);
134133 $ resourceClassResolverProphecy ->isResourceClass (CircularReference::class)->willReturn (true );
135134 $ resourceClassResolverProphecy ->getResourceClass ($ circularReferenceEntity , null )->willReturn (CircularReference::class);
136- $ resourceClassResolverProphecy ->getResourceClass ($ circularReferenceEntity , CircularReference::class)->willReturn (CircularReference::class);
137- $ resourceClassResolverProphecy ->isResourceClass (Argument::type ('string ' ))->willReturn (true );
135+ $ resourceClassResolverProphecy ->getResourceClass (null , CircularReference::class)->willReturn (CircularReference::class);
138136
139137 $ resourceMetadataCollectionFactoryProphecy = $ this ->prophesize (ResourceMetadataCollectionFactoryInterface::class);
140138 $ resourceMetadataCollectionFactoryProphecy ->create (CircularReference::class)->willReturn (new ResourceMetadataCollection ('CircularReference ' ));
141139
140+ $ propertyNameCollectionFactoryProphecy = $ this ->prophesize (PropertyNameCollectionFactoryInterface::class);
141+ $ propertyNameCollectionFactoryProphecy ->create (CircularReference::class, [])->willReturn (new PropertyNameCollection ());
142+
142143 $ normalizer = new ItemNormalizer (
143- $ this -> prophesize (PropertyNameCollectionFactoryInterface::class) ->reveal (),
144+ $ propertyNameCollectionFactoryProphecy ->reveal (),
144145 $ this ->prophesize (PropertyMetadataFactoryInterface::class)->reveal (),
145146 $ iriConverterProphecy ->reveal (),
146147 $ resourceClassResolverProphecy ->reveal (),
@@ -153,13 +154,23 @@ public function testNormalizeCircularReference(): void
153154
154155 $ normalizer ->setSerializer ($ this ->prophesize (SerializerInterface::class)->reveal ());
155156
156- // Symfony >= 7.3
157- $ splObject = class_exists (EventStreamResponse::class) ? spl_object_id ($ circularReferenceEntity ) : spl_object_hash ($ circularReferenceEntity );
158- $ context = [
159- 'circular_reference_limit ' => 2 ,
160- 'circular_reference_limit_counters ' => [$ splObject => 2 ],
161- 'cache_error ' => function (): void {},
162- ];
157+ $ circularReferenceLimit = 2 ;
158+ if (!interface_exists (AdvancedNameConverterInterface::class) && method_exists ($ normalizer , 'setCircularReferenceLimit ' )) {
159+ $ normalizer ->setCircularReferenceLimit ($ circularReferenceLimit );
160+
161+ $ context = [
162+ 'api_empty_resource_as_iri ' => true ,
163+ 'circular_reference_limit ' => [spl_object_hash ($ circularReferenceEntity ) => 2 ],
164+ 'cache_error ' => function (): void {},
165+ ];
166+ } else {
167+ $ context = [
168+ 'api_empty_resource_as_iri ' => true ,
169+ 'circular_reference_limit ' => $ circularReferenceLimit ,
170+ 'circular_reference_limit_counters ' => [spl_object_hash ($ circularReferenceEntity ) => 2 ],
171+ 'cache_error ' => function (): void {},
172+ ];
173+ }
163174
164175 $ this ->assertSame ('/circular_references/1 ' , $ normalizer ->normalize ($ circularReferenceEntity , ItemNormalizer::FORMAT , $ context ));
165176 }
@@ -282,13 +293,17 @@ public function testDenormalize(): void
282293 $ serializerProphecy ->willImplement (NormalizerInterface::class);
283294
284295 $ resourceMetadataCollectionFactory = $ this ->prophesize (ResourceMetadataCollectionFactoryInterface::class);
285- $ resourceMetadataCollectionFactory ->create (Dummy::class)->willReturn (new ResourceMetadataCollection (Dummy::class, [
286- (new ApiResource ())->withOperations (new Operations ([new Get (name: 'get ' )])),
287- ]
296+ $ resourceMetadataCollectionFactory ->create (Dummy::class)->willReturn (new ResourceMetadataCollection (
297+ Dummy::class,
298+ [
299+ (new ApiResource ())->withOperations (new Operations ([new Get (name: 'get ' )])),
300+ ]
288301 ));
289- $ resourceMetadataCollectionFactory ->create (RelatedDummy::class)->willReturn (new ResourceMetadataCollection (RelatedDummy::class, [
290- (new ApiResource ())->withOperations (new Operations ([new Get (name: 'get ' )])),
291- ]
302+ $ resourceMetadataCollectionFactory ->create (RelatedDummy::class)->willReturn (new ResourceMetadataCollection (
303+ RelatedDummy::class,
304+ [
305+ (new ApiResource ())->withOperations (new Operations ([new Get (name: 'get ' )])),
306+ ]
292307 ));
293308
294309 $ normalizer = new ItemNormalizer (
@@ -461,7 +476,8 @@ public function testDenormalizeRelationIsNotResourceLinkage(): void
461476 $ propertyMetadataFactoryProphecy = $ this ->prophesize (PropertyMetadataFactoryInterface::class);
462477 $ propertyMetadataFactoryProphecy ->create (Dummy::class, 'relatedDummy ' , [])->willReturn (
463478 (new ApiProperty ())->withBuiltinTypes ([
464- new Type (Type::BUILTIN_TYPE_OBJECT , false , RelatedDummy::class), ])->withReadable (false )->withWritable (true )->withReadableLink (false )->withWritableLink (false )
479+ new Type (Type::BUILTIN_TYPE_OBJECT , false , RelatedDummy::class),
480+ ])->withReadable (false )->withWritable (true )->withReadableLink (false )->withWritableLink (false )
465481 );
466482
467483 $ iriConverterProphecy = $ this ->prophesize (IriConverterInterface::class);
0 commit comments