Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f8f624b

Browse filesBrowse files
committed
bug #18761 [2.3] [Form] Modified iterator_to_array's 2nd parameter to false in ViolationMapper (issei-m)
This PR was squashed before being merged into the 2.3 branch (closes #18761). Discussion ---------- [2.3] [Form] Modified iterator_to_array's 2nd parameter to false in ViolationMapper | Q | A | ------------- | --- | Branch? | 2.3 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | n/a | License | MIT | Doc PR | n/a For #18747 Commits ------- 7101cab [2.3] [Form] Modified iterator_to_array's 2nd parameter to false in ViolationMapper
2 parents d9d8ea8 + 7101cab commit f8f624b
Copy full SHA for f8f624b

File tree

2 files changed

+26
-11
lines changed
Filter options

2 files changed

+26
-11
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Extension/Validator/ViolationMapper/ViolationMapper.php
+3-5Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Tests/Extension/Validator/ViolationMapper/ViolationMapperTest.php
+23-6Lines 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)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.