symfony 4 - InvalidArgumentException:当前节点列表为空

symfony 4 - InvalidArgumentException: The current node list is empty

您好,我正在尝试为表单添加 symfony 单元测试。这是我的代码...

$crawler = $this->client->request('GET', '/admin/user/new');

        $form = $crawler->selectButton('Save')->form(array(
            'user[displayName]' => 'user',
            'user[username]' => 'user@yahoo.com',
            'user[password]' => 'user123',
            'user[phoneNumber]' => '1234789',
            'user[roles]' => 'ROLE_USER',
        ));
        $crawler = $this->client->submit($form);

        $crawler = $this->client->followRedirect();

        $this->assertGreaterThan(
                0, $crawler->filter('html:contains("Le tue modifiche sono state salvate!")')->count()
        );

但我只遇到了这个错误,

InvalidArgumentException: The current node list is empty.

我尝试使用英语但只有当我在我的应用程序中将我的默认语言更改为意大利语时才失败。

看来我需要按钮的意大利语翻译。 当前节点列表为空表示无法获取$form = $crawler->selectButton('Save')节点。由于我已经将界面翻译成意大利语,因此必须将其更改为意大利语。

$form = $crawler->selectButton('Salva')

并且您可以通过 class 或 ID 获取,因此语言无关紧要。

$form = $crawler->filter('button.btn-success')

我保留这个以防有人从中学到一些东西...