在添加 ArrayCollection 成员的表单功能测试中,有以下语句:
$form['client[members][1][fname]'] = 'Benny';
字段名称已通过 DOM 检查器进行验证。
此行的控制台输出为:
InvalidArgumentException: Unreachable field "members"
G:\Documents\workspace\sym\vendor\symfony\symfony\src\Symfony\Component\DomCrawler\Form.php:459
G:\Documents\workspace\sym\vendor\symfony\symfony\src\Symfony\Component\DomCrawler\Form.php:496
G:\Documents\workspace\sym\vendor\symfony\symfony\src\Symfony\Component\DomCrawler\Form.php:319
G:\Documents\workspace\sym\src\Mana\ClientBundle\Tests\Controller\ClientControllerTest.php:57
应该使用什么方法来测试添加 ArrayCollection 成员?
根据要求进行编辑(注意,开启跟踪重定向):
//link to trigger adding household member form $link = $crawler->selectLink('Add household member')->link(); $crawler = $client->click($link); $form = $crawler->selectButton('Add client')->form(); $form['client[members][1][fname]'] = 'Benny'; $form['client[members][1][dob]'] = "3/12/1999"; $crawler = $client->submit($form); $this->assertTrue($crawler->filter('html:contains("Client View Form")')->count() > 0);