Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[Form] Deleted references in FormBuilder::getFormConfig() to improve …

…performance
  • Loading branch information...
commit 3ba72b7fdf360fe9a802781d60cd9a6e8ca298f1 1 parent 5486bbb
@webmozart webmozart authored
Showing with 39 additions and 0 deletions.
  1. +15 −0 FormBuilder.php
  2. +24 −0 Tests/FormBuilderTest.php
View
15 FormBuilder.php
@@ -205,6 +205,21 @@ public function count()
/**
* {@inheritdoc}
*/
+ public function getFormConfig()
+ {
+ $config = parent::getFormConfig();
+
+ $config->factory = null;
+ $config->parent = null;
+ $config->children = array();
+ $config->unresolvedChildren = array();
+
+ return $config;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
public function getForm()
{
$this->resolveChildren();
View
24 Tests/FormBuilderTest.php
@@ -232,6 +232,30 @@ public function testGetParentForCreatedBuilder()
$this->builder->create('bar', 'text');
}
+ public function testGetFormConfigErasesReferences()
+ {
+ $builder = new FormBuilder('name', null, $this->dispatcher, $this->factory);
+ $builder->setParent(new FormBuilder('parent', null, $this->dispatcher, $this->factory));
+ $builder->add(new FormBuilder('child', null, $this->dispatcher, $this->factory));
+
+ $config = $builder->getFormConfig();
+ $reflClass = new \ReflectionClass($config);
+ $factory = $reflClass->getProperty('factory');
+ $parent = $reflClass->getProperty('parent');
+ $children = $reflClass->getProperty('children');
+ $unresolvedChildren = $reflClass->getProperty('unresolvedChildren');
+
+ $factory->setAccessible(true);
+ $parent->setAccessible(true);
+ $children->setAccessible(true);
+ $unresolvedChildren->setAccessible(true);
+
+ $this->assertNull($factory->getValue($config));
+ $this->assertNull($parent->getValue($config));
+ $this->assertEmpty($children->getValue($config));
+ $this->assertEmpty($unresolvedChildren->getValue($config));
+ }
+
private function getFormBuilder($name = 'name')
{
$mock = $this->getMockBuilder('Symfony\Component\Form\FormBuilder')
Please sign in to comment.
Something went wrong with that request. Please try again.