File tree Expand file tree Collapse file tree 2 files changed +13
-10
lines changed
src/Symfony/Component/Serializer Expand file tree Collapse file tree 2 files changed +13
-10
lines changed Original file line number Diff line number Diff line change 2424class Groups
2525{
2626 /**
27- * @var array
27+ * @var string[]
2828 */
2929 private $ groups ;
3030
@@ -39,23 +39,20 @@ public function __construct(array $data)
3939 throw new InvalidArgumentException (sprintf ('Parameter of annotation "%s" cannot be empty. ' , get_class ($ this )));
4040 }
4141
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 ) {
4744 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 )));
4946 }
5047 }
5148
52- $ this ->groups = $ data [ ' value ' ] ;
49+ $ this ->groups = $ value ;
5350 }
5451
5552 /**
5653 * Gets groups.
5754 *
58- * @return array
55+ * @return string[]
5956 */
6057 public function getGroups ()
6158 {
Original file line number Diff line number Diff line change @@ -31,7 +31,7 @@ public function testEmptyGroupsParameter()
3131 */
3232 public function testNotAnArrayGroupsParameter ()
3333 {
34- new Groups (array ('value ' => ' coopTilleuls ' ));
34+ new Groups (array ('value ' => 12 ));
3535 }
3636
3737 /**
@@ -49,4 +49,10 @@ public function testGroupsParameters()
4949 $ groups = new Groups (array ('value ' => $ validData ));
5050 $ this ->assertEquals ($ validData , $ groups ->getGroups ());
5151 }
52+
53+ public function testSingleGroup ()
54+ {
55+ $ groups = new Groups (array ('value ' => 'a ' ));
56+ $ this ->assertEquals (array ('a ' ), $ groups ->getGroups ());
57+ }
5258}
You can’t perform that action at this time.
0 commit comments