Skip to content

Commit bb35442

Browse files
committed
Check instance of FormBuilderInterface instead of FormBuilder
1 parent 192aadb commit bb35442

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

FormBuilder.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public function add($child, $type = null, array $options = array())
6262
throw new BadMethodCallException('FormBuilder methods cannot be accessed anymore once the builder is turned into a FormConfigInterface instance.');
6363
}
6464

65-
if ($child instanceof self) {
65+
if ($child instanceof FormBuilderInterface) {
6666
$this->children[$child->getName()] = $child;
6767

6868
// In case an unresolved child with the same name exists
@@ -72,7 +72,7 @@ public function add($child, $type = null, array $options = array())
7272
}
7373

7474
if (!is_string($child) && !is_int($child)) {
75-
throw new UnexpectedTypeException($child, 'string, integer or Symfony\Component\Form\FormBuilder');
75+
throw new UnexpectedTypeException($child, 'string, integer or Symfony\Component\Form\FormBuilderInterface');
7676
}
7777

7878
if (null !== $type && !is_string($type) && !$type instanceof FormTypeInterface) {

Tests/FormBuilderTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111

1212
namespace Symfony\Component\Form\Tests;
1313

14+
use Symfony\Component\Form\ButtonBuilder;
1415
use Symfony\Component\Form\FormBuilder;
16+
use Symfony\Component\Form\SubmitButtonBuilder;
1517

1618
class FormBuilderTest extends \PHPUnit_Framework_TestCase
1719
{
@@ -154,6 +156,12 @@ public function testCreateNoTypeNo()
154156
$this->builder->create('foo');
155157
}
156158

159+
public function testAddButton()
160+
{
161+
$this->builder->add(new ButtonBuilder('reset'));
162+
$this->builder->add(new SubmitButtonBuilder('submit'));
163+
}
164+
157165
public function testGetUnknown()
158166
{
159167
$this->setExpectedException('Symfony\Component\Form\Exception\InvalidArgumentException', 'The child with the name "foo" does not exist.');

0 commit comments

Comments
 (0)