tôi tiếp tục nhận được lỗi sau:Lỗi khi cố gắng chọn biểu mẫu từ trình thu thập thông tin symfony2?
There was 1 error:
1) Caremonk\MainSiteBundle\Tests\Controller\SecurityControllerFunctionalTest::testIndex
InvalidArgumentException: The current node list is empty.
Nhưng khi tôi điều hướng đến localhost/đăng nhập, hình thức của tôi populates với nội dung chính xác. Dòng nói ...
$form = $crawler->selectButton('login')->form();
đang gây ra lỗi. Có gì sai với thử nghiệm của tôi?
thử nghiệm chức năng:
<?php
namespace Caremonk\MainSiteBundle\Tests\Controller;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class SecurityControllerFunctionalTest extends WebTestCase
{
public function testIndex()
{
$client = static::createClient();
$crawler = $client->request('GET', '/login');
$form = $crawler->selectButton('login')->form();
$form['username'] = 'testActive';
$form['password'] = 'passwordActive';
}
}
Twig xem:
{# src/Acme/SecurityBundle/Resources/views/Security/login.html.twig #}
{% if error %}
<div>{{ error.message }}</div>
{% endif %}
<form action="{{ path('caremonk_mainsite_login_check') }}" method="post">
<label for="username">Username:</label>
<input type="text" id="username" name="_username" value="{{ last_username }}" />
<label for="password">Password:</label>
<input type="password" id="password" name="_password" />
{#
If you want to control the URL the user is redirected to on success (more details below)
<input type="hidden" name="_target_path" value="/account" />
#}
<button type="submit">login</button>
</form>
Các thông số cũng đòi hỏi các dấu gạch dưới prepended, ví dụ '' '_username''' – Tjorriemorrie