bug #14715 [Form] Check instance of FormBuilderInterface instead of FormBuilder (dosten)

This PR was merged into the 2.3 branch.

Discussion
----------

[Form] Check instance of FormBuilderInterface instead of FormBuilder

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #14714
| License       | MIT
| Doc PR        | -

Commits
-------

44469d0 Check instance of FormBuilderInterface instead of FormBuilder
This commit is contained in:
Fabien Potencier 2015-05-22 13:54:11 +02:00
commit cc749a67f6
2 changed files with 10 additions and 2 deletions

View File

@ -62,7 +62,7 @@ class FormBuilder extends FormConfigBuilder implements \IteratorAggregate, FormB
throw new BadMethodCallException('FormBuilder methods cannot be accessed anymore once the builder is turned into a FormConfigInterface instance.');
}
if ($child instanceof self) {
if ($child instanceof FormBuilderInterface) {
$this->children[$child->getName()] = $child;
// In case an unresolved child with the same name exists
@ -72,7 +72,7 @@ class FormBuilder extends FormConfigBuilder implements \IteratorAggregate, FormB
}
if (!is_string($child) && !is_int($child)) {
throw new UnexpectedTypeException($child, 'string, integer or Symfony\Component\Form\FormBuilder');
throw new UnexpectedTypeException($child, 'string, integer or Symfony\Component\Form\FormBuilderInterface');
}
if (null !== $type && !is_string($type) && !$type instanceof FormTypeInterface) {

View File

@ -11,7 +11,9 @@
namespace Symfony\Component\Form\Tests;
use Symfony\Component\Form\ButtonBuilder;
use Symfony\Component\Form\FormBuilder;
use Symfony\Component\Form\SubmitButtonBuilder;
class FormBuilderTest extends \PHPUnit_Framework_TestCase
{
@ -154,6 +156,12 @@ class FormBuilderTest extends \PHPUnit_Framework_TestCase
$this->builder->create('foo');
}
public function testAddButton()
{
$this->builder->add(new ButtonBuilder('reset'));
$this->builder->add(new SubmitButtonBuilder('submit'));
}
public function testGetUnknown()
{
$this->setExpectedException('Symfony\Component\Form\Exception\InvalidArgumentException', 'The child with the name "foo" does not exist.');