diff --git a/src/Symfony/Component/Serializer/Annotation/Groups.php b/src/Symfony/Component/Serializer/Annotation/Groups.php index 519837a55b73e..b67239bc6f219 100644 --- a/src/Symfony/Component/Serializer/Annotation/Groups.php +++ b/src/Symfony/Component/Serializer/Annotation/Groups.php @@ -24,7 +24,7 @@ class Groups { /** - * @var array + * @var string[] */ private $groups; @@ -39,23 +39,20 @@ public function __construct(array $data) throw new InvalidArgumentException(sprintf('Parameter of annotation "%s" cannot be empty.', get_class($this))); } - if (!is_array($data['value'])) { - throw new InvalidArgumentException(sprintf('Parameter of annotation "%s" must be an array of strings.', get_class($this))); - } - - foreach ($data['value'] as $group) { + $value = (array) $data['value']; + foreach ($value as $group) { if (!is_string($group)) { - throw new InvalidArgumentException(sprintf('Parameter of annotation "%s" must be an array of strings.', get_class($this))); + throw new InvalidArgumentException(sprintf('Parameter of annotation "%s" must be a string or an array of strings.', get_class($this))); } } - $this->groups = $data['value']; + $this->groups = $value; } /** * Gets groups. * - * @return array + * @return string[] */ public function getGroups() { diff --git a/src/Symfony/Component/Serializer/Tests/Annotation/GroupsTest.php b/src/Symfony/Component/Serializer/Tests/Annotation/GroupsTest.php index 72b877729dc83..8228cc5c98671 100644 --- a/src/Symfony/Component/Serializer/Tests/Annotation/GroupsTest.php +++ b/src/Symfony/Component/Serializer/Tests/Annotation/GroupsTest.php @@ -31,7 +31,7 @@ public function testEmptyGroupsParameter() */ public function testNotAnArrayGroupsParameter() { - new Groups(array('value' => 'coopTilleuls')); + new Groups(array('value' => 12)); } /** @@ -49,4 +49,10 @@ public function testGroupsParameters() $groups = new Groups(array('value' => $validData)); $this->assertEquals($validData, $groups->getGroups()); } + + public function testSingleGroup() + { + $groups = new Groups(array('value' => 'a')); + $this->assertEquals(array('a'), $groups->getGroups()); + } }