Php 在Symfony2中使用DomCrawler为选项选择值

Php 在Symfony2中使用DomCrawler为选项选择值,php,symfony,phpunit,Php,Symfony,Phpunit,我正在编写一个小的功能测试,它使用DomCrawler来填写和提交表单。然而,当涉及到填充选项时,我遇到了严重的问题。我怎样才能做到这一点 $crawler = $this->client->request('GET', '/post/new'); $form = $crawler->selectButton('new')->form(); $form['form[name]'] = 'Test'; $form['form[category

我正在编写一个小的功能测试,它使用DomCrawler来填写和提交表单。然而,当涉及到填充选项时,我遇到了严重的问题。我怎样才能做到这一点

    $crawler = $this->client->request('GET', '/post/new');
    $form = $crawler->selectButton('new')->form();
    $form['form[name]'] = 'Test';
    $form['form[category][]'] = '1';
    $crawler = $this->client->submit($form);

不管发生什么事,我总是有一种病态的辩论例外

假设您有一个值为
1
元素,选择它的正确语法是

$form['form[category]']->select('1');
您可以阅读更多关于测试表单的信息