簡體   English   中英

Simfony2 phpunit -c app斷言false為真失敗

[英]Simfony2 phpunit -c app Failed asserting that false is true

我有在我的網站中實現博客的代碼。 我想通過在控制台中發布它來檢查其功能:phpunit -c app。

我得到一個結果:

發生了1個失敗:1)Blog \\ CoreBundle \\ Tests \\ Controller \\ PostControllerTest :: testIndex

沒有反應

斷言false為真失敗。 C:\\ XAMPP \\ htdocs中\\ escribe的\\ src \\博客\\ CoreBundle \\測試\\控制器\\ 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');
    }
}

我在symfony2 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文檔

謝謝AL我休息了一會兒,直到今天才得到答案。 這是一個非常愚蠢的錯誤。 app / config / routing.yml內部的路由為其他控制器錯誤定義。 謝謝你的支持。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM