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

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
This commit is contained in:
Chris Tickner 2012-07-10 03:48:09 -03:00
parent 5f6a17b8cc
commit f71e2a8c7a
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())