2222use Symfony \Component \Form \FormConfigBuilder ;
2323use Symfony \Component \Form \FormError ;
2424use Symfony \Component \Form \FormInterface ;
25+ use Symfony \Component \Form \Tests \Extension \Validator \ViolationMapper \Fixtures \Issue ;
2526use Symfony \Component \PropertyAccess \PropertyPath ;
2627use Symfony \Component \Validator \ConstraintViolation ;
2728use Symfony \Component \Validator \ConstraintViolationInterface ;
@@ -70,12 +71,12 @@ protected function setUp()
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 );
@@ -96,9 +97,9 @@ function () { throw new TransformationFailedException(); }
9697 *
9798 * @return ConstraintViolation
9899 */
99- protected function getConstraintViolation ($ propertyPath )
100+ protected function getConstraintViolation ($ propertyPath, $ root = null )
100101 {
101- return new ConstraintViolation ($ this ->message , $ this ->messageTemplate , $ this ->params , null , $ propertyPath , null );
102+ return new ConstraintViolation ($ this ->message , $ this ->messageTemplate , $ this ->params , $ root , $ propertyPath , null );
102103 }
103104
104105 /**
@@ -112,6 +113,33 @@ protected function getFormError(ConstraintViolationInterface $violation, FormInt
112113 return $ error ;
113114 }
114115
116+ public function testMappingErrorsWhenFormIsNotMapped ()
117+ {
118+ $ form = $ this ->getForm ('name ' , null , Issue::class, [
119+ 'child1 ' => 'child2 ' ,
120+ ]);
121+
122+ $ violation = $ this ->getConstraintViolation ('children[child1].data ' , $ form );
123+
124+ $ child1Form = $ this ->getForm ('child1 ' , null , null , [], false , true , [
125+ 'mapped ' => false ,
126+ ]);
127+ $ child2Form = $ this ->getForm ('child2 ' , null , null , [], false , true , [
128+ 'mapped ' => false ,
129+ ]);
130+
131+ $ form ->add ($ child1Form );
132+ $ form ->add ($ child2Form );
133+
134+ $ form ->submit ([]);
135+
136+ $ this ->mapper ->mapViolation ($ violation , $ form );
137+
138+ $ this ->assertCount (0 , $ form ->getErrors ());
139+ $ this ->assertCount (0 , $ form ->get ('child1 ' )->getErrors ());
140+ $ this ->assertCount (1 , $ form ->get ('child2 ' )->getErrors ());
141+ }
142+
115143 public function testMapToFormInheritingParentDataIfDataDoesNotMatch ()
116144 {
117145 $ violation = $ this ->getConstraintViolation ('children[address].data.foo ' );
0 commit comments