diff --git a/src/Generator/Generator.php b/src/Generator/Generator.php index 1ab80dd..9481471 100644 --- a/src/Generator/Generator.php +++ b/src/Generator/Generator.php @@ -63,6 +63,8 @@ private function createFormBuilderForObject(\ReflectionClass $reflectionObject, /** @var Formable $annotation */ $annotation = $this->reader->getPropertyAnnotation($reflectionProperty, $this->annotationClass); + $name = $annotation->getName() ?: $reflectionProperty->getName(); + if (null !== $annotation) { ++$recognizedFields; @@ -71,13 +73,13 @@ private function createFormBuilderForObject(\ReflectionClass $reflectionObject, $formBuilder->add( $this->createFormBuilderForObject( new \ReflectionClass($class), - $formBuilder->create($annotation->getName(), null, ['compound' => true, 'data_class' => $class]) + $formBuilder->create($name, null, ['compound' => true, 'data_class' => $class]) ) ); } else { $formBuilder->add( - $annotation->getName(), + $name, $annotation->getDataType(), array_merge($annotation->getOptions(), ['property_path' => $annotation->getName()]) ); diff --git a/src/Tests/Integration/DTOs/TestNoPropertyNameDTO.php b/src/Tests/Integration/DTOs/TestNoPropertyNameDTO.php new file mode 100644 index 0000000..7b145ab --- /dev/null +++ b/src/Tests/Integration/DTOs/TestNoPropertyNameDTO.php @@ -0,0 +1,21 @@ +assertInstanceOf('\Symfony\Component\Form\Form', $form); } + /** + * @test + */ + public function it_should_generate_a_form_with_no_property_name() + { + $form = $this->generator->generate(new TestNoPropertyNameDTO()); + $this->assertInstanceOf('\Symfony\Component\Form\Form', $form); + } + /** * @test */