From f71e2a8c7a63c2e62eacc2076ec86a3f9283d21c Mon Sep 17 00:00:00 2001 From: Chris Tickner Date: Tue, 10 Jul 2012 03:48:09 -0300 Subject: [PATCH] [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 --- src/Symfony/Component/Form/FormBuilder.php | 2 +- src/Symfony/Component/Form/Tests/FormBuilderTest.php | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/Form/FormBuilder.php b/src/Symfony/Component/Form/FormBuilder.php index 51fc2cbe9d..be04e66bc3 100644 --- a/src/Symfony/Component/Form/FormBuilder.php +++ b/src/Symfony/Component/Form/FormBuilder.php @@ -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); } diff --git a/src/Symfony/Component/Form/Tests/FormBuilderTest.php b/src/Symfony/Component/Form/Tests/FormBuilderTest.php index 52dcebc46f..42d4317459 100644 --- a/src/Symfony/Component/Form/Tests/FormBuilderTest.php +++ b/src/Symfony/Component/Form/Tests/FormBuilderTest.php @@ -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())