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