[Validator] Fixed: Collections annotated with @Valid may contain scalar values. These values are ignored by the GraphWalker
This commit is contained in:
parent
50955a3919
commit
1a34743990
@ -142,9 +142,12 @@ class GraphWalker
|
||||
|
||||
if ($traverse && (is_array($value) || $value instanceof \Traversable)) {
|
||||
foreach ($value as $key => $element) {
|
||||
// Ignore any scalar values in the collection
|
||||
if (is_object($element) || is_array($element)) {
|
||||
$this->walkReference($element, $group, $propertyPath.'['.$key.']', $traverse);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (is_object($value)) {
|
||||
$metadata = $this->metadataFactory->getClassMetadata(get_class($value));
|
||||
|
@ -330,6 +330,24 @@ class GraphWalkerTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertEquals($violations, $this->walker->getViolations());
|
||||
}
|
||||
|
||||
public function testWalkCascadedPropertyDoesNotValidateNestedScalarValues()
|
||||
{
|
||||
// validate array when validating the property "reference"
|
||||
$this->metadata->addPropertyConstraint('reference', new Valid());
|
||||
|
||||
$this->walker->walkPropertyValue(
|
||||
$this->metadata,
|
||||
'reference',
|
||||
array('scalar', 'values'),
|
||||
'Default',
|
||||
'path'
|
||||
);
|
||||
|
||||
$violations = new ConstraintViolationList();
|
||||
|
||||
$this->assertEquals($violations, $this->walker->getViolations());
|
||||
}
|
||||
|
||||
public function testWalkCascadedPropertyDoesNotValidateNullValues()
|
||||
{
|
||||
$this->metadata->addPropertyConstraint('reference', new Valid());
|
||||
|
Reference in New Issue
Block a user