Skip to content

Commit

Permalink
Merge branch 'master' of github.com:PUGX/formable
Browse files Browse the repository at this point in the history
  • Loading branch information
simodima committed Jul 15, 2015
2 parents 1cae3c0 + 10e39dc commit 94db4b4
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/Generator/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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()])
);
Expand Down
21 changes: 21 additions & 0 deletions src/Tests/Integration/DTOs/TestNoPropertyNameDTO.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php
/**
* Created by PhpStorm.
* User: lucagiacalone
* Date: 14/07/15
* Time: 17:53
*/

namespace Formable\Tests\Integration\DTOs;

use Formable\Definition\Formable;

class TestNoPropertyNameDTO
{
/**
* @var
*
* @Formable(dataType="text", options={})
*/
public $name;
}
10 changes: 10 additions & 0 deletions src/Tests/Integration/GeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Formable\Tests\Integration\DTOs\TestDoubleNestedDTO;
use Formable\Tests\Integration\DTOs\TestMoneyDTO;
use Formable\Tests\Integration\DTOs\TestNestedDTO;
use Formable\Tests\Integration\DTOs\TestNoPropertyNameDTO;
use Formable\Tests\Integration\DTOs\TestPreFilledDTO;
use Formable\Tests\Kernel\AppKernel;
use spec\Formable\Generator\TestDTO;
Expand Down Expand Up @@ -55,6 +56,15 @@ public function it_should_generate_a_form()
$this->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
*/
Expand Down

0 comments on commit 94db4b4

Please sign in to comment.