Skip validation when email is an empty object
This commit is contained in:
parent
bfdbb244fe
commit
de5d68ef2a
@ -51,6 +51,9 @@ class EmailValidator extends ConstraintValidator
|
|||||||
}
|
}
|
||||||
|
|
||||||
$value = (string) $value;
|
$value = (string) $value;
|
||||||
|
if ('' === $value) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (null === $constraint->strict) {
|
if (null === $constraint->strict) {
|
||||||
$constraint->strict = $this->isStrict;
|
$constraint->strict = $this->isStrict;
|
||||||
|
@ -40,6 +40,13 @@ class EmailValidatorTest extends ConstraintValidatorTestCase
|
|||||||
$this->assertNoViolation();
|
$this->assertNoViolation();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testObjectEmptyStringIsValid()
|
||||||
|
{
|
||||||
|
$this->validator->validate(new EmptyEmailObject(), new Email());
|
||||||
|
|
||||||
|
$this->assertNoViolation();
|
||||||
|
}
|
||||||
|
|
||||||
public function testExpectsStringCompatibleType()
|
public function testExpectsStringCompatibleType()
|
||||||
{
|
{
|
||||||
$this->expectException('Symfony\Component\Validator\Exception\UnexpectedTypeException');
|
$this->expectException('Symfony\Component\Validator\Exception\UnexpectedTypeException');
|
||||||
@ -256,3 +263,11 @@ class EmailValidatorTest extends ConstraintValidatorTestCase
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class EmptyEmailObject
|
||||||
|
{
|
||||||
|
public function __toString()
|
||||||
|
{
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user