Symfony 2 - PHPUnit - 传递 $options 以形成测试
Symfony 2 - PHPUnit - pass $options to form test
我正在将我的 symfony2 应用程序传递给 PHPUnit,我在表单测试中遇到了一些问题。在我的表单中,我有一个 choice
列表,我通过使用 $options
的控制器数组选择来填充此列表,如下所示:
//Controller
$form = $this->createForm(new AdddocType(), array(
'docdata' => $myarray,
));
//Form
->add('myfield', 'choice', array(
'choices' => $options['data']['docdata'],
'multiple' => false,
'required' => true,
'expanded' => false,
))
这是我的 PHPUnit 测试:
public function testaddContact()
{
$formData = array(
'myfield' => 10,
...
...
);
$type = new AdddocType();
$form = $this->factory->create($type);
$form->submit($formData);
$this->assertTrue($form->isSynchronized());
}
当我通过 PHPUnit 时,代码在我的 formType 中的这一行停止:
'choices' => $options['data']['docdata'],
我的问题是:如何在我的 PHPUnit 测试中通过 $options
?
谢谢
可以在create()
的第三个参数中传递选项。不难发现...
我正在将我的 symfony2 应用程序传递给 PHPUnit,我在表单测试中遇到了一些问题。在我的表单中,我有一个 choice
列表,我通过使用 $options
的控制器数组选择来填充此列表,如下所示:
//Controller
$form = $this->createForm(new AdddocType(), array(
'docdata' => $myarray,
));
//Form
->add('myfield', 'choice', array(
'choices' => $options['data']['docdata'],
'multiple' => false,
'required' => true,
'expanded' => false,
))
这是我的 PHPUnit 测试:
public function testaddContact()
{
$formData = array(
'myfield' => 10,
...
...
);
$type = new AdddocType();
$form = $this->factory->create($type);
$form->submit($formData);
$this->assertTrue($form->isSynchronized());
}
当我通过 PHPUnit 时,代码在我的 formType 中的这一行停止:
'choices' => $options['data']['docdata'],
我的问题是:如何在我的 PHPUnit 测试中通过 $options
?
谢谢
可以在create()
的第三个参数中传递选项。不难发现...