4
我試圖測試我的表單。我看書上說:Symfony Form測試成員函數create null()null
但我得到一個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);
}
}
}
據我所知,線車是:
$形成= $這個 - >出廠>創建(::的MediaType類);
但我該如何解決?
我推出:
PHPUnit測試/單位/表格/ MediaTypeTest.php
或通過codeception:
PHP供應商/斌/ codecept運行單元表/ MediaTypeTest .php
有什麼想法嗎?
檢查要擴展權類:'的Symfony \分量\表格\測試\ Type \ TestCase代替'Symfony \ Component \ Form \ Tests \ Extension \ Validator \ Type \ TypeTestCase'。讓我知道 – Matteo