symfony 4 表单单元测试不起作用

维穆特

嗨,我正在尝试在 symfony 4 中测试表单。这是我的代码,

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

        $form = $crawler->selectButton('Save')->form(array(
            'user[displayName]' => 'user',
            'user[username]' => '[email protected]',
            'user[password]' => 'user123',
            'user[phoneNumber]' => '1234789',
            'user[roles]' => 'ROLE_USER',
        ));
        $crawler = $this->client->submit($form);
        $this->assertGreaterThan(
                0, $crawler->filter('html:contains("Your changes were saved!")')->count()
        );

形式具有价值,但我得到的只是,

断言 0 大于 0 失败。

实际提交时,我收到此警报。

<div class="alert alert-success alert-dismissible">
    Your changes were saved!
</div>

如果有人可以提供帮助

维穆特

似乎需要遵循重定向,因为表单提交总是被重定向。

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

        $form = $crawler->selectButton('Save')->form(array(
            'user[displayName]' => 'user',
            'user[username]' => '[email protected]',
            '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("Your changes were saved!")')->count()
        );

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章