[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,7 +142,10 @@ class GraphWalker
|
|||||||
|
|
||||||
if ($traverse && (is_array($value) || $value instanceof \Traversable)) {
|
if ($traverse && (is_array($value) || $value instanceof \Traversable)) {
|
||||||
foreach ($value as $key => $element) {
|
foreach ($value as $key => $element) {
|
||||||
$this->walkReference($element, $group, $propertyPath.'['.$key.']', $traverse);
|
// Ignore any scalar values in the collection
|
||||||
|
if (is_object($element) || is_array($element)) {
|
||||||
|
$this->walkReference($element, $group, $propertyPath.'['.$key.']', $traverse);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -330,6 +330,24 @@ class GraphWalkerTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertEquals($violations, $this->walker->getViolations());
|
$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()
|
public function testWalkCascadedPropertyDoesNotValidateNullValues()
|
||||||
{
|
{
|
||||||
$this->metadata->addPropertyConstraint('reference', new Valid());
|
$this->metadata->addPropertyConstraint('reference', new Valid());
|
||||||
|
Reference in New Issue
Block a user