bug #14463 [Validator] Fixed Choice when an empty array is used in the "choices" option (webmozart)
This PR was merged into the 2.3 branch.
Discussion
----------
[Validator] Fixed Choice when an empty array is used in the "choices" option
| Q | A
| ------------- | ---
| Bug fix? | yes
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | #13853
| License | MIT
| Doc PR | -
This is a backport of #14448 for the 2.3 branch.
Commits
-------
8bf8556
[Validator] Fixed Choice when an empty array is used in the "choices" option
This commit is contained in:
commit
01b2d8ef96
|
@ -32,7 +32,7 @@ class ChoiceValidator extends ConstraintValidator
|
||||||
*/
|
*/
|
||||||
public function validate($value, Constraint $constraint)
|
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');
|
throw new ConstraintDefinitionException('Either "choices" or "callback" must be specified on constraint Choice');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -143,6 +143,20 @@ class ChoiceValidatorTest extends AbstractConstraintValidatorTest
|
||||||
->assertRaised();
|
->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()
|
public function testInvalidChoiceMultiple()
|
||||||
{
|
{
|
||||||
$constraint = new Choice(array(
|
$constraint = new Choice(array(
|
||||||
|
|
Reference in New Issue