merged branch mythmakr/3686-min-max-validators-to-ignore-empty-string (PR #4188)
Commits -------f30bf36
Min/Max Validators ignore empty stringe9f5f13
Added test Min/Max validators should ignore empty string Discussion ---------- [Validator] Min/Max validators should ignore empty string Bug fix: yes Feature addition: no Backwards compatibility break: no Symfony2 tests pass: yes ![Build status](https://secure.travis-ci.org/mythmakr/symfony.png?branch=3686-min-max-validators-to-ignore-empty-string) Fixes the following tickets: #3686 Closed related PR #3687 Todo:
This commit is contained in:
commit
a640a33a24
@ -31,7 +31,7 @@ class MaxValidator extends ConstraintValidator
|
||||
*/
|
||||
public function validate($value, Constraint $constraint)
|
||||
{
|
||||
if (null === $value) {
|
||||
if (null === $value || '' === $value) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -31,7 +31,7 @@ class MinValidator extends ConstraintValidator
|
||||
*/
|
||||
public function validate($value, Constraint $constraint)
|
||||
{
|
||||
if (null === $value) {
|
||||
if (null === $value || '' === $value) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -40,6 +40,14 @@ class MaxValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
$this->validator->validate(null, new Max(array('limit' => 10)));
|
||||
}
|
||||
|
||||
public function testEmptyStringIsValid()
|
||||
{
|
||||
$this->context->expects($this->never())
|
||||
->method('addViolation');
|
||||
|
||||
$this->validator->validate('', new Max(array('limit' => 10)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getValidValues
|
||||
*/
|
||||
|
@ -34,6 +34,14 @@ class MinValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
$this->validator->validate(null, new Min(array('limit' => 10)));
|
||||
}
|
||||
|
||||
public function testEmptyStringIsValid()
|
||||
{
|
||||
$this->context->expects($this->never())
|
||||
->method('addViolation');
|
||||
|
||||
$this->validator->validate('', new Min(array('limit' => 10)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getValidValues
|
||||
*/
|
||||
|
Reference in New Issue
Block a user