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.

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

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度