allow empty strings as time format
This commit is contained in:
@@ -26,6 +26,10 @@ class TimeFormatValidator extends ConstraintValidator
|
|||||||
throw new UnexpectedTypeException($constraint, __NAMESPACE__ . '\TimeFormat');
|
throw new UnexpectedTypeException($constraint, __NAMESPACE__ . '\TimeFormat');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (null === $value || '' === $value) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!is_scalar($value) && !(\is_object($value) && method_exists($value, '__toString'))) {
|
if (!is_scalar($value) && !(\is_object($value) && method_exists($value, '__toString'))) {
|
||||||
throw new UnexpectedValueException($value, 'string');
|
throw new UnexpectedValueException($value, 'string');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ class TimeFormatValidatorTest extends ConstraintValidatorTestCase
|
|||||||
/**
|
/**
|
||||||
* @dataProvider getValidTimes
|
* @dataProvider getValidTimes
|
||||||
*/
|
*/
|
||||||
public function testValidationSucceeds(string $value)
|
public function testValidationSucceeds(?string $value)
|
||||||
{
|
{
|
||||||
$this->validator->validate($value, new TimeFormat());
|
$this->validator->validate($value, new TimeFormat());
|
||||||
$this->assertNoViolation();
|
$this->assertNoViolation();
|
||||||
@@ -53,6 +53,8 @@ class TimeFormatValidatorTest extends ConstraintValidatorTestCase
|
|||||||
public function getValidTimes()
|
public function getValidTimes()
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
|
[''],
|
||||||
|
[null],
|
||||||
['00:00'],
|
['00:00'],
|
||||||
['00:01'],
|
['00:01'],
|
||||||
['23:00'],
|
['23:00'],
|
||||||
@@ -65,7 +67,7 @@ class TimeFormatValidatorTest extends ConstraintValidatorTestCase
|
|||||||
/**
|
/**
|
||||||
* @dataProvider getInvalidTimes
|
* @dataProvider getInvalidTimes
|
||||||
*/
|
*/
|
||||||
public function testValidationProblem(string $value)
|
public function testValidationProblem(?string $value)
|
||||||
{
|
{
|
||||||
$this->validator->validate($value, new TimeFormat());
|
$this->validator->validate($value, new TimeFormat());
|
||||||
|
|
||||||
@@ -78,6 +80,7 @@ class TimeFormatValidatorTest extends ConstraintValidatorTestCase
|
|||||||
public function getInvalidTimes()
|
public function getInvalidTimes()
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
|
['a'],
|
||||||
['1:00'],
|
['1:00'],
|
||||||
['01:1'],
|
['01:1'],
|
||||||
['00:60'],
|
['00:60'],
|
||||||
|
|||||||
Reference in New Issue
Block a user