merged branch willdurand/add-all-method-to-form-builder (PR #3886)

Commits
-------

be2456b [Form] [Tests] Used assertCount()
4120f13 [Form] Added all() method to the FormBuilder class

Discussion
----------

[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(),
...).

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

by bschussek at 2012-04-12T09:54:04Z

👍
This commit is contained in:
Fabien Potencier 2012-04-13 06:56:27 +02:00
commit cec8fed31c
2 changed files with 26 additions and 0 deletions

View File

@ -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.
*

View File

@ -110,6 +110,22 @@ class FormBuilderTest extends \PHPUnit_Framework_TestCase
$this->assertTrue($this->builder->has('foo'));
}
public function testAll()
{
$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->assertCount(1, $children);
$this->assertArrayHasKey('foo', $children);
$foo = $children['foo'];
$this->assertEquals('text', $foo['type']);
}
public function testAddFormType()
{
$this->assertFalse($this->builder->has('foo'));