Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch '2.8'

* 2.8:
  [Debug] Fix deprecated use of DebugClassLoader
  Revert "[HttpKernel] Throw a LogicException when kernel.exception does not led to a Response"
  [Validator] Fixed Choice when an empty array is used in the "choices" option
  • Loading branch information...
commit 3b5d00817f6a0d6c6eaf3438534242e4df79958b 2 parents db53966 + c29cda6
@nicolas-grekas nicolas-grekas authored
View
2  Constraints/ChoiceValidator.php
@@ -37,7 +37,7 @@ public function validate($value, Constraint $constraint)
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Choice');
}
- 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');
}
View
17 Tests/Constraints/ChoiceValidatorTest.php
@@ -150,6 +150,23 @@ public function testInvalidChoice()
->assertRaised();
}
+ public function testInvalidChoiceEmptyChoices()
+ {
+ $constraint = new Choice(array(
+ // May happen when the choices are provided dynamically, e.g. from
+ // the DB or the model
+ 'choices' => array(),
+ 'message' => 'myMessage',
+ ));
+
+ $this->validator->validate('baz', $constraint);
+
+ $this->buildViolation('myMessage')
+ ->setParameter('{{ value }}', '"baz"')
+ ->setCode(Choice::NO_SUCH_CHOICE_ERROR)
+ ->assertRaised();
+ }
+
public function testInvalidChoiceMultiple()
{
$constraint = new Choice(array(
Please sign in to comment.
Something went wrong with that request. Please try again.