Skip to content

Commit e2c7c33

Browse files
Johan de Ruijterxabbuh
authored andcommitted
[Form] [Validator] Add failing testcase to demonstrate group sequence issue
When using group sequences on a form, sometimes constraints are ignored even though they should fail.
1 parent 1b68947 commit e2c7c33

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

src/Symfony/Component/Form/Tests/Extension/Validator/Constraints/FormValidatorFunctionalTest.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,34 @@ public function testConstraintsInDifferentGroupsOnSingleField()
232232
$this->assertInstanceOf(Length::class, $errors[0]->getCause()->getConstraint());
233233
}
234234

235+
public function testConstraintsInDifferentGroupsOnSingleFieldWithAdditionalFieldThatHasNoConstraintsAddedBeforeTheFieldWithConstraints()
236+
{
237+
$form = $this->formFactory->create(FormType::class, null, [
238+
'validation_groups' => new GroupSequence(['group1', 'group2']),
239+
])
240+
->add('bar')
241+
->add('foo', TextType::class, [
242+
'constraints' => [
243+
new NotBlank([
244+
'groups' => ['group1'],
245+
]),
246+
new Length([
247+
'groups' => ['group2'],
248+
'max' => 3,
249+
]),
250+
],
251+
]);
252+
$form->submit([
253+
'foo' => '[email protected]',
254+
]);
255+
256+
$errors = $form->getErrors(true);
257+
258+
$this->assertFalse($form->isValid());
259+
$this->assertCount(1, $errors);
260+
$this->assertInstanceOf(Length::class, $errors[0]->getCause()->getConstraint());
261+
}
262+
235263
public function testCascadeValidationToChildFormsUsingPropertyPaths()
236264
{
237265
$form = $this->formFactory->create(FormType::class, null, [

0 commit comments

Comments
 (0)