duandange7480 2015-06-30 13:56
浏览 60
已采纳

Symfony 2 - PHPUnit - 传递$ options进行表单测试

i'm passing my symfony2 application to PHPUnit and i have some problems with the form test. In my form i have a choice list and i filled this list by passing from controller array of choices with $options like this :

//Controller
$form = $this->createForm(new AdddocType(), array(
    'docdata' => $myarray,
));

//Form
->add('myfield', 'choice', array(
    'choices' => $options['data']['docdata'],
    'multiple' => false,
    'required' => true,
    'expanded' => false,
))

And here my PHPUnit test :

public function testaddContact()
{
    $formData = array(
        'myfield' => 10,
        ...
        ...
    );

    $type = new AdddocType();
    $form = $this->factory->create($type);
    $form->submit($formData);

    $this->assertTrue($form->isSynchronized());
}

When i pass PHPUnit, the code stop at this line in my formType :

'choices' => $options['data']['docdata'],

My question is : How can i pass the $options in my PHPUnit test ?

Thanks

  • 写回答

1条回答 默认 最新

  • duanche9384 2015-06-30 14:13
    关注

    Options can be passed in the third argument of create(). It isn't very hard to find that out...

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 制裁名单20240508芯片厂商
  • ¥20 易康econgnition精度验证
  • ¥15 线程问题判断多次进入
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接