Symfony Form create () test participant function on null

I try to check my form. I read that:

But I get an exception null

class MediaTypeTest extends TypeTestCase
{
    protected function setUp()
    {

    }

    protected function tearDown()
    {
    }

    // tests
    public function testMe()
    {

        $formData = array(
            'test' => 'test',
            'test2' => 'test2',
        );

        $form = $this->factory->create(MediaType::class);

        // submit the data to the form directly
        $form->submit($formData);

        $this->assertTrue($form->isSynchronized());
        $this->assertEquals(new Media(), $form->getData());

        $view = $form->createView();
        $children = $view->children;

        foreach (array_keys($formData) as $key) {
            $this->assertArrayHasKey($key, $children);
        }
    }
}

I understand that the string buggy is:

$ form = $ this → factory → create (MediaType :: class);

But how can I decide?

I run:

phpunit tests / unit / Form / MediaTypeTest.php

Or using the code:

php vendor / bin / codecept unit Form / MediaTypeTest.php

Any idea?

+4
source share
1 answer

The factory object is initialized in the installation method of the parent test class , so you must call parentin setupyour testCase (or remove the empty implementation) .

, inherit:

protected function setUp()
{
    parent::setUp();
}

protected function tearDown()
{
    parent::tearDown();
}

+2

Source: https://habr.com/ru/post/1662158/


All Articles