فهرست منبع

merged symfony/form-simplification

Fabien Potencier 14 سال پیش
والد
کامیت
f3cafcb355
2فایلهای تغییر یافته به همراه12 افزوده شده و 22 حذف شده
  1. 6 20
      src/Symfony/Component/Form/FormBuilder.php
  2. 6 2
      tests/Symfony/Tests/Component/Form/FormBuilderTest.php

+ 6 - 20
src/Symfony/Component/Form/FormBuilder.php

@@ -554,32 +554,18 @@ class FormBuilder
      * @param array                     $options The options
      *
      * @return FormBuilder The builder
-     *
-     * @throws FormException if the data class is not set when creating a property builder
      */
     public function create($name, $type = null, array $options = array())
     {
-        if (null !== $type) {
-            $builder = $this->getFormFactory()->createNamedBuilder(
-                $type,
-                $name,
-                null,
-                $options
-            );
-        } else {
-            if (!$this->dataClass) {
-                throw new FormException(sprintf('The "%s" type cannot be guessed as the data class is not set. Provide the type manually (\'text\', \'password\', ...) or set the data class.', $name));
-            }
+        if (null === $type && !$this->dataClass) {
+            $type = 'text';
+        }
 
-            $builder = $this->getFormFactory()->createBuilderForProperty(
-                $this->dataClass,
-                $name,
-                null,
-                $options
-            );
+        if (null !== $type) {
+            return $this->getFormFactory()->createNamedBuilder($type, $name, null, $options);
         }
 
-        return $builder;
+        return $this->getFormFactory()->createBuilderForProperty($this->dataClass, $name, null, $options);
     }
 
     /**

+ 6 - 2
tests/Symfony/Tests/Component/Form/FormBuilderTest.php

@@ -97,8 +97,12 @@ class FormBuilderTest extends \PHPUnit_Framework_TestCase
 
     public function testCreateNoTypeNoDataClass()
     {
-        $this->setExpectedException('Symfony\Component\Form\Exception\FormException', 'The "foo" type cannot be guessed as the data class is not set. Provide the type manually (\'text\', \'password\', ...) or set the data class.');
-        $this->builder->create('foo');
+        $this->factory->expects($this->once())
+                ->method('createNamedBuilder')
+                ->with('text', 'foo', null, array())
+        ;
+
+        $builder = $this->builder->create('foo');
     }
 
     public function testGetUnknown()