Skip to content

Commit

Permalink
[Validator] Fixed string-based constraint validators to accept empty …
Browse files Browse the repository at this point in the history
…values
  • Loading branch information
Bernhard Schussek authored and fabpot committed Dec 10, 2010
1 parent af291bb commit 1b2ca25
Show file tree
Hide file tree
Showing 16 changed files with 48 additions and 8 deletions.
Expand Up @@ -21,7 +21,7 @@ class DateTimeValidator extends ConstraintValidator

public function isValid($value, Constraint $constraint)
{
if ($value === null) {
if ($value === null || $value === '') {
return true;
}

Expand Down
Expand Up @@ -21,7 +21,7 @@ class DateValidator extends ConstraintValidator

public function isValid($value, Constraint $constraint)
{
if ($value === null) {
if ($value === null || $value === '') {
return true;
}

Expand Down
Expand Up @@ -21,7 +21,7 @@ class EmailValidator extends ConstraintValidator

public function isValid($value, Constraint $constraint)
{
if ($value === null) {
if ($value === null || $value === '') {
return true;
}

Expand Down
Expand Up @@ -21,7 +21,7 @@ class FileValidator extends ConstraintValidator
{
public function isValid($value, Constraint $constraint)
{
if ($value === null) {
if ($value === null || $value === '') {
return true;
}

Expand Down
Expand Up @@ -19,7 +19,7 @@ class MaxLengthValidator extends ConstraintValidator
{
public function isValid($value, Constraint $constraint)
{
if ($value === null) {
if ($value === null || $value === '') {
return true;
}

Expand Down
Expand Up @@ -19,7 +19,7 @@ class MinLengthValidator extends ConstraintValidator
{
public function isValid($value, Constraint $constraint)
{
if ($value === null) {
if ($value === null || $value === '') {
return true;
}

Expand Down
Expand Up @@ -19,7 +19,7 @@ class RegexValidator extends ConstraintValidator
{
public function isValid($value, Constraint $constraint)
{
if ($value === null) {
if ($value === null || $value === '') {
return true;
}

Expand Down
Expand Up @@ -21,7 +21,7 @@ class TimeValidator extends ConstraintValidator

public function isValid($value, Constraint $constraint)
{
if ($value === null) {
if ($value === null || $value === '') {
return true;
}

Expand Down
Expand Up @@ -19,6 +19,11 @@ public function testNullIsValid()
$this->assertTrue($this->validator->isValid(null, new DateTime()));
}

public function testEmptyStringIsValid()
{
$this->assertTrue($this->validator->isValid('', new DateTime()));
}

public function testExpectsStringCompatibleType()
{
$this->setExpectedException('Symfony\Component\Validator\Exception\UnexpectedTypeException');
Expand Down
Expand Up @@ -19,6 +19,11 @@ public function testNullIsValid()
$this->assertTrue($this->validator->isValid(null, new Date()));
}

public function testEmptyStringIsValid()
{
$this->assertTrue($this->validator->isValid('', new Date()));
}

public function testExpectsStringCompatibleType()
{
$this->setExpectedException('Symfony\Component\Validator\Exception\UnexpectedTypeException');
Expand Down
Expand Up @@ -19,6 +19,11 @@ public function testNullIsValid()
$this->assertTrue($this->validator->isValid(null, new Email()));
}

public function testEmptyStringIsValid()
{
$this->assertTrue($this->validator->isValid('', new Email()));
}

public function testExpectsStringCompatibleType()
{
$this->setExpectedException('Symfony\Component\Validator\Exception\UnexpectedTypeException');
Expand Down
Expand Up @@ -28,6 +28,11 @@ public function testNullIsValid()
$this->assertTrue($this->validator->isValid(null, new File()));
}

public function testEmptyStringIsValid()
{
$this->assertTrue($this->validator->isValid('', new File()));
}

public function testExpectsStringCompatibleTypeOrFile()
{
$this->setExpectedException('Symfony\Component\Validator\Exception\UnexpectedTypeException');
Expand Down
Expand Up @@ -19,6 +19,11 @@ public function testNullIsValid()
$this->assertTrue($this->validator->isValid(null, new MaxLength(array('limit' => 5))));
}

public function testEmptyStringIsValid()
{
$this->assertTrue($this->validator->isValid('', new MaxLength(array('limit' => 5))));
}

public function testExpectsStringCompatibleType()
{
$this->setExpectedException('Symfony\Component\Validator\Exception\UnexpectedTypeException');
Expand Down
Expand Up @@ -19,6 +19,11 @@ public function testNullIsValid()
$this->assertTrue($this->validator->isValid(null, new MinLength(array('limit' => 6))));
}

public function testEmptyStringIsValid()
{
$this->assertTrue($this->validator->isValid('', new MinLength(array('limit' => 6))));
}

public function testExpectsStringCompatibleType()
{
$this->setExpectedException('Symfony\Component\Validator\Exception\UnexpectedTypeException');
Expand Down
Expand Up @@ -19,6 +19,11 @@ public function testNullIsValid()
$this->assertTrue($this->validator->isValid(null, new Regex(array('pattern' => '/^[0-9]+$/'))));
}

public function testEmptyStringIsValid()
{
$this->assertTrue($this->validator->isValid('', new Regex(array('pattern' => '/^[0-9]+$/'))));
}

public function testExpectsStringCompatibleType()
{
$this->setExpectedException('Symfony\Component\Validator\Exception\UnexpectedTypeException');
Expand Down
Expand Up @@ -19,6 +19,11 @@ public function testNullIsValid()
$this->assertTrue($this->validator->isValid(null, new Time()));
}

public function testEmptyStringIsValid()
{
$this->assertTrue($this->validator->isValid('', new Time()));
}

public function testExpectsStringCompatibleType()
{
$this->setExpectedException('Symfony\Component\Validator\Exception\UnexpectedTypeException');
Expand Down

0 comments on commit 1b2ca25

Please sign in to comment.