From cb87ccb28459b9df1afded85b144404279cf2207 Mon Sep 17 00:00:00 2001 From: Jeremy Mikola Date: Fri, 23 Mar 2012 11:21:47 -0400 Subject: [PATCH] [Form] Failing test for empty_data option BC break This demonstrates the issue described in symfony/symfony#3354. FieldType no longer has access to the child type's data_class option, which makes it unable to create the default closure for empty_data. --- .../Form/Tests/Fixtures/AuthorType.php | 31 +++++++++++++++++++ .../Component/Form/Tests/FormFactoryTest.php | 16 ++++++++++ 2 files changed, 47 insertions(+) create mode 100644 src/Symfony/Component/Form/Tests/Fixtures/AuthorType.php diff --git a/src/Symfony/Component/Form/Tests/Fixtures/AuthorType.php b/src/Symfony/Component/Form/Tests/Fixtures/AuthorType.php new file mode 100644 index 0000000000..43569843f0 --- /dev/null +++ b/src/Symfony/Component/Form/Tests/Fixtures/AuthorType.php @@ -0,0 +1,31 @@ +add('firstName') + ->add('lastName') + ; + } + + public function getName() + { + return 'author'; + } + + public function getDefaultOptions() + { + return array( + 'data_class' => 'Symfony\Component\Form\Tests\Fixtures\Author', + ); + } +} diff --git a/src/Symfony/Component/Form/Tests/FormFactoryTest.php b/src/Symfony/Component/Form/Tests/FormFactoryTest.php index 9bd50a1cf6..18c70bc457 100644 --- a/src/Symfony/Component/Form/Tests/FormFactoryTest.php +++ b/src/Symfony/Component/Form/Tests/FormFactoryTest.php @@ -16,6 +16,8 @@ use Symfony\Component\Form\FormFactory; use Symfony\Component\Form\Guess\Guess; use Symfony\Component\Form\Guess\ValueGuess; use Symfony\Component\Form\Guess\TypeGuess; +use Symfony\Component\Form\Tests\Fixtures\Author; +use Symfony\Component\Form\Tests\Fixtures\AuthorType; use Symfony\Component\Form\Tests\Fixtures\TestExtension; use Symfony\Component\Form\Tests\Fixtures\FooType; use Symfony\Component\Form\Tests\Fixtures\FooTypeBarExtension; @@ -539,6 +541,20 @@ class FormFactoryTest extends \PHPUnit_Framework_TestCase $factory->createNamedBuilder($type, "text", "value", array("unknown" => "opt")); } + public function testFieldTypeCreatesDefaultValueForEmptyDataOption() + { + $factory = new FormFactory(array(new \Symfony\Component\Form\Extension\Core\CoreExtension())); + + $form = $factory->createNamedBuilder(new AuthorType(), 'author')->getForm(); + $form->bind(array('firstName' => 'John', 'lastName' => 'Smith')); + + $author = new Author(); + $author->firstName = 'John'; + $author->setLastName('Smith'); + + $this->assertEquals($author, $form->getData()); + } + private function createMockFactory(array $methods = array()) { return $this->getMockBuilder('Symfony\Component\Form\FormFactory')