From 4b7a73c518435d81bb70ec0625969316a2022900 Mon Sep 17 00:00:00 2001 From: "luca.giacalone@gmail.com" Date: Tue, 14 Jul 2015 17:57:59 +0200 Subject: [PATCH] added annotation property 'name' as optional value --- src/Generator/Generator.php | 6 ++++-- .../DTOs/TestNoPropertyNameDTO.php | 21 +++++++++++++++++++ src/Tests/Integration/GeneratorTest.php | 10 +++++++++ 3 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 src/Tests/Integration/DTOs/TestNoPropertyNameDTO.php 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 */