-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Form] FormErrorIterator do not filter only with Constraint causes #28649
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,7 +23,7 @@ class FormErrorIteratorTest extends TestCase | |
/** | ||
* @dataProvider findByCodesProvider | ||
*/ | ||
public function testFindByCodes($code, $violationsCount) | ||
public function testFindByCodesWhenAllCausesAreViolationConstraints($code, $violationsCount) | ||
{ | ||
if (!class_exists(ConstraintViolation::class)) { | ||
$this->markTestSkipped('Validator component required.'); | ||
|
@@ -52,6 +52,43 @@ public function testFindByCodes($code, $violationsCount) | |
$this->assertCount($violationsCount, $specificFormErrors); | ||
} | ||
|
||
/** | ||
* @dataProvider findByCodesProvider | ||
*/ | ||
public function testFindByCodesWhenAllCausesAreVariousObjectsOrSimpleStrings($code, $violationsCount) | ||
{ | ||
if (!class_exists(ConstraintViolation::class)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should not require validator component to test the new feature (we aim for compatibility without it) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FYI this test class on master contains one test case. I have duplicated this test case on the current PR. These lines are the copied code from the previous test case. Your proposal is to remove them from both test cases? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
then i suggest to refactor it a bit, and keep a single |
||
$this->markTestSkipped('Validator component required.'); | ||
} | ||
|
||
$formBuilder = new FormBuilder( | ||
'form', | ||
null, | ||
new EventDispatcher(), | ||
$this->getMockBuilder('Symfony\Component\Form\FormFactoryInterface')->getMock(), | ||
array() | ||
); | ||
|
||
$form = $formBuilder->getForm(); | ||
|
||
$cause = new ConstraintViolation('Error 1!', null, array(), null, '', null, null, 'code1'); | ||
$form->addError(new FormError('Error 1!', null, array(), null, $cause)); | ||
$cause = new class() { | ||
public function __toString() | ||
{ | ||
return 'code1'; | ||
} | ||
}; | ||
|
||
$form->addError(new FormError('Error 2!', null, array(), null, $cause)); | ||
$form->addError(new FormError('Error 3!', null, array(), null, 'code2')); | ||
$formErrors = $form->getErrors(); | ||
|
||
$specificFormErrors = $formErrors->findByCodes($code); | ||
$this->assertInstanceOf(FormErrorIterator::class, $specificFormErrors); | ||
$this->assertCount($violationsCount, $specificFormErrors); | ||
} | ||
|
||
public function findByCodesProvider() | ||
{ | ||
return array( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
id say
in_array((string) $cause, ..