Simfony2 phpunit-c应用程序断言false为true失败


Simfony2 phpunit -c app Failed asserting that false is true

我有一段代码可以在我的网站上实现博客。我想通过在控制台中发出phpunit-c应用程序来检查它是否正常工作。

我得到一个结果:

有1个失败:1) Blog''CoreBundle''Tests''Controller''PostControllerTest::testIndex

无响应

断言false为true失败。C: ''examplep''htdocs''escibe''src''Blog''CoreBundle''Tests''Controller''PostControllerTesphp:21

以下是我为检查客户端而实现的简单代码:

<?php
namespace Blog'CoreBundle'Tests'Controller;
use Symfony'Bundle'FrameworkBundle'Test'WebTestCase;
/**
 * Class PostControllerTest
 */
class PostControllerTest extends WebTestCase
{
    /**
     * Tests posts index
     */
    public function testIndex()
    {
        $client = static::createClient();
        $crawler = $client->request('GET', '/');
        $this->assertTrue($client->getResponse()->isSuccessful(), 'No response');
    }
}

我在symfoy2 2.5上构建这个提前感谢您的帮助。

您应该通过检查页面中的一些元素来检查页面是否格式良好:

# check that there is a <html> tag (this is an example, in real life it's pretty useless)
$this->assertEquals(
    1,
    $crawler->filter('html:contains("Blog")')->count()
);
# check that the page <title> contains "Blog"
$this->assertEquals(
    1,
    $crawler->filter('title:contains("Blog")')->count()
);
# check that the page have articles (use your own selector)
$this->assertGreaterThan(
    0,
    $crawler->filter('#content div.article')->count()
);

有关更多示例,请参阅官方文档;有关所有断言的列表,请参阅PHPUnit文档。

谢谢A.L.我休息了一下,不知怎么就在今天得到了答案。这真是个愚蠢的错误。为其他控制器错误地定义了app/config/routing.yml内的路由。感谢您的支持。