[Validator] Fixed Choice when an empty array is used in the "choices" option
This commit is contained in:
parent
520660302a
commit
8bf855620f
|
@ -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');
|
||||
}
|
||||
|
||||
|
|
|
@ -143,6 +143,20 @@ class ChoiceValidatorTest extends AbstractConstraintValidatorTest
|
|||
->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(
|
||||
|
|
Reference in New Issue