Skip to content

Commit 41ac18d

Browse files
committed
Merge branch '5.4' into 6.0
* 5.4: [Bridge][Monolog] Add intruction about 'ResetLoggersWorkerSubscriber deprecation' in main UPGRADE-5.4.md [Security] Move TraceableAuthenticator to security-http [Form] Check the type of the constraints option Fixed default behavior
2 parents 603289e + 89a8424 commit 41ac18d

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

Extension/Validator/Type/FormTypeValidatorExtension.php

Lines changed: 2 additions & 1 deletion
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

@@ -64,7 +65,7 @@ public function configureOptions(OptionsResolver $resolver)
6465
'allow_extra_fields' => false,
6566
'extra_fields_message' => 'This form should not contain extra fields.',
6667
]);
67-
68+
$resolver->setAllowedTypes('constraints', [Constraint::class, Constraint::class.'[]']);
6869
$resolver->setNormalizer('constraints', $constraintsNormalizer);
6970
}
7071

Tests/Extension/Validator/Type/FormTypeValidatorExtensionTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Symfony\Component\Form\Tests\Extension\Core\Type\FormTypeTest;
1919
use Symfony\Component\Form\Tests\Extension\Core\Type\TextTypeTest;
2020
use Symfony\Component\Form\Tests\Fixtures\Author;
21+
use Symfony\Component\OptionsResolver\Exception\InvalidOptionsException;
2122
use Symfony\Component\Validator\Constraints\GroupSequence;
2223
use Symfony\Component\Validator\Constraints\Length;
2324
use Symfony\Component\Validator\Constraints\NotBlank;
@@ -59,6 +60,19 @@ public function testValidConstraint()
5960
$this->assertSame([$valid], $form->getConfig()->getOption('constraints'));
6061
}
6162

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

0 commit comments

Comments
 (0)