[Form] [EventListener] fixed sending non array data on submit to ResizeListener

This commit is contained in:
BruceWouaigne 2015-03-05 18:38:17 +01:00 committed by Bernhard Schussek
parent 04ae391318
commit 74d794b6e4
2 changed files with 4 additions and 5 deletions

View File

@ -107,7 +107,7 @@ class ResizeFormListener implements EventSubscriberInterface
} }
if (!is_array($data) && !($data instanceof \Traversable && $data instanceof \ArrayAccess)) { if (!is_array($data) && !($data instanceof \Traversable && $data instanceof \ArrayAccess)) {
throw new UnexpectedTypeException($data, 'array or (\Traversable and \ArrayAccess)'); $data = array();
} }
// Remove all empty rows // Remove all empty rows

View File

@ -167,15 +167,14 @@ class ResizeFormListenerTest extends \PHPUnit_Framework_TestCase
$this->assertFalse($this->form->has('2')); $this->assertFalse($this->form->has('2'));
} }
/** public function testPreSubmitDealsWithNoArrayOrTraversable()
* @expectedException \Symfony\Component\Form\Exception\UnexpectedTypeException
*/
public function testPreSubmitRequiresArrayOrTraversable()
{ {
$data = 'no array or traversable'; $data = 'no array or traversable';
$event = new FormEvent($this->form, $data); $event = new FormEvent($this->form, $data);
$listener = new ResizeFormListener('text', array(), false, false); $listener = new ResizeFormListener('text', array(), false, false);
$listener->preSubmit($event); $listener->preSubmit($event);
$this->assertFalse($this->form->has('1'));
} }
public function testPreSubmitDealsWithNullData() public function testPreSubmitDealsWithNullData()