2017-05-28 43 views
0

我在PHPUnit中有以下默認測試,它返回失敗。我已經從瀏覽器訪問了路徑,並且顯示正常。symfony 2.8 phpunit默認測試返回失敗

class DefaultControllerTest extends WebTestCase 
{ 
    public function testIndex() 
    { 
     $client = static::createClient(); 

     $crawler = $client->request('GET', '/hello/Fabien'); 

     $this->assertTrue($crawler->filter('html:contains("Hello Fabien")')->count() > 0); 
    } 
} 

config_test.yml

imports: 
    - { resource: config_dev.yml } 

framework: 
    test: ~ 
    session: 
     storage_id: session.storage.mock_file 
    profiler: 
     enabled: true # we want the profiler service to be defined 
     collect: false 

web_profiler: 
    toolbar: false 
    intercept_redirects: false 

swiftmailer: 
    disable_delivery: true 
+1

您是否檢查過'var/logs/tst.log'來查看是否獲取了正確的路線並且沒有其他錯誤?另外,你可以試試'$ this-> assertContains('Hello Fabien',$ client-> getResponse() - > getContent());'看看是否有效。如果是這樣,您將不得不根據內容修改過濾器。 –

+0

你用來執行單元測試的命令是什麼? – Florian

+0

我需要使用這個命令'''phpunit -c phpunit.xml.dist'''來執行單元測試,以使它們無誤地運行。 – Florian

回答

0

檢查logs/tests.log後。錯誤來自翻譯信息,幾乎沒有信息沒有開始和結束報價,現在添加它顯示成功信息。