使用 phpunit 6.5.1 symfony 3.4 按钮问题进行功能测试
Functional testing with phpunit 6.5.1 symfony 3.4 button issue
我正在尝试使用 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 是否有问题?
使用以下代码段测试您的表单:
//selectButton accepts the button id|name|text
$form = $crawler->selectButton("logIn")->form();
$form['_username'] = 'AdminAccountKyleTest';
$form['_password'] = 'test';
$client->submit($form);
//follow the form request redirect after login_check
$client->followRedirect();
我正在尝试使用 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 是否有问题?
使用以下代码段测试您的表单:
//selectButton accepts the button id|name|text
$form = $crawler->selectButton("logIn")->form();
$form['_username'] = 'AdminAccountKyleTest';
$form['_password'] = 'test';
$client->submit($form);
//follow the form request redirect after login_check
$client->followRedirect();