diff --git a/src/Symfony/Component/Form/Extension/Validator/ViolationMapper/ViolationMapper.php b/src/Symfony/Component/Form/Extension/Validator/ViolationMapper/ViolationMapper.php index 4b64386117..14e7b521f1 100644 --- a/src/Symfony/Component/Form/Extension/Validator/ViolationMapper/ViolationMapper.php +++ b/src/Symfony/Component/Form/Extension/Validator/ViolationMapper/ViolationMapper.php @@ -275,6 +275,9 @@ class ViolationMapper implements ViolationMapperInterface */ private function acceptsErrors(FormInterface $form) { - return $this->allowNonSynchronized || $form->isSynchronized(); + // Ignore non-submitted forms. This happens, for example, in PATCH + // requests. + // https://github.com/symfony/symfony/pull/10567 + return $form->isSubmitted() && ($this->allowNonSynchronized || $form->isSynchronized()); } } diff --git a/src/Symfony/Component/Form/Tests/Extension/Validator/ViolationMapper/ViolationMapperTest.php b/src/Symfony/Component/Form/Tests/Extension/Validator/ViolationMapper/ViolationMapperTest.php index 9aa75adaed..74da4aee1c 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Validator/ViolationMapper/ViolationMapperTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Validator/ViolationMapper/ViolationMapperTest.php @@ -212,7 +212,7 @@ class ViolationMapperTest extends \PHPUnit_Framework_TestCase $this->assertCount(0, $grandChild->getErrors(), $grandChild->getName().' should not have an error, but has one'); } - public function testMappingIfNotSubmitted() + public function testAbortMappingIfNotSubmitted() { $violation = $this->getConstraintViolation('children[address].data.street'); $parent = $this->getForm('parent'); @@ -230,12 +230,12 @@ class ViolationMapperTest extends \PHPUnit_Framework_TestCase $this->mapper->mapViolation($violation, $parent); - $this->assertCount(0, $parent->getErrors(), $parent->getName().' should not have an error'); - $this->assertCount(0, $child->getErrors(), $child->getName().' should not have an error'); - $this->assertCount(1, $grandChild->getErrors(), $grandChild->getName().' should have one error'); + $this->assertCount(0, $parent->getErrors(), $parent->getName().' should not have an error, but has one'); + $this->assertCount(0, $child->getErrors(), $child->getName().' should not have an error, but has one'); + $this->assertCount(0, $grandChild->getErrors(), $grandChild->getName().' should not have an error, but has one'); } - public function testDotRuleMappingIfNotSubmitted() + public function testAbortDotRuleMappingIfNotSubmitted() { $violation = $this->getConstraintViolation('data.address'); $parent = $this->getForm('parent'); @@ -255,9 +255,9 @@ class ViolationMapperTest extends \PHPUnit_Framework_TestCase $this->mapper->mapViolation($violation, $parent); - $this->assertCount(0, $parent->getErrors(), $parent->getName().' should not have an error'); - $this->assertCount(0, $child->getErrors(), $child->getName().' should not have an error'); - $this->assertCount(1, $grandChild->getErrors(), $grandChild->getName().' should have an error'); + $this->assertCount(0, $parent->getErrors(), $parent->getName().' should not have an error, but has one'); + $this->assertCount(0, $child->getErrors(), $child->getName().' should not have an error, but has one'); + $this->assertCount(0, $grandChild->getErrors(), $grandChild->getName().' should not have an error, but has one'); } public function provideDefaultTests()