8000 bug #25053 [Serializer] Fixing PropertyNormalizer supports parent pro… · symfony/symfony@9619815 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9619815

Browse files
bug #25053 [Serializer] Fixing PropertyNormalizer supports parent properties (Christopher Hertel)
This PR was merged into the 3.4 branch. Discussion ---------- [Serializer] Fixing PropertyNormalizer supports parent properties | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | n/a | License | MIT | Doc PR | n/a With 5ecafc5 support for parent properties was added to 3.4, but supports method was not updated for child classes without properties. Commits ------- a879e4f fixing that PropertyNormalizer supports parent properties
2 parents e222d85 + a879e4f commit 9619815

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

src/Symfony/Component/Serializer/Normalizer/PropertyNormalizer.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,13 @@ private function supports($class)
6060
$class = new \ReflectionClass($class);
6161

6262
// We look for at least one non-static property
63-
foreach ($class->getProperties() as $property) {
64-
if (!$property->isStatic()) {
65-
return true;
63+
do {
64+
foreach ($class->getProperties() as $property) {
65+
if (!$property->isStatic()) {
66+
return true;
67+
}
6668
}
67-
}
69+
} while ($class = $class->getParentClass());
6870

6971
return false;
7072
}

src/Symfony/Component/Serializer/Tests/Normalizer/PropertyNormalizerTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,11 @@ public function testMaxDepth()
441441

442442
$this->assertEquals($expected, $result);
443443
}
444+
445+
public function testInheritedPropertiesSupport()
446+
{
447+
$this->assertTrue($this->normalizer->supportsNormalization(new PropertyChildDummy()));
448+
}
444449
}
445450

446451
class PropertyDummy
@@ -509,3 +514,12 @@ class StaticPropertyDummy
509514
{
510515
private static $property = 'value';
511516
}
517+
518+
class PropertyParentDummy
519+
{
520+
private $foo = 'bar';
521+
}
522+
523+
class PropertyChildDummy extends PropertyParentDummy
524+
{
525+
}

0 commit comments

Comments
 (0)
0