Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 7b7f9ee

Browse filesBrowse files
sarcherweaverryan
authored andcommitted
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. 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.
1 parent 9b4b36f commit 7b7f9ee
Copy full SHA for 7b7f9ee

File tree

Expand file treeCollapse file tree

1 file changed

+4
-1
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+4
-1
lines changed

‎cookbook/form/unit_testing.rst

Copy file name to clipboardExpand all lines: cookbook/form/unit_testing.rst
+4-1Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,12 +183,15 @@ on other extensions. You need add those extensions to the factory object::
183183
protected function setUp()
184184
{
185185
parent::setUp();
186+
187+
$validator = $this->getMock('\Symfony\Component\Validator\ValidatorInterface');
188+
$validator->method('validate')->will($this->returnValue(array()));
186189

187190
$this->factory = Forms::createFormFactoryBuilder()
188191
->addExtensions($this->getExtensions())
189192
->addTypeExtension(
190193
new FormTypeValidatorExtension(
191-
$this->getMock('Symfony\Component\Validator\ValidatorInterface')
194+
$validator
192195
)
193196
)
194197
->addTypeGuesser(

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.