Permalink
Browse files

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

…terface
  • Loading branch information...
Burgov committed Dec 13, 2011
1 parent e3421a0 commit d97d7e93c0a8192a39e1dda65ddba0564f807e14
@@ -225,8 +225,10 @@ public function createNamedBuilder($type, $name, $data = null, array $options =
}
$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);
@@ -320,6 +320,15 @@ public function testCreateNamedBuilderAddsTypeInstances()
$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();

0 comments on commit d97d7e9

Please sign in to comment.