8000 [Serializer] Allow to specify a single value in @Groups by dunglas · Pull Request #20509 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
[Serializer] Allow to specify a single value in @groups
  • Loading branch information
dunglas committed Nov 13, 2016
commit 9b6f12542340db2a40bae47ea1d24287724724de
13 changes: 5 additions & 8 deletions src/Symfony/Component/Serializer/Annotation/Groups.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
class Groups
{
/**
* @var array
* @var string[]
*/
private $groups;

Expand All @@ -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)));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this message be adapted accordingly?

}
}

$this->groups = $data['value'];
$this->groups = $value;
}

/**
* Gets groups.
*
* @return array
* @return string[]
*/
public function getGroups()
{
Expand Down
3C7E
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function testEmptyGroupsParameter()
*/
public function testNotAnArrayGroupsParameter()
{
new Groups(array('value' => 'coopTilleuls'));
new Groups(array('value' => 12));
}

/**
Expand All @@ -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());
}
}
0