【发布时间】:2019-01-14 18:15:28
【问题描述】:
我正在尝试使用 phpunit 测试我的小型 Web 应用程序,但我在提交表单和使用爬虫访问按钮时遇到了困难。 我似乎无法登录,因为节点总是报告为空。我认为问题可能出在提交按钮上,可能试图引用它。
private $client = null;
public function setUp()
{
$this->client = static::createClient();
$this->testlogIn();
}
public function testLogIn()
{
$crawler = $this->client->request('GET', '/login');
$form = $crawler->filter('button#logIn')
->form(
[
'_username' => 'AdminAccountKyleTest',
'_password' => 'test'
],
'POST'
);
$this->client->submit($form);
$this->assertContains('Homepage', $crawler->filter('body > div.main > div > div > div:nth-child(2) > h1')->text());
}
这是按钮的树枝模板:
<button class="btn btn-lg btn-primary btn-block" id="logIn"
type="submit">Sign in</button>
当按钮呈现在树枝中而不是表单上的 SubmitType 时,phpunit 是否有问题?
【问题讨论】:
-
我也试过 $form = $crawler->selectButton('Sign in') 但这也不起作用
标签: php symfony twig phpunit functional-testing