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


Choosing a value for a choice using DomCrawler in Symfony2

我正在写一个小的功能测试,它使用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);

不管怎样,我总是收到InvalidArgumentException。

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

$form['form[category]']->select('1');

你可以在这里阅读更多关于测试表格的信息。