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]".

图片转代码服务由CSDN问答提供 功能建议

我的Symfony项目中有一个名单实体,其中包含两个日期时间字段。

FormType上的输入字段使用两个single_text框,一个用于时间日期。

  $ 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”,
)
   
 
 

任何人都可以告诉我如何 格式化我在单元测试中传递给该字段的日期。

我最接近的是

  $ client =  static :: createClient(array(),array(
'PHP_AUTH_USER'=>'username',
'PHP_AUTH_PW'=>'password',
)); 
 
 $ date = new \ DateTime  ('2015-04-01 08:00'); 
 
 //浏览到 一个exsting服务用户并为该记录添加一个名单
 $ crawler = $ client-> request('GET','/ serviceuser / 2'); 
 $ crawler = $ client-> click($ crawler-  > selectLink('添加新名册') - > link()); 
 
 //填写表单并提交
 $ form = $ crawler-> selectButton('Create') - >  form(array(
'appbundle_roster [serviceUserId]'=>  2,
'appbundle_roster [rosterStartTime]'=>  $ date->格式('yyyy-MM-dd'),
 
'appbundle_roster [rosterStatus]'=>  1,
'appbundle_roster [numberResourcesNeeded]'=>  2,
'appbundle_roster [customerId]'=>  2,
)); 
   
 
 

此错误失败

  AppBundle \ Tests \ Controller \ RosterControllerTest  :: testCompleteScenario 
 InvalidArgumentException:无法在复合字段“appbundle_roster [rosterStartTime]”上设置值。
   
 
  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

相关推荐 更多相似问题