mercredi 5 août 2015

Symfony2 FormIntegrationTestCase data is not changed in PRE_SUBMIT

Let's assume I have a form with two fields of type 'entity' and 'text'.

In my form I have PRE_SUBMIT listener, which changes values. It simply looks like this:

public function preSubmit(FormEvent $event)
{
    $data = $event->getData();

    $data['entityFiled'] = new SomeEntity();
    $data['textFiled'] = 'some_text';
    $event->setData($data);
}

The problem is in my FormIntegration test.

public function testSubmit($defaultData, $submittedData, $expectedData)
{
    $form = $this->factory->create($this->type, $defaultData, []);

    $this->assertEquals($defaultData, $form->getData());

    $form->submit($submittedData);
    $this->assertTrue($form->isValid());
    $this->assertEquals($expectedData, $form->getData());
}

Here $form->getData() should return properties with the updated in PRE_SUBMIT data, but only text field seems to be changed. Entity field is null there, as it is by default.

This happens only in FormIntegration test, functional tests works well.

Aucun commentaire:

Enregistrer un commentaire