8000 [Form] Failing test for empty_data option BC break · symfony/symfony@cb87ccb · GitHub
[go: up one dir, main page]

Skip to content

Commit cb87ccb

Browse files
jmikolawebmozart
authored andcommitted
[Form] Failing test for empty_data option BC break
This demonstrates the issue described in #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.
1 parent b733045 commit cb87ccb

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
namespace Symfony\Component\Form\Tests\Fixtures;
4+
5+
use Symfony\Component\Form\FormInterface;
6+
7+
use Symfony\Component\Form\AbstractType;
8+
use Symfony\Component\Form\FormBuilder;
9+
10+
class AuthorType extends AbstractType
11+
{
12+
public function buildForm(FormBuilder $builder, array $options)
13+
{
14+
$builder
15+
->add('firstName')
16+
->add('lastName')
17+
;
18+
}
19+
20+
public function getName()
21+
{
22+
return 'author';
23+
}
24+
25+
public function getDefaultOptions()
26+
{
27+
return array(
28+
'data_class' => 'Symfony\Component\Form\Tests\Fixtures\Author',
29+
);
30+
}
31+
}

src/Symfony/Component/Form/Tests/FormFactoryTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
use Symfony\Component\Form\Guess\Guess;
1717
use Symfony\Component\Form\Guess\ValueGuess;
1818
use Symfony\Component\Form\Guess\TypeGuess;
19+
use Symfony\Component\Form\Tests\Fixtures\Author;
20+
use Symfony\Component\Form\Tests\Fixtures\AuthorType;
1921
use Symfony\Component\Form\Tests\Fixtures\TestExtension;
2022
use Symfony\Component\Form\Tests\Fixtures\FooType;
2123
use Symfony\Component\Form\Tests\Fixtures\FooTypeBarExtension;
@@ -539,6 +541,20 @@ public function testUnknownOption()
539541
$factory->createNamedBuilder($type, "text", "value", array("unknown" => "opt"));
540542
}
541543

544+
public function testFieldTypeCreatesDefaultValueForEmptyDataOption()
545+
{
546+
$factory = new FormFactory(array(new \Symfony\Component\Form\Extension\Core\CoreExtension()));
547+
548+
$form = $factory->createNamedBuilder(new AuthorType(), 'author')->getForm();
549+
$form->bind(array('firstName' => 'John', 'lastName' => 'Smith'));
550+
551+
$author = new Author();
552+
$author->firstName = 'John';
553+
$author->setLastName('Smith');
554+
555+
$this->assertEquals($author, $form->getData());
556+
}
557+
542558
private function createMockFactory(array $methods = array())
543559
{
544560
return $this->getMockBuilder('Symfony\Component\Form\FormFactory')

0 commit comments

Comments
 (0)
0