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 04925da

Browse filesBrowse files
committed
[Form] Check the type of the constraints option
Signed-off-by: Alexander M. Turek <me@derrabus.de>
1 parent 055b38f commit 04925da
Copy full SHA for 04925da

File tree

Expand file treeCollapse file tree

2 files changed

+16
-0
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+16
-0
lines changed

‎src/Symfony/Component/Form/Extension/Validator/Type/FormTypeValidatorExtension.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Extension/Validator/Type/FormTypeValidatorExtension.php
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Symfony\Component\Form\FormRendererInterface;
1919
use Symfony\Component\OptionsResolver\Options;
2020
use Symfony\Component\OptionsResolver\OptionsResolver;
21+
use Symfony\Component\Validator\Constraint;
2122
use Symfony\Component\Validator\Validator\ValidatorInterface;
2223
use Symfony\Contracts\Translation\TranslatorInterface;
2324

@@ -66,6 +67,7 @@ public function configureOptions(OptionsResolver $resolver)
6667
'allow_extra_fields' => false,
6768
'extra_fields_message' => 'This form should not contain extra fields.',
6869
]);
70+
$resolver->setAllowedTypes('constraints', [Constraint::class, Constraint::class.'[]']);
6971
$resolver->setAllowedTypes('legacy_error_messages', 'bool');
7072
$resolver->setDeprecated('legacy_error_messages', 'symfony/form', '5.2', function (Options $options, $value) {
7173
if (true === $value) {

‎src/Symfony/Component/Form/Tests/Extension/Validator/Type/FormTypeValidatorExtensionTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Tests/Extension/Validator/Type/FormTypeValidatorExtensionTest.php
+14Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use Symfony\Component\Form\Tests\Extension\Core\Type\FormTypeTest;
2020
use Symfony\Component\Form\Tests\Extension\Core\Type\TextTypeTest;
2121
use Symfony\Component\Form\Tests\Fixtures\Author;
22+
use Symfony\Component\OptionsResolver\Exception\InvalidOptionsException;
2223
use Symfony\Component\Validator\Constraints\GroupSequence;
2324
use Symfony\Component\Validator\Constraints\Length;
2425
use Symfony\Component\Validator\Constraints\NotBlank;
@@ -61,6 +62,19 @@ public function testValidConstraint()
6162
$this->assertSame([$valid], $form->getConfig()->getOption('constraints'));
6263
}
6364

65+
public function testValidConstraintsArray()
66+
{
67+
$form = $this->createForm(['constraints' => [$valid = new Valid()]]);
68+
69+
$this->assertSame([$valid], $form->getConfig()->getOption('constraints'));
70+
}
71+
72+
public function testInvalidConstraint()
73+
{
74+
$this->expectException(InvalidOptionsException::class);
75+
$this->createForm(['constraints' => ['foo' => 'bar']]);
76+
}
77+
6478
public function testGroupSequenceWithConstraintsOption()
6579
{
6680
$form = Forms::createFormFactoryBuilder()

0 commit comments

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