8000 merged branch willdurand/add-all-method-to-form-builder (PR #3886) · hostingnuggets/symfony@cec8fed · GitHub
[go: up one dir, main page]

Skip to content

Commit cec8fed

Browse files
committed
merged branch willdurand/add-all-method-to-form-builder (PR symfony#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 :+1:
2 parents b2af6b4 + be2456b commit cec8fed

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

src/Symfony/Component/Form/FormBuilder.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,16 @@ public function has($name)
643643
return isset($this->children[$name]);
644644
}
645645

646+
/**
647+
* Returns the children.
648+
*
649+
* @return array
650+
*/
651+
public function all()
652+
{
653+
return $this->children;
654+
}
655+
646656
/**
647657
* Creates the form.
648658
*

src/Symfony/Component/Form/Tests/FormBuilderTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,22 @@ public function testAdd()
110110
$this->assertTrue($this->builder->has('foo'));
111111
}
112112

113+
public function testAll()
114+
{
115+
$this->assertCount(0, $this->builder->all());
116+
$this->assertFalse($this->builder->has('foo'));
117+
118+
$this->builder->add('foo', 'text');
119+
$children = $this->builder->all();
120+
121+
$this->assertTrue($this->builder->has('foo'));
122+
$this->assertCount(1, $children);
123+
$this->assertArrayHasKey('foo', $children);
124+
125+
$foo = $children['foo'];
126+
$this->assertEquals('text', $foo['type']);
127+
}
128+
113129
public function testAddFormType()
114130
{
115131
$this->assertFalse($this->builder->has('foo'));

0 commit comments

Comments
 (0)
0