File tree 2 files changed +13
-10
lines changed
src/Symfony/Component/Serializer
2 files changed +13
-10
lines changed Original file line number Diff line number Diff line change 24
24
class Groups
25
25
{
26
26
/**
27
- * @var array
27
+ * @var string[]
28
28
*/
29
29
private $ groups ;
30
30
@@ -39,23 +39,20 @@ public function __construct(array $data)
39
39
throw new InvalidArgumentException (sprintf ('Parameter of annotation "%s" cannot be empty. ' , get_class ($ this )));
40
40
}
41
41
42
- if (!is_array ($ data ['value ' ])) {
43
- throw new InvalidArgumentException (sprintf ('Parameter of annotation "%s" must be an array of strings. ' , get_class ($ this )));
44
- }
45
-
46
- foreach ($ data ['value ' ] as $ group ) {
42
+ $ value = (array ) $ data ['value ' ];
43
+ foreach ($ value as $ group ) {
47
44
if (!is_string ($ group )) {
48
- throw new InvalidArgumentException (sprintf ('Parameter of annotation "%s" must be an array of strings. ' , get_class ($ this )));
45
+ throw new InvalidArgumentException (sprintf ('Parameter of annotation "%s" must be a string or an array of strings. ' , get_class ($ this )));
49
46
}
50
47
}
51
48
52
- $ this ->groups = $ data [ ' value ' ] ;
49
+ $ this ->groups = $ value ;
53
50
}
54
51
55
52
/**
56
53
* Gets groups.
57
54
*
58
- * @return array
55
+ * @return string[]
59
56
*/
60
57
public function getGroups ()
61
58
{
Original file line number Diff line number Diff line change @@ -31,7 +31,7 @@ public function testEmptyGroupsParameter()
31
31
*/
32
32
public function testNotAnArrayGroupsParameter ()
33
33
{
34
- new Groups (array ('value ' => ' coopTilleuls ' ));
34
+ new Groups (array ('value ' => 12 ));
35
35
}
36
36
37
37
/**
@@ -49,4 +49,10 @@ public function testGroupsParameters()
49
49
$ groups = new Groups (array ('value ' => $ validData ));
50
50
$ this ->assertEquals ($ validData , $ groups ->getGroups ());
51
51
}
52
+
53
+ public function testSingleGroup ()
54
+ {
55
+ $ groups = new Groups (array ('value ' => 'a ' ));
56
+ $ this ->assertEquals (array ('a ' ), $ groups ->getGroups ());
57
+ }
52
58
}
You can’t perform that action at this time.
0 commit comments