symfony/symfony-docs — pull request #4213 by sarcher (2014-09-08 21:46:35+00:00)
Title: Handle "constraints" option in form unit testing

In the current documentation, although a mocked `ValidatorInterface` is being passed to the `FormTypeValidatorExtension`, the actual `validate()` method in it is returning null. This causes any test against a form type that utilizes the extension's `constraints` option to fail, because of the following code in `Symfony\Component\Form\Extension\Validator\EventListener\ValidationListener`:

```php
// Validate the form in group "Default"
$violations = $this->validator->validate($form);

foreach ($violations as $violation) {
// Allow the "invalid" constraint to be put onto
// non-synchronized forms
$allowNonSynchronized = Form::ERR_INVALID === $violation->getCode();

$this->violationMapper->mapViolation($violation, $form, $allowNonSynchronized);
}
```

Note the `foreach` loop that is expecting an array; currently the mocked object returns null and any test fails.

Since the documentation uses the `ValidatorExtension` as a specific example, I think it would be nice for the example code to handle this case, preventing the user from having to dig deeper into the code to discover the problem.