I'm trying to test my form. I read that :
But I get a null
exception
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 line buggy is :
$form = $this->factory->create(MediaType::class);
But how can I resolve ?
I launch :
phpunit tests/unit/Form/MediaTypeTest.php
Or via codeception :
php vendor/bin/codecept run unit Form/MediaTypeTest.php
Any idea ?
Symfony\Component\Form\Test\TypeTestCase instead
ofSymfony\Component\Form\Tests\Extension\Validator\Type\TypeTestCase
. Let me know – Matteo