Handle "constraints" option in form unit testing#4213
Closed
sarcher wants to merge 2 commits intosymfony:2.5from
Closed
Handle "constraints" option in form unit testing#4213sarcher wants to merge 2 commits intosymfony:2.5from
sarcher wants to merge 2 commits intosymfony:2.5from
Conversation
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.
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.
cookbook/form/unit_testing.rst
Outdated
Member
There was a problem hiding this comment.
it should actually return a ConstraintViolationList
Replaced `array()` with `new ConstraintViolationList()`.
Contributor
|
I believe this applies all the way back to version 2.3. Can someone verify? Thanks! |
Member
|
@weaverryan yep, it is 2.3+ |
Contributor
|
Thanks for the report and the fix! Cheers Shane! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In the current documentation, although a mocked
ValidatorInterfaceis being passed to theFormTypeValidatorExtension, the actualvalidate()method in it is returning null. This causes any test against a form type that utilizes the extension'sconstraintsoption to fail, because of the following code inSymfony\Component\Form\Extension\Validator\EventListener\ValidationListener:Note the
foreachloop that is expecting an array; currently the mocked object returns null and any test fails.Since the documentation uses the
ValidatorExtensionas 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.