如何使用symfony以PHPunit格式提交表格?
我正在使用symfony 3.0和phpunit 3.7.1。我想通过phpunit文件提交表格。 文件名:abcControllerTest.php如何使用symfony以PHPunit格式提交表格?,phpunit,symfony,webtest,Phpunit,Symfony,Webtest,我正在使用symfony 3.0和phpunit 3.7.1。我想通过phpunit文件提交表格。 文件名:abcControllerTest.php <?php namespace AbcBundle\Tests\Controller; use Symfony\Component\HttpFoundation\Response; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; use Symfony\Component\Htt
<?php
namespace AbcBundle\Tests\Controller;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Component\HttpFoundation\Request;
class AbcControllerTest extends WebTestCase {
public function testEmpty() {
$whereParams = array('params' => array(
'var' => '',
));
return $whereParams;
}
/**
* ABC Builder
* @depends testEmpty
*/
public function testAbc(array $whereParams) {
$client = static::createClient();
$crawler = $client->request('GET', $GLOBALS['host'] . '/abc/ac_file/param', $whereParams);
$buttonCrawlerNode = $crawler->selectButton('Submit');
$form = $buttonCrawlerNode->form();
$crawler = $client->submit($form);
}
}
哪一行给出了错误?您应该使用$this->assertTrue($client->getResponse()->issusccessful())之类的工具检查第一页的加载是否正常
您可以使用$client->getResponse()->getContent()
调试,我在这一行中遇到错误:$form=$buttonCrawlerNode->form();节点
可能是因为XHTML
无效,或者您用于查找提交
的路径错误,或者是因为请求没有正确到达您的网页。顺便说一句,最好只报告stacktrace而不是错误消息。这更有帮助。哪一行给了你错误?您应该使用$this->assertTrue($client->getResponse()->issusccessful())之类的工具检查第一页的加载是否正常
您可以使用$client->getResponse()->getContent()
调试,我在这一行中遇到错误:$form=$buttonCrawlerNode->form();节点
可能是因为XHTML
无效,或者您用于查找提交
的路径错误,或者是因为请求没有正确到达您的网页。顺便说一句,最好只报告stacktrace而不是错误消息。这更有帮助。