Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/neo4j/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html PHPUnit和Symfony_Html_Symfony_Phpunit - Fatal编程技术网

Html PHPUnit和Symfony

Html PHPUnit和Symfony,html,symfony,phpunit,Html,Symfony,Phpunit,我试图测试我的索引方法,只是为了测试我的页面中是否有一些精确的单词 所以我有这个 public function testIndexAction() { $client = static::createClient(); $crawler = $client->request('GET', 'conducteurs'); $this->assertSame(1, $crawler->filter('html:contains("Liste des con

我试图测试我的索引方法,只是为了测试我的页面中是否有一些精确的单词

所以我有这个

public function testIndexAction()
{
    $client = static::createClient();
    $crawler = $client->request('GET', 'conducteurs');
    $this->assertSame(1, $crawler->filter('html:contains("Liste des conducteurs")')->count());
}

在我的页面中,有“导体列表”,但我的测试失败了。你知道为什么吗?phpunit.xml是否有精确的设置?

该字符串可能出现多次。 您可以将断言更改为

$this->assertGreaterThan(0,$crawler->filter('html:contains("Liste des conducteurs")')->count());

我不可能猜到你的应用程序发生了什么,因为我还没有看到它。然而,我能做的是建议您如何调试它并改进您的测试,以提供更好的反馈

在开始查看响应内容之前,您可以确保响应是成功的。您还可以将响应内容用作断言消息,因此如果断言失败,phpunit将显示内容

public function testIndexAction()
{
$client=static::createClient();
$crawler=$client->request('GET','conductors');
$this->assertSame(200$client->getResponse()->getStatusCode(),$client->getResponse()->getContent());
$this->assertSame(1$crawler->filter('html:contains(“listedesconductors”))->count(),$client->getResponse()->getContent());
}
如果状态代码不是200,但也不是错误,则可能是您的站点进行了重定向(301/302),在这种情况下,您可以自动:

$client->followRedirects();
或者遵循特定的重定向:

$crawler=$client->followRedirect();

也许你错过了前导斜杠<代码>$client->request('GET','/conductors')?我试过带和不带,仍然不工作这是我想的,但是没有,只有一个这样的字符串。如果我尝试另一个词(它不像“bonjoru”那样存在),它就不起作用了。我尝试了类似的东西,但是代码200不起作用。它使用302(或者301,我不记得了),即使这个页面上没有重定向,symfony调试工具栏上的代码是200,这是因为你的浏览器自动执行了重定向。除非你告诉他们,否则测试不会这么做。更新了我的答案以提示您如何处理它。