dsaf415212 2017-04-23 21:11
浏览 52
已采纳

Symfony单元测试表单,使用jquery datepicker表单

I have a Roster entity in my Symfony project which contains two datetime fields.

Input field on FormType uses two single_text boxes, one for date one for time.

 $builder->add('serviceUserId', EntityType::class, array('class' => 'AppBundle:ServiceUser',
            'data' => $options['serviceUser']))
            ->add('rosterStartTime', DateTimeType::class,
                array('date_widget' => "single_text",
                    'time_widget' => "single_text",
                ))
            ->add('rosterEndTime', DateTimeType::class, array('date_widget' => "single_text",
                'time_widget' => "single_text",
            )

Can anyone tell me how to format the date I'm passing to this field in my Unit Test.

The nearest I've gotten is

      $client = static::createClient(array(), array(
        'PHP_AUTH_USER' => 'username',
        'PHP_AUTH_PW' => 'password',
    ));

    $date = new \DateTime('2015-04-01 08:00');

    //browse to an exsting service user and add a roster to that record
    $crawler = $client->request('GET', '/serviceuser/2');
    $crawler = $client->click($crawler->selectLink('Add New Roster')->link());

    // Fill in the form and submit it
    $form = $crawler->selectButton('Create')->form(array(
        'appbundle_roster[serviceUserId]' => 2,
        'appbundle_roster[rosterStartTime]'  => $date->format('yyyy-MM-dd'),

        'appbundle_roster[rosterStatus ]' => 1,
        'appbundle_roster[numberResourcesNeeded]' => 2,
        'appbundle_roster[customerId]' => 2,
    ));

It's failing with this error

     AppBundle\Tests\Controller\RosterControllerTest::testCompleteScenario
     InvalidArgumentException: Cannot set value on a compound field "appbundle_roster[rosterStartTime]".
  • 写回答

1条回答 默认 最新

  • dongying3744 2017-04-23 21:52
    关注

    Can you try this instead:

    'appbundle_roster[rosterStartTime][year]' => 2015,
    'appbundle_roster[rosterStartTime][month]' => 4,
    'appbundle_roster[rosterStartTime][day]' => 1,
    

    It sounds (from error message) like it's rendering as selectable drop-down lists instead of a input text field.

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

报告相同问题?

悬赏问题

  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮