symfony/symfony — pull request #4453 by Gator92 (2012-05-30 01:45:59+00:00)
Title: [WIP][Validator][Constraints][Collection] walk constraints by groups

Bug fix: no
Feature addition: yes
Backwards compatibility break: not sure
Symfony2 tests pass: no
Fixes the following tickets: -
Todo: -
License of the code: MIT
Documentation PR: -

This change to the Validator Collection Constraint allows for walking by group. Consider the following use case example for validating postal code lengths:

```
$array = array(
'postal' => '123abc',
//and a bunch of other properties
);

$collection = new Collection(array(
'postal' =>
array (new Size(array('min' => 6, 'max' => 6, 'groups' => array('can'))),
new Size(array('min' => 5, 'max' => 5, 'groups' => array('fin','usa'))),
))); //and a bunch of other constraints

$validator->validateValue($array, $collection, array('Default','can'));
```

In the above code, the Collection constraint would walk all of the constraints for the field 'postal'. This has been changed so only the group(s) specified would be applied, which I beleive is how groups work when validating an object's properties. My concern is that some of the current Collection Constraint tests fail, since they use 'MyGroup' for the validation. The constraint within the test collection belongs to the 'Default' group and is not walked as the test intends. I'm not sure if this is the desired behavior, or if the tests can merely be changed to pass the desired group, as illustrated in the test case diff.