fixing that PropertyNormalizer supports parent properties

This commit is contained in:
Christopher Hertel 2017-11-20 17:26:54 +01:00
parent 1b6597d19c
commit a879e4f34b
2 changed files with 20 additions and 4 deletions

View File

@ -60,11 +60,13 @@ class PropertyNormalizer extends AbstractObjectNormalizer
$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;
}

View File

@ -441,6 +441,11 @@ class PropertyNormalizerTest extends TestCase
$this->assertEquals($expected, $result);
}
public function testInheritedPropertiesSupport()
{
$this->assertTrue($this->normalizer->supportsNormalization(new PropertyChildDummy()));
}
}
class PropertyDummy
@ -509,3 +514,12 @@ class StaticPropertyDummy
{
private static $property = 'value';
}
class PropertyParentDummy
{
private $foo = 'bar';
}
class PropertyChildDummy extends PropertyParentDummy
{
}