diff --git a/Parser/FormTypeParser.php b/Parser/FormTypeParser.php index ecace3f..6519c03 100644 --- a/Parser/FormTypeParser.php +++ b/Parser/FormTypeParser.php @@ -11,8 +11,8 @@ namespace Nelmio\ApiDocBundle\Parser; +use Symfony\Component\Form\Exception\UnexpectedTypeException; use Symfony\Component\OptionsResolver\Exception\MissingOptionsException; -use Symfony\Component\Form\FormRegistry; use Symfony\Component\Form\FormFactoryInterface; use Symfony\Component\Form\Exception\FormException; @@ -38,10 +38,9 @@ class FormTypeParser implements ParserInterface 'country' => 'string', ); - public function __construct(FormFactoryInterface $formFactory, FormRegistry $formRegistry) + public function __construct(FormFactoryInterface $formFactory) { $this->formFactory = $formFactory; - $this->formRegistry = $formRegistry; } /** @@ -165,8 +164,10 @@ class FormTypeParser implements ParserInterface return $this->formFactory->create($type); } - if ($this->formRegistry->hasType($item)) { + try { return $this->formFactory->create($item); + } catch (UnexpectedTypeException $e) { + // nothing } } } diff --git a/Tests/Fixtures/Form/CollectionType.php b/Tests/Fixtures/Form/CollectionType.php new file mode 100644 index 0000000..1d16dbc --- /dev/null +++ b/Tests/Fixtures/Form/CollectionType.php @@ -0,0 +1,35 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Nelmio\ApiDocBundle\Tests\Fixtures\Form; + +use Symfony\Component\Form\AbstractType; +use Symfony\Component\Form\FormBuilderInterface; +use Symfony\Component\OptionsResolver\OptionsResolverInterface; + +class CollectionType extends AbstractType +{ + /** + * {@inheritdoc} + */ + public function buildForm(FormBuilderInterface $builder, array $options) + { + $builder + ->add('a', 'collection', array('type' => 'text')) + ->add('b', 'collection', array('type' => new TestType())) + ; + } + + public function getName() + { + return 'collection_type'; + } +} diff --git a/Tests/Parser/FormTypeParserTest.php b/Tests/Parser/FormTypeParserTest.php new file mode 100644 index 0000000..5c6f98a --- /dev/null +++ b/Tests/Parser/FormTypeParserTest.php @@ -0,0 +1,70 @@ +setResolvedTypeFactory($resolvedTypeFactory); + $formFactoryBuilder->addExtension(new CoreExtension()); + $formFactoryBuilder->addTypeExtension(new DescriptionFormTypeExtension()); + $formFactory = $formFactoryBuilder->getFormFactory(); + $formTypeParser = new FormTypeParser($formFactory); + $output = $formTypeParser->parse($typeName); + + $this->assertEquals($expected, $output); + } + + public function dataTestParse() + { + return array( + array('Nelmio\ApiDocBundle\Tests\Fixtures\Form\TestType', array( + 'a' => array( + 'dataType' => 'string', + 'required' => true, + 'description' => 'A nice description', + 'readonly' => false + ), + 'b' => array( + 'dataType' => 'string', + 'required' => true, + 'description' => '', + 'readonly' => false + ), + 'c' => array( + 'dataType' => 'boolean', + 'required' => true, + 'description' => '', + 'readonly' => false + )) + ), + array('Nelmio\ApiDocBundle\Tests\Fixtures\Form\CollectionType', array( + 'a' => array( + 'dataType' => 'array of strings', + 'required' => true, + 'description' => '', + 'readonly' => false + ), 'b' => array( + 'dataType' => 'string', + 'required' => true, + 'description' => '', + 'readonly' => false + )) + ), + ); + } +}