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

[Form] Failing test for empty_data option BC break #3685

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
[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.
  • Loading branch information
jmikola committed Mar 23, 2012
commit 69c9fef3a0bae4efa891a28f823f92658b3373fc
31 changes: 31 additions & 0 deletions 31 tests/Symfony/Tests/Component/Form/Fixtures/AuthorType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace Symfony\Tests\Component\Form\Fixtures;

use Symfony\Component\Form\FormInterface;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilder;

class AuthorType extends AbstractType
{
public function buildForm(FormBuilder $builder, array $options)
{
$builder
->add('firstName')
->add('lastName')
;
}

public function getName()
{
return 'author';
}

public function getDefaultOptions(array $options)
{
return array(
'data_class' => 'Symfony\Tests\Component\Form\Fixtures\Author',
);
}
}
16 changes: 16 additions & 0 deletions 16 tests/Symfony/Tests/Component/Form/FormFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
use Symfony\Component\Form\Guess\Guess;
use Symfony\Component\Form\Guess\ValueGuess;
use Symfony\Component\Form\Guess\TypeGuess;
use Symfony\Tests\Component\Form\Fixtures\Author;
use Symfony\Tests\Component\Form\Fixtures\AuthorType;
use Symfony\Tests\Component\Form\Fixtures\TestExtension;
use Symfony\Tests\Component\Form\Fixtures\FooType;
use Symfony\Tests\Component\Form\Fixtures\FooTypeBarExtension;
Expand Down Expand Up @@ -531,6 +533,20 @@ public function testUnknownOption()
$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')
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.