9393use Symfony \Component \Translation \DependencyInjection \TranslatorPass ;
9494use Symfony \Component \Translation \LocaleSwitcher ;
9595use Symfony \Component \Translation \TranslatableMessage ;
96+ use Symfony \Component \Validator \Constraints \Traverse ;
9697use Symfony \Component \Validator \DependencyInjection \AddConstraintValidatorsPass ;
9798use Symfony \Component \Validator \Validation ;
9899use Symfony \Component \Validator \Validator \ValidatorInterface ;
@@ -1312,16 +1313,17 @@ public function testValidation()
13121313 $ projectDir = $ container ->getParameter ('kernel.project_dir ' );
13131314
13141315 $ ref = new \ReflectionClass (Form::class);
1315- $ xmlMappings = [
1316- \dirname ($ ref ->getFileName ()).'/Resources/config/validation.xml ' ,
1317- strtr ($ projectDir .'/config/validator/foo.xml ' , '/ ' , \DIRECTORY_SEPARATOR ),
1318- ];
1316+ $ xmlMappings = [];
1317+ if (!$ ref ->getAttributes (Traverse::class)) {
1318+ $ xmlMappings [] = \dirname ($ ref ->getFileName ()).'/Resources/config/validation.xml ' ;
1319+ }
1320+ $ xmlMappings [] = strtr ($ projectDir .'/config/validator/foo.xml ' , '/ ' , \DIRECTORY_SEPARATOR );
13191321
13201322 $ calls = $ container ->getDefinition ('validator.builder ' )->getMethodCalls ();
13211323
1322- $ annotations = !class_exists (FullStack::class);
1324+ $ attributes = !class_exists (FullStack::class);
13231325
1324- $ this ->assertCount ($ annotations ? 8 : 7 , $ calls );
1326+ $ this ->assertCount ($ attributes ? 8 : 7 , $ calls );
13251327 $ this ->assertSame ('setConstraintValidatorFactory ' , $ calls [0 ][0 ]);
13261328 $ this ->assertEquals ([new Reference ('validator.validator_factory ' )], $ calls [0 ][1 ]);
13271329 $ this ->assertSame ('setGroupProviderLocator ' , $ calls [1 ][0 ]);
@@ -1333,7 +1335,7 @@ public function testValidation()
13331335 $ this ->assertSame ('addXmlMappings ' , $ calls [4 ][0 ]);
13341336 $ this ->assertSame ([$ xmlMappings ], $ calls [4 ][1 ]);
13351337 $ i = 4 ;
1336- if ($ annotations ) {
1338+ if ($ attributes ) {
13371339 $ this ->assertSame ('enableAttributeMapping ' , $ calls [++$ i ][0 ]);
13381340 }
13391341 $ this ->assertSame ('addMethodMapping ' , $ calls [++$ i ][0 ]);
@@ -1408,15 +1410,19 @@ public function testValidationPaths()
14081410 $ this ->assertEquals ([new Reference ('validator.mapping.cache.adapter ' )], $ calls [8 ][1 ]);
14091411
14101412 $ xmlMappings = $ calls [4 ][1 ][0 ];
1411- $ this ->assertCount (3 , $ xmlMappings );
1412- try {
1413- // Testing symfony/symfony
1414- $ this ->assertStringEndsWith ('Component ' .\DIRECTORY_SEPARATOR .'Form/Resources/config/validation.xml ' , $ xmlMappings [0 ]);
1415- } catch (\Exception $ e ) {
1416- // Testing symfony/framework-bundle with deps=high
1417- $ this ->assertStringEndsWith ('symfony ' .\DIRECTORY_SEPARATOR .'form/Resources/config/validation.xml ' , $ xmlMappings [0 ]);
1413+
1414+ if (!(new \ReflectionClass (Form::class))->getAttributes (Traverse::class)) {
1415+ try {
1416+ // Testing symfony/symfony
1417+ $ this ->assertStringEndsWith ('Component ' .\DIRECTORY_SEPARATOR .'Form/Resources/config/validation.xml ' , $ xmlMappings [0 ]);
1418+ } catch (\Exception $ e ) {
1419+ // Testing symfony/framework-bundle with deps=high
1420+ $ this ->assertStringEndsWith ('symfony ' .\DIRECTORY_SEPARATOR .'form/Resources/config/validation.xml ' , $ xmlMappings [0 ]);
1421+ }
1422+ array_shift ($ xmlMappings );
14181423 }
1419- $ this ->assertStringEndsWith ('TestBundle/Resources/config/validation.xml ' , $ xmlMappings [1 ]);
1424+ $ this ->assertCount (2 , $ xmlMappings );
1425+ $ this ->assertStringEndsWith ('TestBundle/Resources/config/validation.xml ' , $ xmlMappings [0 ]);
14201426
14211427 $ yamlMappings = $ calls [5 ][1 ][0 ];
14221428 $ this ->assertCount (1 , $ yamlMappings );
@@ -1434,16 +1440,19 @@ public function testValidationPathsUsingCustomBundlePath()
14341440
14351441 $ calls = $ container ->getDefinition ('validator.builder ' )->getMethodCalls ();
14361442 $ xmlMappings = $ calls [4 ][1 ][0 ];
1437- $ this ->assertCount (3 , $ xmlMappings );
1438-
1439- try {
1440- // Testing symfony/symfony
1441- $ this ->assertStringEndsWith ('Component ' .\DIRECTORY_SEPARATOR .'Form/Resources/config/validation.xml ' , $ xmlMappings [0 ]);
1442- } catch (\Exception $ e ) {
1443- // Testing symfony/framework-bundle with deps=high
1444- $ this ->assertStringEndsWith ('symfony ' .\DIRECTORY_SEPARATOR .'form/Resources/config/validation.xml ' , $ xmlMappings [0 ]);
1443+
1444+ if (!(new \ReflectionClass (Form::class))->getAttributes (Traverse::class)) {
1445+ try {
1446+ // Testing symfony/symfony
1447+ $ this ->assertStringEndsWith ('Component ' .\DIRECTORY_SEPARATOR .'Form/Resources/config/validation.xml ' , $ xmlMappings [0 ]);
1448+ } catch (\Exception $ e ) {
1449+ // Testing symfony/framework-bundle with deps=high
1450+ $ this ->assertStringEndsWith ('symfony ' .\DIRECTORY_SEPARATOR .'form/Resources/config/validation.xml ' , $ xmlMappings [0 ]);
1451+ }
1452+ array_shift ($ xmlMappings );
14451453 }
1446- $ this ->assertStringEndsWith ('CustomPathBundle/Resources/config/validation.xml ' , $ xmlMappings [1 ]);
1454+ $ this ->assertCount (2 , $ xmlMappings );
1455+ $ this ->assertStringEndsWith ('CustomPathBundle/Resources/config/validation.xml ' , $ xmlMappings [0 ]);
14471456
14481457 $ yamlMappings = $ calls [5 ][1 ][0 ];
14491458 $ this ->assertCount (1 , $ yamlMappings );
@@ -1490,7 +1499,6 @@ public function testValidationMapping()
14901499 $ calls = $ container ->getDefinition ('validator.builder ' )->getMethodCalls ();
14911500
14921501 $ this ->assertSame ('addXmlMappings ' , $ calls [4 ][0 ]);
1493- $ this ->assertCount (3 , $ calls [4 ][1 ][0 ]);
14941502
14951503 $ this ->assertSame ('addYamlMappings ' , $ calls [5 ][0 ]);
14961504 $ this ->assertCount (3 , $ calls [5 ][1 ][0 ]);
0 commit comments