8000 [2.3] [Form] Modified iterator_to_array's 2nd parameter to false in V… · symfony/symfony@7101cab · GitHub
[go: up one dir, main page]

Skip to content

Commit 7101cab

Browse files
issei-mfabpot
authored andcommitted
[2.3] [Form] Modified iterator_to_array's 2nd parameter to false in ViolationMapper
1 parent 4533220 commit 7101cab

File tree

2 files changed

+26
-11
lines changed

2 files changed

+26
-11
lines changed

src/Symfony/Component/Form/Extension/Validator/ViolationMapper/ViolationMapper.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,7 @@ private function matchChild(FormInterface $form, PropertyPathIteratorInterface $
161161
}
162162
}
163163

164-
$children = iterator_to_array(new \RecursiveIteratorIterator(
165-
new InheritDataAwareIterator($form)
166-
));
164+
$children = iterator_to_array(new \RecursiveIteratorIterator(new InheritDataAwareIterator($form)), false);
167165

168166
while ($it->valid()) {
169167
if ($it->isIndex()) {
@@ -188,7 +186,7 @@ private function matchChild(FormInterface $form, PropertyPathIteratorInterface $
188186
}
189187

190188
/** @var FormInterface $child */
191-
foreach ($children as $key => $child) {
189+
foreach ($children as $i => $child) {
192190
$childPath = (string) $child->getPropertyPath();
193191
if ($childPath === $chunk) {
194192
$target = $child;
@@ -197,7 +195,7 @@ private function matchChild(FormInterface $form, PropertyPathIteratorInterface $
197195
continue;
198196
}
199197

200-
unset($children[$key]);
198+
unset($children[$i]);
201199
}
202200

203201
$it->next();

src/Symfony/Component/Form/Tests/Extension/Validator/ViolationMapper/ViolationMapperTest.php

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1477,22 +1477,39 @@ public function testErrorMappingForFormInheritingParentData($target, $childName,
14771477

14781478
public function testBacktrackIfSeveralSubFormsWithSamePropertyPath()
14791479
{
1480-
$violation = $this->getConstraintViolation('data.address[street]');
14811480
$parent = $this->getForm('parent');
14821481
$child1 = $this->getForm('subform1', 'address');
14831482
$child2 = $this->getForm('subform2', 'address');
1484-
$grandChild = $this->getForm('street');
1483+
$child3 = $this->getForm('subform3', null, null, array(), true);
1484+
$child4 = $this->getForm('subform4', null, null, array(), true);
1485+
$grandChild1 = $this->getForm('street');
1486+
$grandChild2 = $this->getForm('street', '[sub_address1_street]');
1487+
$grandChild3 = $this->getForm('street', '[sub_address2_street]');
14851488

14861489
$parent->add($child1);
14871490
$parent->add($child2);
1488-
$child2->add($grandChild);
1491+
$parent->add($child3);
1492+
$parent->add($child4);
1493+
$child2->add($grandChild1);
1494+
$child3->add($grandChild2);
1495+
$child4->add($grandChild3);
14891496

1490-
$this->mapper->mapViolation($violation, $parent);
1497+
$parent->submit(array());
1498+
1499+
$violation1 = $this->getConstraintViolation('data.address[street]');
1500+
$violation2 = $this->getConstraintViolation('data[sub_address1_street]');
1501+
$violation3 = $this->getConstraintViolation('data[sub_address2_street]');
1502+
$this->mapper->mapViolation($violation1, $parent);
1503+
$this->mapper->mapViolation($violation2, $parent);
1504+
$this->mapper->mapViolation($violation3, $parent);
14911505

1492-
// The error occurred on the child of the second form with the same path
14931506
$this->assertCount(0, $parent->getErrors(), $parent->getName().' should not have an error, but has one');
14941507
$this->assertCount(0, $child1->getErrors(), $child1->getName().' should not have an error, but has one');
14951508
$this->assertCount(0, $child2->getErrors(), $child2->getName().' should not have an error, but has one');
1496-
$this->assertEquals(array($this->getFormError()), $grandChild->getErrors(), $grandChild->getName().' should have an error, but has none');
1509+
$this->assertCount(0, $child3->getErrors(), $child3->getName().' should not have an error, but has one');
1510+
$this->assertCount(0, $child4->getErrors(), $child4->getName().' should not have an error, but has one');
1511+
$this->assertEquals(array($this->getFormError($violation1, $grandChild1)), $grandChild1->getErrors(), $grandChild1->getName().' should have an error, but has none');
1512+
$this->assertEquals(array($this->getFormError($violation2, $grandChild2)), $grandChild2->getErrors(), $grandChild2->getName().' should have an error, but has none');
1513+
$this->assertEquals(array($this->getFormError($violation3, $grandChild3)), $grandChild3->getErrors(), $grandChild3->getName().' should have an error, but has none');
14971514
}
14981515
}

0 commit comments

Comments
 (0)
0