93
93
use Symfony \Component \Translation \DependencyInjection \TranslatorPass ;
94
94
use Symfony \Component \Translation \LocaleSwitcher ;
95
95
use Symfony \Component \Translation \TranslatableMessage ;
96
+ use Symfony \Component \Validator \Constraints \Traverse ;
96
97
use Symfony \Component \Validator \DependencyInjection \AddConstraintValidatorsPass ;
97
98
use Symfony \Component \Validator \Validation ;
98
99
use Symfony \Component \Validator \Validator \ValidatorInterface ;
@@ -1312,16 +1313,17 @@ public function testValidation()
1312
1313
$ projectDir = $ container ->getParameter ('kernel.project_dir ' );
1313
1314
1314
1315
$ 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 );
1319
1321
1320
1322
$ calls = $ container ->getDefinition ('validator.builder ' )->getMethodCalls ();
1321
1323
1322
- $ annotations = !class_exists (FullStack::class);
1324
+ $ attributes = !class_exists (FullStack::class);
1323
1325
1324
- $ this ->assertCount ($ annotations ? 8 : 7 , $ calls );
1326
+ $ this ->assertCount ($ attributes ? 8 : 7 , $ calls );
1325
1327
$ this ->assertSame ('setConstraintValidatorFactory ' , $ calls [0 ][0 ]);
1326
1328
$ this ->assertEquals ([new Reference ('validator.validator_factory ' )], $ calls [0 ][1 ]);
1327
1329
$ this ->assertSame ('setGroupProviderLocator ' , $ calls [1 ][0 ]);
@@ -1333,7 +1335,7 @@ public function testValidation()
1333
1335
$ this ->assertSame ('addXmlMappings ' , $ calls [4 ][0 ]);
1334
1336
$ this ->assertSame ([$ xmlMappings ], $ calls [4 ][1 ]);
1335
1337
$ i = 4 ;
1336
- if ($ annotations ) {
1338
+ if ($ attributes ) {
1337
1339
$ this ->assertSame ('enableAttributeMapping ' , $ calls [++$ i ][0 ]);
1338
1340
}
1339
1341
$ this ->assertSame ('addMethodMapping ' , $ calls [++$ i ][0 ]);
@@ -1408,15 +1410,19 @@ public function testValidationPaths()
1408
1410
$ this ->assertEquals ([new Reference ('validator.mapping.cache.adapter ' )], $ calls [8 ][1 ]);
1409
1411
1410
1412
$ 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 );
1418
1423
}
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 ]);
1420
1426
1421
1427
$ yamlMappings = $ calls [5 ][1 ][0 ];
1422
1428
$ this ->assertCount (1 , $ yamlMappings );
@@ -1434,16 +1440,19 @@ public function testValidationPathsUsingCustomBundlePath()
1434
1440
1435
1441
$ calls = $ container ->getDefinition ('validator.builder ' )->getMethodCalls ();
1436
1442
$ 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 );
1445
1453
}
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 ]);
1447
1456
1448
1457
$ yamlMappings = $ calls [5 ][1 ][0 ];
1449
1458
$ this ->assertCount (1 , $ yamlMappings );
@@ -1490,7 +1499,6 @@ public function testValidationMapping()
1490
1499
$ calls = $ container ->getDefinition ('validator.builder ' )->getMethodCalls ();
1491
1500
1492
1501
$ this ->assertSame ('addXmlMappings ' , $ calls [4 ][0 ]);
1493
- $ this ->assertCount (3 , $ calls [4 ][1 ][0 ]);
1494
1502
1495
1503
$ this ->assertSame ('addYamlMappings ' , $ calls [5 ][0 ]);
1496
1504
$ this ->assertCount (3 , $ calls [5 ][1 ][0 ]);
0 commit comments