Skip to content

Commit

Permalink
bug #30720 Fix getSetMethodNormalizer to correctly ignore the attribu…
Browse files Browse the repository at this point in the history
…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 e3bbf8d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
Expand Up @@ -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;
}
}
Expand Down
Expand Up @@ -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();
Expand Down

0 comments on commit e3bbf8d

Please sign in to comment.