Skip to content

Commit cd93eea

Browse files
committed
Merge branch '4.4' into 5.1
* 4.4: [Validator] RangeTest: fix expected deprecation [Yaml] Fix for #36624; Allow PHP constant as first key in block Use PHPUnit 9.3 on php 8. fix mapping errors from unmapped forms [Validator] Add target guards for Composite nested constraints
2 parents 4b9cd63 + 726b863 commit cd93eea

File tree

3 files changed

+49
-15
lines changed

3 files changed

+49
-15
lines changed

Extension/Validator/ViolationMapper/ViolationMapper.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -231,13 +231,6 @@ private function reconstructPath(ViolationPath $violationPath, FormInterface $or
231231
// Form inherits its parent data
232232
// Cut the piece out of the property path and proceed
233233
$propertyPathBuilder->remove($i);
234-
} elseif (!$scope->getConfig()->getMapped()) {
235-
// Form is not mapped
236-
// Set the form as new origin and strip everything
237-
// we have so far in the path
238-
$origin = $scope;
239-
$propertyPathBuilder->remove(0, $i + 1);
240-
$i = 0;
241234
} else {
242235
/* @var \Symfony\Component\PropertyAccess\PropertyPathInterface $propertyPath */
243236
$propertyPath = $scope->getPropertyPath();
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Form\Tests\Extension\Validator\ViolationMapper\Fixtures;
13+
14+
class Issue
15+
{
16+
}

Tests/Extension/Validator/ViolationMapper/ViolationMapperTest.php

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use Symfony\Component\Form\FormConfigBuilder;
2323
use Symfony\Component\Form\FormError;
2424
use Symfony\Component\Form\FormInterface;
25+
use Symfony\Component\Form\Tests\Extension\Validator\ViolationMapper\Fixtures\Issue;
2526
use Symfony\Component\PropertyAccess\PropertyPath;
2627
use Symfony\Component\Validator\ConstraintViolation;
2728
use Symfony\Component\Validator\ConstraintViolationInterface;
@@ -70,12 +71,12 @@ protected function setUp(): void
7071
$this->params = ['foo' => 'bar'];
7172
}
7273

73-
protected function getForm($name = 'name', $propertyPath = null, $dataClass = null, $errorMapping = [], $inheritData = false, $synchronized = true)
74+
protected function getForm($name = 'name', $propertyPath = null, $dataClass = null, $errorMapping = [], $inheritData = false, $synchronized = true, array $options = [])
7475
{
7576
$config = new FormConfigBuilder($name, $dataClass, $this->dispatcher, [
7677
'error_mapping' => $errorMapping,
77-
]);
78-
$config->setMapped(true);
78+
] + $options);
79+
$config->setMapped(isset($options['mapped']) ? $options['mapped'] : true);
7980
$config->setInheritData($inheritData);
8081
$config->setPropertyPath($propertyPath);
8182
$config->setCompound(true);
@@ -91,12 +92,9 @@ function () { throw new TransformationFailedException(); }
9192
return new Form($config);
9293
}
9394

94-
/**
95-
* @param $propertyPath
96-
*/
97-
protected function getConstraintViolation($propertyPath): ConstraintViolation
95+
protected function getConstraintViolation($propertyPath, $root = null): ConstraintViolation
9896
{
99-
return new ConstraintViolation($this->message, $this->messageTemplate, $this->params, null, $propertyPath, null);
97+
return new ConstraintViolation($this->message, $this->messageTemplate, $this->params, $root, $propertyPath, null);
10098
}
10199

102100
protected function getFormError(ConstraintViolationInterface $violation, FormInterface $form): FormError
@@ -107,6 +105,33 @@ protected function getFormError(ConstraintViolationInterface $violation, FormInt
107105
return $error;
108106
}
109107

108+
public function testMappingErrorsWhenFormIsNotMapped()
109+
{
110+
$form = $this->getForm('name', null, Issue::class, [
111+
'child1' => 'child2',
112+
]);
113+
114+
$violation = $this->getConstraintViolation('children[child1].data', $form);
115+
116+
$child1Form = $this->getForm('child1', null, null, [], false, true, [
117+
'mapped' => false,
118+
]);
119+
$child2Form = $this->getForm('child2', null, null, [], false, true, [
120+
'mapped' => false,
121+
]);
122+
123+
$form->add($child1Form);
124+
$form->add($child2Form);
125+
126+
$form->submit([]);
127+
128+
$this->mapper->mapViolation($violation, $form);
129+
130+
$this->assertCount(0, $form->getErrors());
131+
$this->assertCount(0, $form->get('child1')->getErrors());
132+
$this->assertCount(1, $form->get('child2')->getErrors());
133+
}
134+
110135
public function testMapToFormInheritingParentDataIfDataDoesNotMatch()
111136
{
112137
$violation = $this->getConstraintViolation('children[address].data.foo');

0 commit comments

Comments
 (0)