Skip to content

Commit

Permalink
Skip validation when email is an empty object
Browse files Browse the repository at this point in the history
  • Loading branch information
acrobat committed May 3, 2020
1 parent bfdbb24 commit de5d68e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
Expand Up @@ -51,6 +51,9 @@ public function validate($value, Constraint $constraint)
}

$value = (string) $value;
if ('' === $value) {
return;
}

if (null === $constraint->strict) {
$constraint->strict = $this->isStrict;
Expand Down
Expand Up @@ -40,6 +40,13 @@ public function testEmptyStringIsValid()
$this->assertNoViolation();
}

public function testObjectEmptyStringIsValid()
{
$this->validator->validate(new EmptyEmailObject(), new Email());

$this->assertNoViolation();
}

public function testExpectsStringCompatibleType()
{
$this->expectException('Symfony\Component\Validator\Exception\UnexpectedTypeException');
Expand Down Expand Up @@ -256,3 +263,11 @@ public function provideCheckTypes()
];
}
}

class EmptyEmailObject
{
public function __toString()
{
return '';
}
}

0 comments on commit de5d68e

Please sign in to comment.