@@ -549,7 +549,7 @@ public function testDenormalizeUntypedStringObject()
549
549
$ this ->assertEquals ('' , $ actual ->value ->value );
550
550
}
551
551
552
- public function testChildContextKeepsOriginalContextCacheKey ()
552
+ public function testProvidingContextCacheKeyGeneratesSameChildContextCacheKey ()
553
553
{
554
554
$ foobar = new Dummy ();
555
555
$ foobar ->foo = new EmptyDummy ();
@@ -584,6 +584,7 @@ protected function createChildContext(array $parentContext, string $attribute, ?
584
584
};
585
585
586
586
$ serializer = new Serializer ([$ normalizer ]);
587
+
587
588
$ serializer ->normalize ($ foobar , null , ['cache_key ' => 'hardcoded ' , 'iri ' => '/dummy/1 ' ]);
588
589
$ firstChildContextCacheKey = $ normalizer ->childContextCacheKey ;
589
590
@@ -593,6 +594,46 @@ protected function createChildContext(array $parentContext, string $attribute, ?
593
594
$ this ->assertSame ($ firstChildContextCacheKey , $ secondChildContextCacheKey );
594
595
}
595
596
597
+ public function testChildContextKeepsOriginalContextCacheKey ()
598
+ {
599
+ $ foobar = new Dummy ();
600
+ $ foobar ->foo = new EmptyDummy ();
601
+ $ foobar ->bar = 'bar ' ;
602
+ $ foobar ->baz = 'baz ' ;
603
+ $ data = [
604
+ 'foo ' => [],
605
+ 'bar ' => 'bar ' ,
606
+ 'baz ' => 'baz ' ,
607
+ ];
608
+
609
+ $ normalizer = new class () extends AbstractObjectNormalizerDummy {
610
+ public $ childContextCacheKey = null ;
611
+
612
+ protected function extractAttributes (object $ object , string $ format = null , array $ context = []): array
613
+ {
614
+ return array_keys ((array ) $ object );
615
+ }
616
+
617
+ protected function getAttributeValue (object $ object , string $ attribute , string $ format = null , array $ context = [])
618
+ {
619
+ return $ object ->{$ attribute };
620
+ }
621
+
622
+ protected function createChildContext (array $ parentContext , string $ attribute , ?string $ format ): array
623
+ {
624
+ $ childContext = parent ::createChildContext ($ parentContext , $ attribute , $ format );
625
+ $ this ->childContextCacheKey = $ childContext ['cache_key ' ];
626
+
627
+ return $ childContext ;
628
+ }
629
+ };
630
+
631
+ $ serializer = new Serializer ([$ normalizer ]);
632
+ $ serializer ->normalize ($ foobar , null , ['cache_key ' => 'hardcoded ' , 'iri ' => '/dummy/1 ' ]);
633
+
634
+ $ this ->assertSame ('hardcoded-foo ' , $ normalizer ->childContextCacheKey );
635
+ }
636
+
596
637
public function testChildContextCacheKeyStaysFalseWhenOriginalCacheKeyIsFalse ()
597
638
{
598
639
$ foobar = new Dummy ();
0 commit comments