vendredi 24 octobre 2014

Symfony validation to validate a simple value does not work with LessThan constraint


Vote count:

0




it seems impossible to validate a simple value with the Symfony\Component\Validator\Constraints\LessThan constraint.


Here is a simple test:



$lessConstraint = new LessThan();
$lessConstraint->value = 5;
$errors[] = $this->get('validator')->validateValue('This must fail.', $lessConstraint);
var_dump($errors);


I was expecting a constraint violation as the tested string is longer than 5 characters. But, the result is an empty ConstraintViolationList list:



array(1) { [0]=> object(Symfony\Component\Validator\ConstraintViolationList)#517 (1) { ["violations":"Symfony\Component\Validator\ConstraintViolationList":private]=> array(0) { } } }


Same problem with the Symfony\Component\Validator\Constraints\LessThanOrEqual constraint. However, as shown in the doc, it works perfectly with the Symfony\Component\Validator\Constraints\Email constraint: I get an error if the string is not an email.


What is my mistake?



asked 1 min ago







Symfony validation to validate a simple value does not work with LessThan constraint

Aucun commentaire:

Enregistrer un commentaire