2017-01-16 82 views
0

我想知道是否有任何工具爲測試控制器的測試類提供代碼覆蓋率分析。我知道有一些單元測試,但那不是我正在尋找的。控制器測試類的代碼覆蓋率分析

我正在開發一個Symfony2項目,裏面有很多控制器,我寫了一些測試來檢查它們的行爲,所以現在我想知道它們是多麼完整。

謝謝。

P.S. :這是一個什麼樣一個的例子我的我的測試看起來可以像

public function testSample() { 

     $client = $this->createAuthenticatedClient($this->getReference('admin-0')) ; 
     $client->followRedirects() ; 
     $crawler = $client->request("GET", "/config/database/"); 
     $this->assertStatusCode(200, $client); 

} 

正如你所看到的,我真的不測試我的User類,而是其行爲取決於其creditential的(在這種情況下,管理員)

回答

0

您可能想要根據您展示的示例查看Functional Tests。想想你將如何測試你在代碼中創建的代碼的所有功能。如果你從網絡的角度來看它,就像點擊鏈接和按鈕等等。無論用戶可能做什麼。看看我寫在Using Mink to perform Functional Tests in Symfony3上的這個博客。

像@geoB指出的那樣,你可以使用命令行:

PHPUnit的--coverage文本

要顯示您的報道。下面顯示了一個示例屏幕截圖: phpunit --coverage

+0

你的屏幕截圖確實有助於理解我應該期待什麼。該命令工作正常,但我必須把白名單,以獲得連貫的結果。 – Asew

0

這裏的phpunit命令的摘錄:

phpunit --help 
PHPUnit 5.4.6 by Sebastian Bergmann and contributors. 

Usage: phpunit [options] UnitTest [UnitTest.php] 
     phpunit [options] <directory> 

Code Coverage Options: 

    --coverage-clover <file> Generate code coverage report in Clover XML format. 
    --coverage-crap4j <file> Generate code coverage report in Crap4J XML format. 
    --coverage-html <dir>  Generate code coverage report in HTML format. 
    --coverage-php <file>  Export PHP_CodeCoverage object to file. 
    --coverage-text=<file> Generate code coverage report in text format. 
          Default: Standard output. 
    --coverage-xml <dir>  Generate code coverage report in PHPUnit XML format. 
    --whitelist <dir>   Whitelist <dir> for code coverage analysis. 
    --disable-coverage-ignore Disable annotations for ignoring code coverage. 

請注意,您可以添加IF Xdebug的加載將生成一個覆蓋報告參數。

+0

我覺得這個命令本身是一個單元測試,但它爲函數測試提供了代碼覆蓋範圍。無論如何,感謝您的幫助,白名單選項非常有幫助。 – Asew