$form =
$formBuilder->
getForm();
$cause =
new ConstraintViolation('Error 1!', null,
[], null, '', null, null, 'code1'
);
$form->
addError(new FormError('Error 1!', null,
[], null,
$cause));
$cause =
new ConstraintViolation('Error 2!', null,
[], null, '', null, null, 'code1'
);
$form->
addError(new FormError('Error 2!', null,
[], null,
$cause));
$cause =
new ConstraintViolation('Error 3!', null,
[], null, '', null, null, 'code2'
);
$form->
addError(new FormError('Error 3!', null,
[], null,
$cause));
$formErrors =
$form->
getErrors();
$specificFormErrors =
$formErrors->
findByCodes($code);
$this->
assertInstanceOf(FormErrorIterator::
class,
$specificFormErrors);
$this->
assertCount($violationsCount,
$specificFormErrors);
} public static function findByCodesProvider() { return [ ['code1', 2
],
[['code1', 'code2'
], 3
],
['code3', 0
],
];
}