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.

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

报告相同问题?

悬赏问题

  • ¥15 如何使用simulink建立一个永磁同步直线电机模型?
  • ¥30 天体光谱图的的绘制并得到星表
  • ¥15 PointNet++的onnx模型只能使用一次
  • ¥20 西南科技大学数字信号处理
  • ¥15 有两个非常“自以为是”烦人的问题急期待大家解决!
  • ¥30 STM32 INMP441无法读取数据
  • ¥15 R语言绘制密度图,一个密度曲线内fill不同颜色如何实现
  • ¥100 求汇川机器人IRCB300控制器和示教器同版本升级固件文件升级包
  • ¥15 用visualstudio2022创建vue项目后无法启动
  • ¥15 x趋于0时tanx-sinx极限可以拆开算吗