Skip to content

Commit 56f24d0

Browse files
committed
Fixed the null value exception case.
1 parent c927c48 commit 56f24d0

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/Symfony/Component/Validator/Constraints/ValidValidator.php

+4
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ public function validate($value, Constraint $constraint)
2626
throw new UnexpectedTypeException($constraint, __NAMESPACE__.'\Valid');
2727
}
2828

29+
if (null === $value) {
30+
return;
31+
}
32+
2933
$this->context
3034
->getValidator()
3135
->inContext($this->context)

src/Symfony/Component/Validator/Tests/Constraints/ValidValidatorTest.php

+12
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,18 @@ public function testPropertyPathsArePassedToNestedContexts()
2020
$this->assertSame('fooBar.fooBarBaz.foo', $violations->get(0)->getPropertyPath());
2121
}
2222

23+
public function testNullValues()
24+
{
25+
$validatorBuilder = new ValidatorBuilder();
26+
$validator = $validatorBuilder->enableAnnotationMapping()->getValidator();
27+
28+
$foo = new Foo();
29+
$foo->fooBar = null;
30+
$violations = $validator->validate($foo, null, array('nested'));
31+
32+
$this->assertCount(0, $violations);
33+
}
34+
2335
protected function createValidator()
2436
{
2537
return new ValidValidator();

0 commit comments

Comments
 (0)