Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit cb87ccb

Browse filesBrowse 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
Copy full SHA for cb87ccb

File tree

2 files changed

+47
-0
lines changed
Filter options

2 files changed

+47
-0
lines changed
+31Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Tests/FormFactoryTest.php
+16Lines 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)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.