bug #34490 [Serializer] Fix MetadataAwareNameConverter usage with string group (antograssiot)

This PR was merged into the 4.3 branch.

Discussion
----------

[Serializer] Fix MetadataAwareNameConverter usage with string group

| Q             | A
| ------------- | ---
| Branch?       | 4.3
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #34455
| License       | MIT
| Doc PR        |

Allow to use the short syntax for serialization context group like `['groups' => 'user']`

Commits
-------

d4f749a465 [Serializer] Fix MetadataAwareNameConverter usage with string group
This commit is contained in:
Nicolas Grekas 2019-11-28 11:19:20 +01:00
commit 33731bf287
2 changed files with 3 additions and 1 deletions

View File

@ -123,7 +123,7 @@ final class MetadataAwareNameConverter implements AdvancedNameConverterInterface
if (!$groups && ($context[AbstractNormalizer::GROUPS] ?? [])) {
continue;
}
if ($groups && !array_intersect($groups, $context[AbstractNormalizer::GROUPS] ?? [])) {
if ($groups && !array_intersect($groups, (array) ($context[AbstractNormalizer::GROUPS] ?? []))) {
continue;
}

View File

@ -146,6 +146,8 @@ final class MetadataAwareNameConverterTest extends TestCase
return [
['buz', 'buz', ['groups' => ['a']]],
['buzForExport', 'buz', ['groups' => ['b']]],
['buz', 'buz', ['groups' => 'a']],
['buzForExport', 'buz', ['groups' => 'b']],
['buz', 'buz', ['groups' => ['c']]],
['buz', 'buz', []],
];