我想要開始使用symfony 3的UnitTest過程,我仍然困惑如何做到這一點以及如何測試我的表單,我遵循官方文檔和說明來創建識別TestClass:UnitTest formType Symfony 3
TestFormType:
<?php
namespace Tests\EvalBundle\Form\Type;
use EvalBundle\Form\DepartmentType;
use EvalBundle\Entity\Department;
use Symfony\Component\Form\Test\TypeTestCase;
class DepartmentTypeTest extends TypeTestCase
{
public function testSubmitValidData(){
$formData = array(
'name' => 'test',
);
$departmentType = new DepartmentType();
$form = $this->factory->create($departmentType);
$department = new Department();
$department = fromArray($formData);
$form->submit($formData);
$this->assertTrue($form->isSynchronized());
$this->assertEquals($department, $form->getData());
$view = $form->createView();
$children = $view->children;
foreach (array_keys($formData) as $key) {
$this->assertArrayHasKey($key, $children);
}
}
}
?>
我有一些errors
這些功能:
fromArray,assertTrue,assertEquals,assertArrayHasKey : they are not undefined.
這裏是一個有些熟悉的這可以幫助我理解這個概念嗎?
'fromArray'方法是不存在的。另外,在我看來,表單的測試給出了太多的錯誤。 – jjoselon