merged branch ChrisTickner/formbuilder_remove_bug_fix (PR #4826)

Commits
-------

f71e2a8 [Form] FormBuilder Bug Fix: remove() was not properly removing children

Discussion
----------

[Form] FormBuilder Bug Fix: remove() was not properly removing children

Bug fix: yes
Feature addition: no
Backwards compatibility break: no
Symfony2 tests pass: yes
Fixes the following tickets: #4803
License of the code: MIT

FormBuilder initially sets unresolved children as NULL, until resolved.
 If FormBuilder::remove() is called before that child is resolved, the
if statement turns false, because isset(null) is false, when it should
be true.  Instead, we should check to see if the key exists, and if so,
process and unset it.

Closes #4803

---------------------------------------------------------------------------

by bschussek at 2012-07-10T07:41:55Z

Can you please add a test covering this case?

---------------------------------------------------------------------------

by ChrisTickner at 2012-07-10T09:43:07Z

Sure, added a test case.  It fails before the patch and passes after.

---------------------------------------------------------------------------

by bschussek at 2012-07-10T09:47:06Z

Thanks. Can you please add a comment to the test with the URL of this PR? Also, please squash your commits into one when your done.

---------------------------------------------------------------------------

by ChrisTickner at 2012-07-10T10:02:16Z

Oops, I deleted the remote branch and re-pushed without realizing we'd lose some history on this PR page.  Live and learn I suppose.

---------------------------------------------------------------------------

by bschussek at 2012-07-10T10:18:20Z

Thanks!
This commit is contained in:
Fabien Potencier 2012-07-10 12:18:45 +02:00
commit 5487a1f076
2 changed files with 10 additions and 1 deletions

View File

@ -144,7 +144,7 @@ class FormBuilder extends FormConfig implements \IteratorAggregate, FormBuilderI
{
unset($this->unresolvedChildren[$name]);
if (isset($this->children[$name])) {
if (array_key_exists($name, $this->children)) {
if ($this->children[$name] instanceof self) {
$this->children[$name]->setParent(null);
}

View File

@ -134,6 +134,15 @@ class FormBuilderTest extends \PHPUnit_Framework_TestCase
$this->assertFalse($this->builder->has('foo'));
}
// https://github.com/symfony/symfony/pull/4826
public function testRemoveAndGetForm()
{
$this->builder->add('foo', 'text');
$this->builder->remove('foo');
$form = $this->builder->getForm();
$this->assertInstanceOf('Symfony\Component\Form\Form', $form);
}
public function testCreateNoTypeNo()
{
$this->factory->expects($this->once())