Skip to content

Commit

Permalink
merged branch willdurand/add-all-method-to-form-builder (PR symfony#3886
Browse files Browse the repository at this point in the history
)

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

:+1:
  • Loading branch information
fabpot committed Apr 13, 2012
2 parents b2af6b4 + be2456b commit cec8fed
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/Symfony/Component/Form/FormBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,16 @@ public function has($name)
return isset($this->children[$name]);
}

/**
* Returns the children.
*
* @return array
*/
public function all()
{
return $this->children;
}

/**
* Creates the form.
*
Expand Down
16 changes: 16 additions & 0 deletions src/Symfony/Component/Form/Tests/FormBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,22 @@ public function testAdd()
$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'));
Expand Down

0 comments on commit cec8fed

Please sign in to comment.