[Validator] fixed error message for dates like 2012-02-31 (closes #4223)

This commit is contained in:
Fabien Potencier 2012-07-09 17:53:53 +02:00
parent 03d22b74ec
commit facbcdcf45
2 changed files with 3 additions and 2 deletions

View File

@ -48,12 +48,12 @@ class DateValidator extends ConstraintValidator
$value = (string) $value;
if (!preg_match(static::PATTERN, $value, $matches)) {
if (!preg_match(static::PATTERN, $value, $matches) || !checkdate($matches[2], $matches[3], $matches[1])) {
$this->setMessage($constraint->message, array('{{ value }}' => $value));
return false;
}
return checkdate($matches[2], $matches[3], $matches[1]);
return true;
}
}

View File

@ -73,6 +73,7 @@ class DateValidatorTest extends \PHPUnit_Framework_TestCase
public function testInvalidDates($date)
{
$this->assertFalse($this->validator->isValid($date, new Date()));
$this->assertEquals('This value is not a valid date', $this->validator->getMessageTemplate());
}
public function getInvalidDates()