merged branch mythmakr/3686-min-max-validators-to-ignore-empty-string (PR #4188)

Commits
-------

f30bf36 Min/Max Validators ignore empty string
e9f5f13 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:
Fabien Potencier 2012-07-10 10:21:58 +02:00
commit a640a33a24
4 changed files with 18 additions and 2 deletions

View File

@ -31,7 +31,7 @@ class MaxValidator extends ConstraintValidator
*/
public function validate($value, Constraint $constraint)
{
if (null === $value) {
if (null === $value || '' === $value) {
return;
}

View File

@ -31,7 +31,7 @@ class MinValidator extends ConstraintValidator
*/
public function validate($value, Constraint $constraint)
{
if (null === $value) {
if (null === $value || '' === $value) {
return;
}

View File

@ -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
*/

View File

@ -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
*/