@@ -1026,6 +1026,43 @@ public function testNormalizeObjectWithPropertyAndAccessorMethodsWithSameName()
10261026 $ this ->assertSame ('isFoo ' , $ denormalized ->isFoo ());
10271027 }
10281028
1029+ public function testNormalizeChildObjectWithPropertyAndAccessorMethodsWithSameName ()
1030+ {
1031+ // This test follows the same logic used in testNormalizeObjectWithPropertyAndAccessorMethodsWithSameName()
1032+ $ normalizer = $ this ->getNormalizerForAccessors ();
1033+
1034+ $ object = new ChildObjectWithPropertyAndAccessorSameName (
1035+ 'foo ' ,
1036+ 'getFoo ' ,
1037+ 'canFoo ' ,
1038+ 'hasFoo ' ,
1039+ 'isFoo '
1040+ );
1041+ $ normalized = $ normalizer ->normalize ($ object );
1042+
1043+ $ this ->assertSame ([
1044+ 'getFoo ' => 'getFoo ' ,
1045+ 'canFoo ' => 'canFoo ' ,
1046+ 'hasFoo ' => 'hasFoo ' ,
1047+ 'isFoo ' => 'isFoo ' ,
1048+ // The getFoo accessor method is used for foo, thus it's also 'getFoo' instead of 'foo'
1049+ 'foo ' => 'getFoo ' ,
1050+ ], $ normalized );
1051+
1052+ $ denormalized = $ this ->normalizer ->denormalize ($ normalized , ChildObjectWithPropertyAndAccessorSameName::class);
1053+
1054+ $ this ->assertSame ('getFoo ' , $ denormalized ->getFoo ());
1055+
1056+ // On the initial object the value was 'foo', but the normalizer prefers the accessor method 'getFoo'
1057+ // Thus on the denoramilzed object the value is 'getFoo'
1058+ $ this ->assertSame ('foo ' , $ object ->foo );
1059+ $ this ->assertSame ('getFoo ' , $ denormalized ->foo );
1060+
1061+ $ this ->assertSame ('hasFoo ' , $ denormalized ->hasFoo ());
1062+ $ this ->assertSame ('canFoo ' , $ denormalized ->canFoo ());
1063+ $ this ->assertSame ('isFoo ' , $ denormalized ->isFoo ());
1064+ }
1065+
10291066 /**
10301067 * Priority of accessor methods is defined by the PropertyReadInfoExtractorInterface passed to the PropertyAccessor
10311068 * component. By default ReflectionExtractor::$defaultAccessorPrefixes are used.
@@ -1501,6 +1538,10 @@ public function isFoo()
15011538 }
15021539}
15031540
1541+ class ChildObjectWithPropertyAndAccessorSameName extends ObjectWithPropertyAndAccessorSameName
1542+ {
1543+ }
1544+
15041545class ObjectWithPropertyHasserAndIsser
15051546{
15061547 public function __construct (
0 commit comments