Fixed the null value exception case.

This commit is contained in:
Valentin 2017-12-04 02:10:25 +03:00
parent c927c481aa
commit 56f24d08c9
2 changed files with 16 additions and 0 deletions

View File

@ -26,6 +26,10 @@ class ValidValidator extends ConstraintValidator
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Valid');
}
if (null === $value) {
return;
}
$this->context
->getValidator()
->inContext($this->context)

View File

@ -20,6 +20,18 @@ class ValidValidatorTest extends TestCase
$this->assertSame('fooBar.fooBarBaz.foo', $violations->get(0)->getPropertyPath());
}
public function testNullValues()
{
$validatorBuilder = new ValidatorBuilder();
$validator = $validatorBuilder->enableAnnotationMapping()->getValidator();
$foo = new Foo();
$foo->fooBar = null;
$violations = $validator->validate($foo, null, array('nested'));
$this->assertCount(0, $violations);
}
protected function createValidator()
{
return new ValidValidator();