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

This commit is contained in:
Bart van den Burg 2011-12-13 11:53:49 +01:00
parent e3421a0b1d
commit d97d7e93c0
2 changed files with 12 additions and 1 deletions

View File

@ -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);

View File

@ -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();