[Validator] Support for DateTimeImmutable
This commit is contained in:
parent
eadfc933ab
commit
f49659f137
@ -30,7 +30,7 @@ class DateTimeValidator extends DateValidator
|
|||||||
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\DateTime');
|
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\DateTime');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (null === $value || '' === $value || $value instanceof \DateTime) {
|
if (null === $value || '' === $value || $value instanceof \DateTimeInterface) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,7 +47,7 @@ class DateValidator extends ConstraintValidator
|
|||||||
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Date');
|
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Date');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (null === $value || '' === $value || $value instanceof \DateTime) {
|
if (null === $value || '' === $value || $value instanceof \DateTimeInterface) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,6 +42,13 @@ class DateTimeValidatorTest extends AbstractConstraintValidatorTest
|
|||||||
$this->assertNoViolation();
|
$this->assertNoViolation();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testDateTimeImmutableClassIsValid()
|
||||||
|
{
|
||||||
|
$this->validator->validate(new \DateTimeImmutable(), new DateTime());
|
||||||
|
|
||||||
|
$this->assertNoViolation();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException \Symfony\Component\Validator\Exception\UnexpectedTypeException
|
* @expectedException \Symfony\Component\Validator\Exception\UnexpectedTypeException
|
||||||
*/
|
*/
|
||||||
|
@ -42,6 +42,13 @@ class DateValidatorTest extends AbstractConstraintValidatorTest
|
|||||||
$this->assertNoViolation();
|
$this->assertNoViolation();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testDateTimeImmutableClassIsValid()
|
||||||
|
{
|
||||||
|
$this->validator->validate(new \DateTimeImmutable(), new Date());
|
||||||
|
|
||||||
|
$this->assertNoViolation();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException \Symfony\Component\Validator\Exception\UnexpectedTypeException
|
* @expectedException \Symfony\Component\Validator\Exception\UnexpectedTypeException
|
||||||
*/
|
*/
|
||||||
|
Reference in New Issue
Block a user