File tree Expand file tree Collapse file tree 2 files changed +15
-1
lines changed
src/Symfony/Component/Validator Expand file tree Collapse file tree 2 files changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -32,7 +32,7 @@ class ChoiceValidator extends ConstraintValidator
32
32
*/
33
33
public function validate ($ value , Constraint $ constraint )
34
34
{
35
- if (!$ constraint ->choices && !$ constraint ->callback ) {
35
+ if (!is_array ( $ constraint ->choices ) && !$ constraint ->callback ) {
36
36
throw new ConstraintDefinitionException ('Either "choices" or "callback" must be specified on constraint Choice ' );
37
37
}
38
38
Original file line number Diff line number Diff line change @@ -143,6 +143,20 @@ public function testInvalidChoice()
143
143
->assertRaised ();
144
144
}
145
145
146
+ public function testInvalidChoiceEmptyChoices ()
147
+ {
148
+ $ constraint = new Choice (array (
149
+ 'choices ' => array (),
150
+ 'message ' => 'myMessage ' ,
151
+ ));
152
+
153
+ $ this ->validator ->validate ('baz ' , $ constraint );
154
+
155
+ $ this ->buildViolation ('myMessage ' )
156
+ ->setParameter ('{{ value }} ' , '"baz" ' )
157
+ ->assertRaised ();
158
+ }
159
+
146
160
public function testInvalidChoiceMultiple ()
147
161
{
148
162
$ constraint = new Choice (array (
You can’t perform that action at this time.
0 commit comments