[Form] Fix php warning on invalid FormFactory::createBuilder() argument

This commit is contained in:
Alexander Schwenn 2015-09-17 23:09:48 +02:00
parent 327c647be5
commit b5599a5897
2 changed files with 12 additions and 1 deletions

View File

@ -76,9 +76,11 @@ class FormFactory implements FormFactoryInterface
} elseif ($type instanceof FormTypeInterface) {
// BC
$typeName = $type->getName();
} else {
} elseif (is_string($type)) {
// BC
$typeName = $type;
} else {
throw new UnexpectedTypeException($type, 'string, Symfony\Component\Form\ResolvedFormTypeInterface or Symfony\Component\Form\FormTypeInterface');
}
if (null === $name) {

View File

@ -293,6 +293,15 @@ class FormFactoryTest extends \PHPUnit_Framework_TestCase
$this->factory->createNamedBuilder('name', new \stdClass());
}
/**
* @expectedException \Symfony\Component\Form\Exception\UnexpectedTypeException
* @expectedExceptionMessage Expected argument of type "string, Symfony\Component\Form\ResolvedFormTypeInterface or Symfony\Component\Form\FormTypeInterface", "stdClass" given
*/
public function testCreateThrowsUnderstandableException()
{
$this->factory->create(new \stdClass());
}
public function testCreateUsesTypeNameIfTypeGivenAsString()
{
$options = array('a' => '1', 'b' => '2');