@@ -1545,6 +1545,84 @@ public function testDenormalizeObjectWithNullDisabledTypeEnforcement(): void
1545
1545
$ this ->assertInstanceOf (DtoWithNullValue::class, $ actual );
1546
1546
$ this ->assertEquals (new DtoWithNullValue (), $ actual );
1547
1547
}
1548
+
1549
+ public function testCacheKey (): void
1550
+ {
1551
+ $ relatedDummy = new RelatedDummy ();
1552
+
1553
+ $ dummy = new Dummy ();
1554
+ $ dummy ->setName ('foo ' );
1555
+ $ dummy ->setAlias ('ignored ' );
1556
+ $ dummy ->setRelatedDummy ($ relatedDummy );
1557
+ $ dummy ->relatedDummies ->add (new RelatedDummy ());
1558
+
1559
+ $ relatedDummies = new ArrayCollection ([$ relatedDummy ]);
1560
+
1561
+ $ propertyNameCollectionFactoryProphecy = $ this ->prophesize (PropertyNameCollectionFactoryInterface::class);
1562
+ $ propertyNameCollectionFactoryProphecy ->create (Dummy::class, Argument::type ('array ' ))->willReturn (new PropertyNameCollection (['name ' , 'alias ' , 'relatedDummy ' , 'relatedDummies ' ]));
1563
+
1564
+ $ relatedDummyType = new Type (Type::BUILTIN_TYPE_OBJECT , false , RelatedDummy::class);
1565
+ $ relatedDummiesType = new Type (Type::BUILTIN_TYPE_OBJECT , false , ArrayCollection::class, true , new Type (Type::BUILTIN_TYPE_INT ), $ relatedDummyType );
1566
+
1567
+ $ propertyMetadataFactoryProphecy = $ this ->prophesize (PropertyMetadataFactoryInterface::class);
1568
+ $ propertyMetadataFactoryProphecy ->create (Dummy::class, 'name ' , Argument::type ('array ' ))->willReturn ((new ApiProperty ())->withBuiltinTypes ([new Type (Type::BUILTIN_TYPE_STRING )])->withDescription ('' )->withReadable (true ));
1569
+ $ propertyMetadataFactoryProphecy ->create (Dummy::class, 'alias ' , Argument::type ('array ' ))->willReturn ((new ApiProperty ())->withBuiltinTypes ([new Type (Type::BUILTIN_TYPE_STRING )])->withDescription ('' )->withReadable (true ));
1570
+ $ propertyMetadataFactoryProphecy ->create (Dummy::class, 'relatedDummy ' , Argument::type ('array ' ))->willReturn ((new ApiProperty ())->withBuiltinTypes ([$ relatedDummyType ])->withDescription ('' )->withReadable (true )->withWritable (false )->withReadableLink (false ));
1571
+ $ propertyMetadataFactoryProphecy ->create (Dummy::class, 'relatedDummies ' , Argument::type ('array ' ))->willReturn ((new ApiProperty ())->withBuiltinTypes ([$ relatedDummiesType ])->withReadable (true )->withWritable (false )->withReadableLink (false ));
1572
+
1573
+ $ iriConverterProphecy = $ this ->prophesize (IriConverterInterface::class);
1574
+ $ iriConverterProphecy ->getIriFromResource ($ dummy , Argument::cetera ())->willReturn ('/dummies/1 ' );
1575
+ $ iriConverterProphecy ->getIriFromResource ($ relatedDummy , Argument::cetera ())->willReturn ('/dummies/2 ' );
1576
+
1577
+ $ propertyAccessorProphecy = $ this ->prophesize (PropertyAccessorInterface::class);
1578
+ $ propertyAccessorProphecy ->getValue ($ dummy , 'name ' )->willReturn ('foo ' );
1579
+ $ propertyAccessorProphecy ->getValue ($ dummy , 'relatedDummy ' )->willReturn ($ relatedDummy );
1580
+ $ propertyAccessorProphecy ->getValue ($ dummy , 'relatedDummies ' )->willReturn ($ relatedDummies );
1581
+
1582
+ $ resourceClassResolverProphecy = $ this ->prophesize (ResourceClassResolverInterface::class);
1583
+ $ resourceClassResolverProphecy ->getResourceClass (null , Dummy::class)->willReturn (Dummy::class);
1584
+ $ resourceClassResolverProphecy ->getResourceClass ($ dummy , null )->willReturn (Dummy::class);
1585
+ $ resourceClassResolverProphecy ->getResourceClass ($ relatedDummy , RelatedDummy::class)->willReturn (RelatedDummy::class);
1586
+ $ resourceClassResolverProphecy ->getResourceClass ($ relatedDummies , RelatedDummy::class)->willReturn (RelatedDummy::class);
1587
+ $ resourceClassResolverProphecy ->isResourceClass (Dummy::class)->willReturn (true );
1588
+ $ resourceClassResolverProphecy ->isResourceClass (RelatedDummy::class)->willReturn (true );
1589
+
1590
+ $ serializerProphecy = $ this ->prophesize (SerializerInterface::class);
1591
+ $ serializerProphecy ->willImplement (NormalizerInterface::class);
1592
+ $ serializerProphecy ->normalize ('foo ' , null , Argument::type ('array ' ))->willReturn ('foo ' );
1593
+ $ serializerProphecy ->normalize (['/dummies/2 ' ], null , Argument::type ('array ' ))->willReturn (['/dummies/2 ' ]);
1594
+
1595
+ $ normalizer = $ this ->getMockForAbstractClass (AbstractItemNormalizer::class, [
1596
+ $ propertyNameCollectionFactoryProphecy ->reveal (),
1597
+ $ propertyMetadataFactoryProphecy ->reveal (),
1598
+ $ iriConverterProphecy ->reveal (),
1599
+ $ resourceClassResolverProphecy ->reveal (),
1600
+ $ propertyAccessorProphecy ->reveal (),
1601
+ null ,
1602
+ null ,
1603
+ [],
1604
+ null ,
1605
+ null ,
1606
+ ]);
1607
+ $ normalizer ->setSerializer ($ serializerProphecy ->reveal ());
1608
+
1609
+ $ expected = [
1610
+ 'name ' => 'foo ' ,
1611
+ 'relatedDummy ' => '/dummies/2 ' ,
1612
+ 'relatedDummies ' => ['/dummies/2 ' ],
1613
+ ];
1614
+ $ this ->assertSame ($ expected , $ normalizer ->normalize ($ dummy , null , [
1615
+ 'resources ' => [],
1616
+ 'groups ' => ['group ' ],
1617
+ 'ignored_attributes ' => ['alias ' ],
1618
+ 'operation_name ' => 'operation_name ' ,
1619
+ 'root_operation_name ' => 'root_operation_name ' ,
1620
+ ]));
1621
+
1622
+ $ operationCacheKey = (new \ReflectionClass ($ normalizer ))->getProperty ('localFactoryOptionsCache ' )->getValue ($ normalizer );
1623
+ $ this ->assertEquals (array_keys ($ operationCacheKey ), [sprintf ('%s%s%s%s ' , Dummy::class, 'operation_name ' , 'root_operation_name ' , 'n ' )]);
1624
+ $ this ->assertEquals (current ($ operationCacheKey ), ['serializer_groups ' => ['group ' ]]);
1625
+ }
1548
1626
}
1549
1627
1550
1628
class ObjectWithBasicProperties
0 commit comments