merged branch entering/form-validationlistener-remove-count (PR #8430)
This PR was squashed before being merged into the master branch (closes #8430).
Discussion
----------
[Form] Validation listener remove count()
| Q | A
| ------------- | ---
| Bug fix? | no
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets |
| License | MIT
| Doc PR |
Removing what looks a extra count not needed.
Commits
-------
23a71e5
[Form] Validation listener remove count()
This commit is contained in:
commit
0a894bc800
@ -54,7 +54,6 @@ class ValidationListener implements EventSubscriberInterface
|
|||||||
// Validate the form in group "Default"
|
// Validate the form in group "Default"
|
||||||
$violations = $this->validator->validate($form);
|
$violations = $this->validator->validate($form);
|
||||||
|
|
||||||
if (count($violations) > 0) {
|
|
||||||
foreach ($violations as $violation) {
|
foreach ($violations as $violation) {
|
||||||
// Allow the "invalid" constraint to be put onto
|
// Allow the "invalid" constraint to be put onto
|
||||||
// non-synchronized forms
|
// non-synchronized forms
|
||||||
@ -64,5 +63,4 @@ class ValidationListener implements EventSubscriberInterface
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,7 @@ use Symfony\Component\Form\Extension\Validator\Constraints\Form;
|
|||||||
use Symfony\Component\Form\Extension\Validator\EventListener\ValidationListener;
|
use Symfony\Component\Form\Extension\Validator\EventListener\ValidationListener;
|
||||||
use Symfony\Component\PropertyAccess\PropertyPath;
|
use Symfony\Component\PropertyAccess\PropertyPath;
|
||||||
use Symfony\Component\Validator\ConstraintViolation;
|
use Symfony\Component\Validator\ConstraintViolation;
|
||||||
|
use Symfony\Component\Validator\ConstraintViolationList;
|
||||||
|
|
||||||
class ValidationListenerTest extends \PHPUnit_Framework_TestCase
|
class ValidationListenerTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
@ -142,4 +143,23 @@ class ValidationListenerTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
$this->listener->validateForm(new FormEvent($form, null));
|
$this->listener->validateForm(new FormEvent($form, null));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testValidateWithEmptyViolationList()
|
||||||
|
{
|
||||||
|
$form = $this->getMockForm();
|
||||||
|
$form->expects($this->once())
|
||||||
|
->method('isRoot')
|
||||||
|
->will($this->returnValue(true));
|
||||||
|
|
||||||
|
$this->validator
|
||||||
|
->expects($this->once())
|
||||||
|
->method('validate')
|
||||||
|
->will($this->returnValue(new ConstraintViolationList()));
|
||||||
|
|
||||||
|
$this->violationMapper
|
||||||
|
->expects($this->never())
|
||||||
|
->method('mapViolation');
|
||||||
|
|
||||||
|
$this->listener->validateForm(new FormEvent($form, null));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
namespace Symfony\Component\Form\Tests\Extension\Validator\Type;
|
namespace Symfony\Component\Form\Tests\Extension\Validator\Type;
|
||||||
|
|
||||||
use Symfony\Component\Form\FormInterface;
|
use Symfony\Component\Form\FormInterface;
|
||||||
|
use Symfony\Component\Validator\ConstraintViolationList;
|
||||||
|
|
||||||
class FormTypeValidatorExtensionTest extends TypeTestCase
|
class FormTypeValidatorExtensionTest extends TypeTestCase
|
||||||
{
|
{
|
||||||
@ -69,15 +70,20 @@ class FormTypeValidatorExtensionTest extends TypeTestCase
|
|||||||
|
|
||||||
public function testSubmitValidatesData()
|
public function testSubmitValidatesData()
|
||||||
{
|
{
|
||||||
$builder = $this->factory->createBuilder('form', null, array(
|
$builder = $this->factory->createBuilder(
|
||||||
|
'form',
|
||||||
|
null,
|
||||||
|
array(
|
||||||
'validation_groups' => 'group',
|
'validation_groups' => 'group',
|
||||||
));
|
)
|
||||||
|
);
|
||||||
$builder->add('firstName', 'form');
|
$builder->add('firstName', 'form');
|
||||||
$form = $builder->getForm();
|
$form = $builder->getForm();
|
||||||
|
|
||||||
$this->validator->expects($this->once())
|
$this->validator->expects($this->once())
|
||||||
->method('validate')
|
->method('validate')
|
||||||
->with($this->equalTo($form));
|
->with($this->equalTo($form))
|
||||||
|
->will($this->returnValue(new ConstraintViolationList()));
|
||||||
|
|
||||||
// specific data is irrelevant
|
// specific data is irrelevant
|
||||||
$form->submit(array());
|
$form->submit(array());
|
||||||
|
Reference in New Issue
Block a user