Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commit2319d6a

Browse files
committed
bug#4213 Handle "constraints" option in form unit testing (sarcher)
This PR was submitted for the 2.5 branch but it was merged into the 2.3 branch instead (closes#4213).Discussion----------Handle "constraints" option in form unit testingIn 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.Commits-------3746f07 Fixed return value8251e79 Handle "constraints" option in form unit testing
2 parents9b4b36f +0b2c979 commit2319d6a

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

‎cookbook/form/unit_testing.rst‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,18 +177,22 @@ on other extensions. You need add those extensions to the factory object::
177177
use Symfony\Component\Form\Forms;
178178
use Symfony\Component\Form\FormBuilder;
179179
use Symfony\Component\Form\Extension\Validator\Type\FormTypeValidatorExtension;
180+
use Symfony\Component\Validator\ConstraintViolationList;
180181

181182
class TestedTypeTest extends TypeTestCase
182183
{
183184
protected function setUp()
184185
{
185186
parent::setUp();
187+
188+
$validator = $this->getMock('\Symfony\Component\Validator\ValidatorInterface');
189+
$validator->method('validate')->will($this->returnValue(new ConstraintViolationList()));
186190

187191
$this->factory = Forms::createFormFactoryBuilder()
188192
->addExtensions($this->getExtensions())
189193
->addTypeExtension(
190194
new FormTypeValidatorExtension(
191-
$this->getMock('Symfony\Component\Validator\ValidatorInterface')
195+
$validator
192196
)
193197
)
194198
->addTypeGuesser(

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp