Skip to content

Commit

Permalink
bug #25053 [Serializer] Fixing PropertyNormalizer supports parent pro…
Browse files Browse the repository at this point in the history
…perties (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
  • Loading branch information
nicolas-grekas committed Nov 20, 2017
2 parents e222d85 + a879e4f commit 9619815
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
Expand Up @@ -60,11 +60,13 @@ private function supports($class)
$class = new \ReflectionClass($class);

// We look for at least one non-static property
foreach ($class->getProperties() as $property) {
if (!$property->isStatic()) {
return true;
do {
foreach ($class->getProperties() as $property) {
if (!$property->isStatic()) {
return true;
}
}
}
} while ($class = $class->getParentClass());

return false;
}
Expand Down
Expand Up @@ -441,6 +441,11 @@ public function testMaxDepth()

$this->assertEquals($expected, $result);
}

public function testInheritedPropertiesSupport()
{
$this->assertTrue($this->normalizer->supportsNormalization(new PropertyChildDummy()));
}
}

class PropertyDummy
Expand Down Expand Up @@ -509,3 +514,12 @@ class StaticPropertyDummy
{
private static $property = 'value';
}

class PropertyParentDummy
{
private $foo = 'bar';
}

class PropertyChildDummy extends PropertyParentDummy
{
}

0 comments on commit 9619815

Please sign in to comment.