From 4120f1392f098e222482280033ef1d8518b20020 Mon Sep 17 00:00:00 2001 From: William DURAND Date: Wed, 11 Apr 2012 19:07:08 +0200 Subject: [PATCH 1/2] [Form] Added all() method to the FormBuilder class In order to perform some introspection on a FormBuilder instance, we need to be able to get its children. Almost everything is accessible in this class, but the children are not. This PR adds a all() method to respect the current API (get(), remove(), ...). --- src/Symfony/Component/Form/FormBuilder.php | 10 ++++++++++ .../Component/Form/Tests/FormBuilderTest.php | 16 ++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/src/Symfony/Component/Form/FormBuilder.php b/src/Symfony/Component/Form/FormBuilder.php index d0caa65d0e..42b94ec4f0 100644 --- a/src/Symfony/Component/Form/FormBuilder.php +++ b/src/Symfony/Component/Form/FormBuilder.php @@ -643,6 +643,16 @@ class FormBuilder return isset($this->children[$name]); } + /** + * Returns the children. + * + * @return array + */ + public function all() + { + return $this->children; + } + /** * Creates the form. * diff --git a/src/Symfony/Component/Form/Tests/FormBuilderTest.php b/src/Symfony/Component/Form/Tests/FormBuilderTest.php index 9860c6bfca..b17aed9e47 100644 --- a/src/Symfony/Component/Form/Tests/FormBuilderTest.php +++ b/src/Symfony/Component/Form/Tests/FormBuilderTest.php @@ -110,6 +110,22 @@ class FormBuilderTest extends \PHPUnit_Framework_TestCase $this->assertTrue($this->builder->has('foo')); } + public function testAll() + { + $this->assertEquals(0, count($this->builder->all())); + $this->assertFalse($this->builder->has('foo')); + + $this->builder->add('foo', 'text'); + $children = $this->builder->all(); + + $this->assertTrue($this->builder->has('foo')); + $this->assertEquals(1, count($children)); + $this->assertArrayHasKey('foo', $children); + + $foo = $children['foo']; + $this->assertEquals('text', $foo['type']); + } + public function testAddFormType() { $this->assertFalse($this->builder->has('foo')); From be2456b19e4100626044504cd2823f157c3e57ee Mon Sep 17 00:00:00 2001 From: William DURAND Date: Wed, 11 Apr 2012 20:45:41 +0200 Subject: [PATCH 2/2] =?UTF-8?q?[Form]=C2=A0[Tests]=20Used=20assertCount()?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Symfony/Component/Form/Tests/FormBuilderTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/Form/Tests/FormBuilderTest.php b/src/Symfony/Component/Form/Tests/FormBuilderTest.php index b17aed9e47..f5276f322e 100644 --- a/src/Symfony/Component/Form/Tests/FormBuilderTest.php +++ b/src/Symfony/Component/Form/Tests/FormBuilderTest.php @@ -112,14 +112,14 @@ class FormBuilderTest extends \PHPUnit_Framework_TestCase public function testAll() { - $this->assertEquals(0, count($this->builder->all())); + $this->assertCount(0, $this->builder->all()); $this->assertFalse($this->builder->has('foo')); $this->builder->add('foo', 'text'); $children = $this->builder->all(); $this->assertTrue($this->builder->has('foo')); - $this->assertEquals(1, count($children)); + $this->assertCount(1, $children); $this->assertArrayHasKey('foo', $children); $foo = $children['foo'];