/**
  * @dataProvider dataTestParse
  */
 public function testParse($typeName, $expected)
 {
     $resolvedTypeFactory = new ResolvedFormTypeFactory();
     $formFactoryBuilder = new FormFactoryBuilder();
     $formFactoryBuilder->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);
 }
 /**
  * @dataProvider dataTestParseWithoutEntity
  */
 public function testParseWithoutEntity($typeName, $expected)
 {
     $resolvedTypeFactory = new ResolvedFormTypeFactory();
     $formFactoryBuilder = new FormFactoryBuilder();
     $formFactoryBuilder->setResolvedTypeFactory($resolvedTypeFactory);
     $formFactoryBuilder->addExtension(new CoreExtension());
     $formFactoryBuilder->addTypeExtension(new DescriptionFormTypeExtension());
     $formFactory = $formFactoryBuilder->getFormFactory();
     $formTypeParser = new FormTypeParser($formFactory, $entityToChoice = false);
     set_error_handler(array('Nelmio\\ApiDocBundle\\Tests\\WebTestCase', 'handleDeprecation'));
     trigger_error('test', E_USER_DEPRECATED);
     $output = $formTypeParser->parse($typeName);
     restore_error_handler();
     $this->assertEquals($expected, $output);
 }
Exemple #3
0
 /**
  * {@inheritdoc}
  */
 public function parse(array $input)
 {
     $formTypeOutput = $this->jmsMetadataParser->parse($input);
     $formType = $this->formFactory->create($input['class'], null, $input['options']);
     $input['class'] = $formType->getConfig()->getOption('data_class');
     $entityMetadata = $this->getEntityMetadata($input['class']);
     $validationOutput = $this->validationParser->parse($input);
     /** @var Form $item */
     foreach ($formType->all() as $item) {
         $key = $item->getName();
         $camelCasedKey = $item->getConfig()->getOption('property_path') ?: $key;
         if (!isset($validationOutput[$camelCasedKey])) {
             continue;
         }
         $format = $this->getFormat($item, $validationOutput, $camelCasedKey);
         $dataType = $this->getType($item, $validationOutput, $camelCasedKey);
         $formTypeOutput[$key]['description'] = $this->getDescription($entityMetadata->getProperty($camelCasedKey));
         $formTypeOutput[$key]['format'] = $format;
         $formTypeOutput[$key]['required'] = $validationOutput[$camelCasedKey]['required'];
         $formTypeOutput[$key]['dataType'] = $dataType;
     }
     return $formTypeOutput;
 }