symfony 4 表单单元测试不起作用
symfony 4 Form unit test not working
您好,我正在尝试在 symfony 4 中测试表单。这是我的代码,
$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);
$this->assertGreaterThan(
0, $crawler->filter('html:contains("Your changes were saved!")')->count()
);
表单有值,但我得到的只是,
Failed asserting that 0 is greater than 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]' => '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("Your changes were saved!")')->count()
);
您好,我正在尝试在 symfony 4 中测试表单。这是我的代码,
$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);
$this->assertGreaterThan(
0, $crawler->filter('html:contains("Your changes were saved!")')->count()
);
表单有值,但我得到的只是,
Failed asserting that 0 is greater than 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]' => '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("Your changes were saved!")')->count()
);