[Validator] Support for DateTimeImmutable

This commit is contained in:
Krzysiek Piasecki 2016-05-12 08:29:24 +02:00 committed by Nicolas Grekas
parent eadfc933ab
commit f49659f137
4 changed files with 16 additions and 2 deletions

View File

@ -30,7 +30,7 @@ class DateTimeValidator extends DateValidator
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\DateTime');
}
if (null === $value || '' === $value || $value instanceof \DateTime) {
if (null === $value || '' === $value || $value instanceof \DateTimeInterface) {
return;
}

View File

@ -47,7 +47,7 @@ class DateValidator extends ConstraintValidator
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Date');
}
if (null === $value || '' === $value || $value instanceof \DateTime) {
if (null === $value || '' === $value || $value instanceof \DateTimeInterface) {
return;
}

View File

@ -42,6 +42,13 @@ class DateTimeValidatorTest extends AbstractConstraintValidatorTest
$this->assertNoViolation();
}
public function testDateTimeImmutableClassIsValid()
{
$this->validator->validate(new \DateTimeImmutable(), new DateTime());
$this->assertNoViolation();
}
/**
* @expectedException \Symfony\Component\Validator\Exception\UnexpectedTypeException
*/

View File

@ -42,6 +42,13 @@ class DateValidatorTest extends AbstractConstraintValidatorTest
$this->assertNoViolation();
}
public function testDateTimeImmutableClassIsValid()
{
$this->validator->validate(new \DateTimeImmutable(), new Date());
$this->assertNoViolation();
}
/**
* @expectedException \Symfony\Component\Validator\Exception\UnexpectedTypeException
*/