Skip to content

Commit 5e3bcec

Browse files
Merge branch '3.4' into 4.1
* 3.4: [Validator] Added IBAN format for Vatican City State filter out invalid Intl values [Validator] Fixed grouped composite constraints [Form] Filter arrays out of scalar form types
2 parents ba6e80f + ad5f91f commit 5e3bcec

File tree

4 files changed

+47
-0
lines changed

4 files changed

+47
-0
lines changed

Constraints/IbanValidator.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ class IbanValidator extends ConstraintValidator
129129
'TN' => 'TN59\d{2}\d{3}\d{13}\d{2}', // Tunisia
130130
'TR' => 'TR\d{2}\d{5}[\dA-Z]{1}[\dA-Z]{16}', // Turkey
131131
'UA' => 'UA\d{2}\d{6}[\dA-Z]{19}', // Ukraine
132+
'VA' => 'VA\d{2}\d{3}\d{15}', // Vatican City State
132133
'VG' => 'VG\d{2}[A-Z]{4}\d{16}', // Virgin Islands, British
133134
'WF' => 'FR\d{2}\d{5}\d{5}[\dA-Z]{11}\d{2}', // Wallis and Futuna Islands
134135
'XK' => 'XK\d{2}\d{4}\d{10}\d{2}', // Republic of Kosovo

Tests/Constraints/IbanValidatorTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ public function getValidIbans()
156156
array('TR330006100519786457841326'), //Turkey
157157
array('UA213223130000026007233566001'), //Ukraine
158158
array('AE260211000000230064016'), //United Arab Emirates
159+
array('VA59001123000012345678'), //Vatican City State
159160
);
160161
}
161162

@@ -274,6 +275,7 @@ public function getIbansWithInvalidFormat()
274275
array('TR3300061005197864578413261'), //Turkey
275276
array('UA21AAAA1300000260072335660012'), //Ukraine
276277
array('AE2602110000002300640161'), //United Arab Emirates
278+
array('VA590011230000123456781'), //Vatican City State
277279
);
278280
}
279281

@@ -385,6 +387,7 @@ public function getIbansWithValidFormatButIncorrectChecksum()
385387
array('TR330006100519786457841327'), //Turkey
386388
array('UA213223130000026007233566002'), //Ukraine
387389
array('AE260211000000230064017'), //United Arab Emirates
390+
array('VA59001123000012345671'), //Vatican City State
388391
);
389392
}
390393

Tests/Validator/RecursiveValidatorTest.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
namespace Symfony\Component\Validator\Tests\Validator;
1313

1414
use Symfony\Component\Translation\IdentityTranslator;
15+
use Symfony\Component\Validator\Constraints\All;
16+
use Symfony\Component\Validator\Constraints\Collection;
17+
use Symfony\Component\Validator\Constraints\Length;
18+
use Symfony\Component\Validator\Constraints\NotBlank;
1519
use Symfony\Component\Validator\ConstraintValidatorFactory;
1620
use Symfony\Component\Validator\Context\ExecutionContextFactory;
1721
use Symfony\Component\Validator\Mapping\Factory\MetadataFactoryInterface;
@@ -95,4 +99,38 @@ public function testRelationBetweenChildAAndChildB()
9599

96100
$validator->validate($entity, null, array());
97101
}
102+
103+
public function testCollectionConstraintValidateAllGroupsForNestedConstraints()
104+
{
105+
$this->metadata->addPropertyConstraint('data', new Collection(array('fields' => array(
106+
'one' => array(new NotBlank(array('groups' => 'one')), new Length(array('min' => 2, 'groups' => 'two'))),
107+
'two' => array(new NotBlank(array('groups' => 'two'))),
108+
))));
109+
110+
$entity = new Entity();
111+
$entity->data = array('one' => 't', 'two' => '');
112+
113+
$violations = $this->validator->validate($entity, null, array('one', 'two'));
114+
115+
$this->assertCount(2, $violations);
116+
$this->assertInstanceOf(Length::class, $violations->get(0)->getConstraint());
117+
$this->assertInstanceOf(NotBlank::class, $violations->get(1)->getConstraint());
118+
}
119+
120+
public function testAllConstraintValidateAllGroupsForNestedConstraints()
121+
{
122+
$this->metadata->addPropertyConstraint('data', new All(array('constraints' => array(
123+
new NotBlank(array('groups' => 'one')),
124+
new Length(array('min' => 2, 'groups' => 'two')),
125+
))));
126+
127+
$entity = new Entity();
128+
$entity->data = array('one' => 't', 'two' => '');
129+
130+
$violations = $this->validator->validate($entity, null, array('one', 'two'));
131+
132+
$this->assertCount(2, $violations);
133+
$this->assertInstanceOf(NotBlank::class, $violations->get(0)->getConstraint());
134+
$this->assertInstanceOf(Length::class, $violations->get(1)->getConstraint());
135+
}
98136
}

Validator/RecursiveContextualValidator.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\Validator\Validator;
1313

1414
use Symfony\Component\Validator\Constraint;
15+
use Symfony\Component\Validator\Constraints\Composite;
1516
use Symfony\Component\Validator\Constraints\GroupSequence;
1617
use Symfony\Component\Validator\ConstraintValidatorFactoryInterface;
1718
use Symfony\Component\Validator\Context\ExecutionContext;
@@ -787,6 +788,10 @@ private function validateInGroup($value, $cacheKey, MetadataInterface $metadata,
787788
if (null !== $cacheKey) {
788789
$constraintHash = spl_object_hash($constraint);
789790

791+
if ($constraint instanceof Composite) {
792+
$constraintHash .= $group;
793+
}
794+
790795
if ($context->isConstraintValidated($cacheKey, $constraintHash)) {
791796
continue;
792797
}

0 commit comments

Comments
 (0)