Parcourir la source

[Form] Fixed: Bubbling errors are caught correctly

Bernhard Schussek il y a 14 ans
Parent
commit
4372bd5dc8

+ 4 - 1
src/Symfony/Component/Form/Form.php

@@ -304,6 +304,10 @@ class Form implements \IteratorAggregate, FormInterface
             $clientData = (string)$clientData;
         }
 
+        // Initialize errors in the very beginning so that we don't lose any
+        // errors added during listeners
+        $this->errors = array();
+
         $event = new DataEvent($this, $clientData);
         $this->dispatcher->dispatch(Events::preBind, $event);
 
@@ -368,7 +372,6 @@ class Form implements \IteratorAggregate, FormInterface
         }
 
         $this->bound = true;
-        $this->errors = array();
         $this->data = $appData;
         $this->normData = $normData;
         $this->clientData = $clientData;

+ 0 - 11
tests/Symfony/Tests/Component/Form/Type/FormTypeTest.php

@@ -276,17 +276,6 @@ class FormTest extends TestCase
         $this->assertTrue($form->isBound());
     }
 
-    public function testHasNoErrorsIfOnlyFieldHasErrors()
-    {
-        $builder = $this->factory->createBuilder('form', 'author');
-        $builder->add('firstName', 'field');
-        $form = $builder->getForm();
-
-        $form->bind(array('firstName' => 'Bernhard'));
-
-        $this->assertFalse($form->hasErrors());
-    }
-
     public function testSetDataUpdatesAllFieldsFromTransformedData()
     {
         $originalAuthor = new Author();