[Validator] Allow DateTime objects as valid Times
This commit is contained in:
parent
f3cafcb355
commit
ca52a04f5e
@ -25,6 +25,10 @@ class TimeValidator extends ConstraintValidator
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($value instanceof \DateTime) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!is_scalar($value) && !(is_object($value) && method_exists($value, '__toString'))) {
|
||||
throw new UnexpectedTypeException($value, 'string');
|
||||
}
|
||||
|
@ -33,6 +33,11 @@ class DateValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertTrue($this->validator->isValid('', new Date()));
|
||||
}
|
||||
|
||||
public function testDateTimeClassIsValid()
|
||||
{
|
||||
$this->validator->isValid(new \DateTime(), new Date());
|
||||
}
|
||||
|
||||
public function testExpectsStringCompatibleType()
|
||||
{
|
||||
$this->setExpectedException('Symfony\Component\Validator\Exception\UnexpectedTypeException');
|
||||
|
@ -33,6 +33,11 @@ class TimeValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertTrue($this->validator->isValid('', new Time()));
|
||||
}
|
||||
|
||||
public function testDateTimeClassIsValid()
|
||||
{
|
||||
$this->validator->isValid(new \DateTime(), new Time());
|
||||
}
|
||||
|
||||
public function testExpectsStringCompatibleType()
|
||||
{
|
||||
$this->setExpectedException('Symfony\Component\Validator\Exception\UnexpectedTypeException');
|
||||
|
Reference in New Issue
Block a user