diff --git a/src/Symfony/Component/Validator/Constraints/ChoiceValidator.php b/src/Symfony/Component/Validator/Constraints/ChoiceValidator.php index 0581d7da74b6..5455b7217f1e 100644 --- a/src/Symfony/Component/Validator/Constraints/ChoiceValidator.php +++ b/src/Symfony/Component/Validator/Constraints/ChoiceValidator.php @@ -32,7 +32,7 @@ class ChoiceValidator extends ConstraintValidator */ public function validate($value, Constraint $constraint) { - if (!$constraint->choices && !$constraint->callback) { + if (!is_array($constraint->choices) && !$constraint->callback) { throw new ConstraintDefinitionException('Either "choices" or "callback" must be specified on constraint Choice'); } diff --git a/src/Symfony/Component/Validator/Tests/Constraints/ChoiceValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/ChoiceValidatorTest.php index 59b9e03f4172..f3ccd8ad5f47 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/ChoiceValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/ChoiceValidatorTest.php @@ -143,6 +143,20 @@ public function testInvalidChoice() ->assertRaised(); } + public function testInvalidChoiceEmptyChoices() + { + $constraint = new Choice(array( + 'choices' => array(), + 'message' => 'myMessage', + )); + + $this->validator->validate('baz', $constraint); + + $this->buildViolation('myMessage') + ->setParameter('{{ value }}', '"baz"') + ->assertRaised(); + } + public function testInvalidChoiceMultiple() { $constraint = new Choice(array(