Ver Fonte

Added a check to see if the type is a string if it's not a FormTypeInterface

Bart van den Burg há 13 anos atrás
pai
commit
d97d7e93c0

+ 3 - 1
src/Symfony/Component/Form/FormFactory.php

@@ -225,8 +225,10 @@ class FormFactory implements FormFactoryInterface
                 }
 
                 $this->addType($type);
-            } else {
+            } elseif (is_string($type)) {
                 $type = $this->getType($type);
+            } else {
+                throw new UnexpectedTypeException($type, 'string or Symfony\Component\Form\FormTypeInterface');
             }
 
             $defaultOptions = $type->getDefaultOptions($options);

+ 9 - 0
tests/Symfony/Tests/Component/Form/FormFactoryTest.php

@@ -320,6 +320,15 @@ class FormFactoryTest extends \PHPUnit_Framework_TestCase
         $this->assertTrue($this->factory->hasType('foo'));
     }
 
+    /**
+     * @expectedException        Symfony\Component\Form\Exception\UnexpectedTypeException
+     * @expectedExceptionMessage Expected argument of type "string or Symfony\Component\Form\FormTypeInterface", "stdClass" given
+     */
+    public function testCreateNamedBuilderThrowsUnderstandableException()
+    {
+        $this->factory->createNamedBuilder(new \StdClass, 'name');
+    }
+
     public function testCreateUsesTypeNameAsName()
     {
         $type = new FooType();