8000 Merge branch '2.5' · symfony/symfony@1d7599d · GitHub
[go: up one dir, main page]

Skip to content

Commit 1d7599d

Browse files
committed
Merge branch '2.5'
* 2.5: [Validator] Fixed missing use statements [Validators] Fixed failing tests requiring ICU 52.1 which are skipped otherwise [FrameworkBundle] Fixed validator factory definition when the Validator API is "auto" for PHP < 5.3.9 return empty metadata collection if none do exist
2 parents a6beede + fb97786 commit 1d7599d

22 files changed

+250
-26
lines changed

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,15 +469,30 @@ private function addValidationSection(ArrayNodeDefinition $rootNode)
469469
->booleanNode('strict_email')->defaultFalse()->end()
470470
->enumNode('api')
471471
->values(array('2.4', '2.5', '2.5-bc', 'auto'))
472-
->defaultValue('auto')
473472
->beforeNormalization()
473+
// XML/YAML parse as numbers, not as strings
474474
->ifTrue(function ($v) { return is_scalar($v); })
475475
->then(function ($v) { return (string) $v; })
476476
->end()
477477
->end()
478478
->end()
479479
->end()
480480
->end()
481+
->validate()
482+
->ifTrue(function ($v) { return !isset($v['validation']['api']) || 'auto' === $v['validation']['api']; })
483+
->then(function ($v) {
484+
// This condition is duplicated in ValidatorBuilder. This
485+
// duplication is necessary in order to know the desired
486+
// API version already during container configuration
487+
// (to adjust service classes etc.)
488+
// See https://github.com/symfony/symfony/issues/11580
489+
$v['validation']['api'] = version_compare(PHP_VERSION, '5.3.9', '<')
490+
? '2.4'
491+
: '2.5-bc';
492+
493+
return $v;
494+
})
495+
->end()
481496
;
482497
}
483498

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -737,21 +737,23 @@ private function registerValidationConfiguration(array $config, ContainerBuilder
737737
$validatorBuilder->addMethodCall('setMetadataCache', array(new Reference('validator.mapping.cache.'.$config['cache'])));
738738
}
739739

740-
if ('auto' !== $config['api']) {
741-
switch ($config['api']) {
742-
case '2.4':
743-
$api = Validation::API_VERSION_2_4;
744-
break;
745-
case '2.5':
746-
$api = Validation::API_VERSION_2_5;
747-
break;
748-
default:
749-
$api = Validation::API_VERSION_2_5_BC;
750-
break;
FAAC 751-
}
752-
753-
$validatorBuilder->addMethodCall('setApiVersion', array($api));
754-
}
740+
switch ($config['api']) {
741+
case '2.4':
742+
$api = Validation::API_VERSION_2_4;
743+
break;
744+
case '2.5':
745+
$api = Validation::API_VERSION_2_5;
746+
break;
747+
default:
748+
$api = Validation::API_VERSION_2_5_BC;
749+
break;
750+
}
751+
752+
$validatorBuilder->addMethodCall('setApiVersion', array($api));
753+
754+
// You can use this parameter to check the API version in your own
755+
// bundle extension classes
756+
$container->setParameter('validator.api', $api);
755757
}
756758

757759
private function getValidatorXmlMappingFiles(ContainerBuilder $container)

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/ConfigurationTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ protected static function getBundleDefaultConfig()
130130
'static_method' => array('loadValidatorMetadata'),
131131
'translation_domain' => 'validators',
132132
'strict_email' => false,
133-
'api' => 'auto',
133+
'api' => version_compare(PHP_VERSION, '5.3.9', '<') ? '2.4' : '2.5-bc',
134134
),
135135
'annotations' => array(
136136
'cache' => 'file',
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
$container->loadFromExtension('framework', array(
4+
'secret' => 's3cr3t',
5+
'validation' => array(
6+
'enabled' => true,
7+
'api' => '2.5',
8+
),
9+
));
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
$container->loadFromExtension('framework', array(
4+
'secret' => 's3cr3t',
5+
'validation' => array(
6+
'enabled' => true,
7+
'api' => '2.5-bc',
8+
),
9+
));
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
$container->loadFromExtension('framework', array(
4+
'secret' => 's3cr3t',
5+
'validation' => array(
6+
'enabled' => true,
7+
'api' => 'auto',
8+
),
9+
));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
$container->loadFromExtension('framework', array(
4+
'secret' => 's3cr3t',
5+
'validation' => array(
6+
'enabled' => true,
7+
),
8+
));
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" ?>
2+
3+
<container xmlns="http://symfony.com/schema/dic/services"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xmlns:framework="http://symfony.com/schema/dic/symfony"
6+
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
7+
http://symfony.com/schema/dic/symfony http://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
8+
9+
<framework:config secret="s3cr3t">
10+
<framework:validation enabled="true" api="2.5" />
11+
</framework:config>
12+
</container>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" ?>
2+
3+
<container xmlns="http://symfony.com/schema/dic/services"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xmlns:framework="http://symfony.com/schema/dic/symfony"
6+
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
7+
http://symfony.com/schema/dic/symfony http://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
8+
9+
<framework:config secret="s3cr3t">
10+
<framework:validation enabled="true" api="2.5-bc" />
11+
</framework:config>
12+
</container>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" ?>
2+
3+
<container xmlns="http://symfony.com/schema/dic/services"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xmlns:framework="http://symfony.com/schema/dic/symfony"
6+
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
7+
http://symfony.com/schema/dic/symfony http://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
8+
9+
<framework:config secret="s3cr3t">
10+
<framework:validation enabled="true" api="auto" />
11+
</framework:config>
12+
</container>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" ?>
2+
3+
<container xmlns="http://symfony.com/schema/dic/services"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xmlns:framework="http://symfony.com/schema/dic/symfony"
6+
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
7+
http://symfony.com/schema/dic/symfony http://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
8+
9+
<framework:config secret="s3cr3t">
10+
<framework:validation enabled="true" />
11+
</framework:config>
12+
</container>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
framework:
2+
secret: s3cr3t
3+
validation:
4+
enabled: true
5+
api: 2.5
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
framework:
2+
secret: s3cr3t
3+
validation:
4+
enabled: true
5+
api: 2.5-bc
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
framework:
2+
secret: s3cr3t
3+
validation:
4+
enabled: true
5+
api: auto
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
framework:
2+
secret: s3cr3t
3+
validation:
4+
enabled: true

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php

Lines changed: 86 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ public function testValidation()
265265

266266
$calls = $container->getDefinition('validator.builder')->getMethodCalls();
267267

268-
$this->assertCount(6, $calls);
268+
$this->assertCount(7, $calls);
269269
$this->assertSame('setConstraintValidatorFactory', $calls[0][0]);
270270
$this->assertEquals(array(new Reference('validator.validator_factory')), $calls[0][1]);
271271
$this->assertSame('setTranslator', $calls[1][0]);
@@ -278,6 +278,13 @@ public function testValidation()
278278
$this->assertSame(array('loadValidatorMetadata'), $calls[4][1]);
279279
$this->assertSame('setMetadataCache', $calls[5][0]);
280280
$this->assertEquals(array(new Reference('validator.mapping.cache.apc')), $calls[5][1]);
281+
$this->assertSame('setApiVersion', $calls[6][0]);
282+
283+
if (version_compare(PHP_VERSION, '5.3.9', '<')) {
284+
$this->assertEquals(array(Validation::API_VERSION_2_4), $calls[6][1]);
285+
} else {
286+
$this->assertEquals(array(Validation::API_VERSION_2_5_BC), $calls[6][1]);
287+
}
281288
}
282289

283290
public function testFullyConfiguredValidationService()
@@ -319,7 +326,7 @@ public function testValidationAnnotations()
319326

320327
$calls = $container->getDefinition('validator.builder')->getMethodCalls();
321328

322-
$this->assertCount(< F438 span class="pl-c1 x x-first x-last">6, $calls);
329+
$this->assertCount(7, $calls);
323330
$this->assertSame('enableAnnotationMapping', $calls[4][0]);
324331
$this->assertEquals(array(new Reference('annotation_reader')), $calls[4][1]);
325332
$this->assertSame('addMethodMapping', $calls[5][0]);
@@ -337,7 +344,7 @@ public function testValidationPaths()
337344

338345
$calls = $container->getDefinition('validator.builder')->getMethodCalls();
339346

340-
$this->assertCount(7, $calls);
347+
$this->assertCount(8, $calls);
341348
$this->assertSame('addXmlMappings', $calls[3][0]);
342349
$this->assertSame('addYamlMappings', $calls[4][0]);
343350
$this->assertSame('enableAnnotationMapping', $calls[5][0]);
@@ -360,12 +367,12 @@ public function testValidationNoStaticMethod()
360367

361368
$calls = $container->getDefinition('validator.builder')->getMethodCalls();
362369

363-
$this->assertCount(4, $calls);
370+
$this->assertCount(5, $calls);
364371
$this->assertSame('addXmlMappings', $calls[3][0]);
365372
// no cache, no annotations, no static methods
366373
}
367374

368-
public function testValidationApiVersion()
375+
public function testValidation2Dot4Api()
369376
{
370377
$container = $this->createContainerFromFile('validation_2_4_api');
371378

@@ -380,6 +387,80 @@ public function testValidationApiVersion()
380387
// no cache, no annotations
381388
}
382389

390+
public function testValidation2Dot5Api()
391+
{
392+
$container = $this->createContainerFromFile('validation_2_5_api');
393+
394+
$calls = $container->getDefinition('validator.builder')->getMethodCalls();
395+
396+
$this->assertCount(6, $calls);
397+
$this->assertSame('addXmlMappings', $calls[3][0]);
398+
$this->assertSame('addMethodMapping', $calls[4][0]);
399+
$t 10000 his->assertSame(array('loadValidatorMetadata'), $calls[4][1]);
400+
$this->assertSame('setApiVersion', $calls[5][0]);
401+
$this->assertSame(array(Validation::API_VERSION_2_5), $calls[5][1]);
402+
// no cache, no annotations
403+
}
404+
405+
public function testValidation2Dot5BcApi()
406+
{
407+
$container = $this->createContainerFromFile('validation_2_5_bc_api');
408+
409+
$calls = $container->getDefinition('validator.builder')->getMethodCalls();
410+
411+
$this->assertCount(6, $calls);
412+
$this->assertSame('addXmlMappings', $calls[3][0]);
413+
$this->assertSame('addMethodMapping', $calls[4][0]);
414+
$this->assertSame(array('loadValidatorMetadata'), $calls[4][1]);
415+
$this->assertSame('setApiVersion', $calls[5][0]);
416+
$this->assertSame(array(Validation::API_VERSION_2_5_BC), $calls[5][1]);
417+
// no cache, no annotations
418+
}
419+
420+
public function testValidationImplicitApi()
421+
{
422+
$container = $this->createContainerFromFile('validation_implicit_api');
423+
424+
$calls = $container->getDefinition('validator.builder')->getMethodCalls();
425+
426+
$this->assertCount(6, $calls);
427+
$this->assertSame('addXmlMappings', $calls[3][0]);
428+
$this->assertSame('addMethodMapping', $calls[4][0]);
429+
$this->assertSame(array('loadValidatorMetadata'), $calls[4][1]);
430+
$this->assertSame('setApiVersion', $calls[5][0]);
431+
// no cache, no annotations
432+
433+
if (version_compare(PHP_VERSION, '5.3.9', '<')) {
434+
$this->assertSame(array(Validation::API_VERSION_2_4), $calls[5][1]);
435+
} else {
436+
$this->assertSame(array(Validation::API_VERSION_2_5_BC), $calls[5][1]);
437+
}
438+
}
439+
440+
/**
441+
* This feature is equivalent to the implicit api, only that the "api"
442+
* key is explicitly set to "auto".
443+
*/
444+
public function testValidationAutoApi()
445+
{
446+
$container = $this->createContainerFromFile('validation_auto_api');
447+
448+
$calls = $container->getDefinition('validator.builder')->getMethodCalls();
449+
450+
$this->assertCount(6, $calls);
451+
$this->assertSame('addXmlMappings', $calls[3][0]);
452+
$this->assertSame('addMethodMapping', $calls[4][0]);
453+
$this->assertSame(array('loadValidatorMetadata'), $calls[4][1]);
454+
$this->assertSame('setApiVersion', $calls[5][0]);
455+
// no cache, no annotations
456+
457+
if (version_compare(PHP_VERSION, '5.3.9', '<')) {
458+
$this->assertSame(array(Validation::API_VERSION_2_4), $calls[5][1]);
459+
} else {
460+
$this->assertSame(array(Validation::API_VERSION_2_5_BC), $calls[5][1]);
461+
}
462+
}
463+
383464
public function testFormsCanBeEnabledWithoutCsrfProtection()
384465
{
385466
$container = $this->createContainerFromFile('form_no_csrf');

src/Symfony/Component/Validator/Mapping/ClassMetadata.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,10 @@ public function hasMemberMetadatas($property)
371371
*/
372372
public function getMemberMetadatas($property)
373373
{
374+
if (!isset($this->members[$property])) {
375+
return array();
376+
}
377+
374378
return $this->members[$property];
375379
}
376380

@@ -387,6 +391,10 @@ public function hasPropertyMetadata($property)
387391
*/
388392
public function getPropertyMetadata($property)
389393
{
394+
if (!isset($this->members[$property])) {
395+
return array();
396+
}
397+
390398
return $this->members[$property];
391399
}
392400

src/Symfony/Component/Validator/Tests/Constraints/CountryValidatorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public function testInvalidCountries($country)
8888
$this->validator->validate($country, $constraint);
8989

9090
$this->assertViolation('myMessage', array(
91-
'{{ value }}' => $country,
91+
'{{ value }}' => '"'.$country.'"',
9292
));
9393
}
9494

src/Symfony/Component/Validator/Tests/Constraints/CurrencyValidatorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public function testInvalidCurrencies($currency)
102102
$this->validator->validate($currency, $constraint);
103103

104104
$this->assertViolation('myMessage', array(
105-
'{{ value }}' => $currency,
105+
'{{ value }}' => '"'.$currency.'"',
106106
));
107107
}
108108

src/Symfony/Component/Validator/Tests/Constraints/LanguageValidatorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public function testInvalidLanguages($language)
8888
$this->validator->validate($language, $constraint);
8989

9090
$this->assertViolation('myMessage', array(
91-
'{{ value }}' => $language,
91+
'{{ value }}' => '"'.$language.'"',
9292
));
9393
}
9494

src/Symfony/Component/Validator/Tests/Constraints/LocaleValidatorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public function testInvalidLocales($locale)
9090
$this->validator->validate($locale, $constraint);
9191

9292
$this->assertViolation('myMessage', array(
93-
'{{ value }}' => $locale,
93+
'{{ value }}' => '"'.$locale.'"',
9494
));
9595
}
9696

0 commit comments

Comments
 (0)
0