【发布时间】:2017-04-12 09:51:06
【问题描述】:
我正在尝试测试我的表单。我读到了:
但我得到一个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);
}
}
}
我知道线路问题是:
$form = $this->factory->create(MediaType::class);
但是我该如何解决呢?
我启动:
phpunit tests/unit/Form/MediaTypeTest.php
或通过代码接收:
php vendor/bin/codecept 运行单元Form/MediaTypeTest.php
有什么想法吗?
【问题讨论】:
-
检查您是否扩展了正确的类:
Symfony\Component\Form\Test\TypeTestCase insteadofSymfony\Component\Form\Tests\Extension\Validator\Type\TypeTestCase。告诉我
标签: php unit-testing symfony phpunit codeception