[Form] Fixed: Form::bind() throws an exception if form is anonymous

This commit is contained in:
Bernhard Schussek 2011-02-06 18:10:50 +01:00 committed by Fabien Potencier
parent 6ff4120784
commit bd3e6c6b49
2 changed files with 14 additions and 0 deletions

View File

@ -713,6 +713,10 @@ class Form extends Field implements \IteratorAggregate, FormInterface
*/
public function bind(Request $request, $data = null)
{
if (!$this->getName()) {
throw new FormException('You cannot bind anonymous forms. Please give this form a name');
}
// Store object from which to read the default values and where to
// write the submitted values
if (null !== $data) {

View File

@ -276,6 +276,16 @@ class FormTest extends \PHPUnit_Framework_TestCase
$this->assertEquals(array('group2'), $childForm->getValidationGroups());
}
/**
* @expectedException Symfony\Component\Form\Exception\FormException
*/
public function testBindThrowsExceptionIfAnonymous()
{
$form = new Form(null, array('validator' => $this->createMockValidator()));
$form->bind($this->createPostRequest());
}
public function testBindValidatesData()
{
$form = new Form('author', array(