Pārlūkot izejas kodu

[Form] Fixed: FormBuilder::add() accepts FormTypeInterface instances

Bernhard Schussek 14 gadi atpakaļ
vecāks
revīzija
364b0f5208

+ 3 - 2
src/Symfony/Component/Form/FormBuilder.php

@@ -16,6 +16,7 @@ use Symfony\Component\Form\DataTransformer\DataTransformerInterface;
 use Symfony\Component\Form\Validator\FormValidatorInterface;
 use Symfony\Component\Form\Exception\FormException;
 use Symfony\Component\Form\Exception\UnexpectedTypeException;
+use Symfony\Component\Form\Type\FormTypeInterface;
 use Symfony\Component\EventDispatcher\EventDispatcherInterface;
 use Symfony\Component\EventDispatcher\EventSubscriberInterface;
 
@@ -312,8 +313,8 @@ class FormBuilder
             throw new UnexpectedTypeException($name, 'string');
         }
 
-        if (null !== $type && !is_string($type)) {
-            throw new UnexpectedTypeException($type, 'string');
+        if (null !== $type && !is_string($type) && !$type instanceof FormTypeInterface) {
+            throw new UnexpectedTypeException($type, 'string or Symfony\Component\Form\Type\FormTypeInterface');
         }
 
         $this->children[$name] = array(

+ 7 - 0
tests/Symfony/Tests/Component/Form/FormBuilderTest.php

@@ -59,6 +59,13 @@ class FormBuilderTest extends \PHPUnit_Framework_TestCase
         $this->assertTrue($this->builder->has('foo'));
     }
 
+    public function testAddFormType()
+    {
+        $this->assertFalse($this->builder->has('foo'));
+        $this->builder->add('foo', $this->getMock('Symfony\Component\Form\Type\FormTypeInterface'));
+        $this->assertTrue($this->builder->has('foo'));
+    }
+
     public function testRemove()
     {
         $this->builder->add('foo', 'text');