Skip to content
Permalink
Browse files

bug #30720 Fix getSetMethodNormalizer to correctly ignore the attribu…

…tes specified in "ignored_attributes" (Emmanuel BORGES)

This PR was merged into the 3.4 branch.

Discussion
----------

Fix getSetMethodNormalizer to correctly ignore the attributes specified in "ignored_attributes"

…ed in "ignored_attributes"

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #30453
| License       | MIT

The GetSetMethodNormalizer class correctly ignores the attributes specified in "ignored_attributes"

Commits
-------

606d8d3 Fix getSetMethodNormalizer to correctly ignore the attributes specified in "ignored_attributes"
  • Loading branch information...
fabpot committed Mar 30, 2019
2 parents cc6bfea + 606d8d3 commit e3bbf8de11eed7564f829ffd6ccc4d67d5571320
@@ -109,7 +109,7 @@ protected function extractAttributes($object, $format = null, array $context = [
$attributeName = lcfirst(substr($method->name, 0 === strpos($method->name, 'is') ? 2 : 3));
if ($this->isAllowedAttribute($object, $attributeName)) {
if ($this->isAllowedAttribute($object, $attributeName, $format, $context)) {
$attributes[] = $attributeName;
}
}
@@ -91,6 +91,23 @@ public function testDenormalize()
$this->assertTrue($obj->isBaz());
}
public function testIgnoredAttributesInContext()
{
$ignoredAttributes = ['foo', 'bar', 'baz', 'object'];
$this->normalizer->setIgnoredAttributes($ignoredAttributes);
$obj = new GetSetDummy();
$obj->setFoo('foo');
$obj->setBar('bar');
$obj->setCamelCase(true);
$this->assertEquals(
[
'fooBar' => 'foobar',
'camelCase' => true,
],
$this->normalizer->normalize($obj, 'any')
);
}
public function testDenormalizeWithObject()
{
$data = new \stdClass();

0 comments on commit e3bbf8d

Please sign in to comment.
You can’t perform that action at this time.