2012-02-27 78 views
3

我正在努力設置代碼覆蓋率。 我必須做什麼,我如何設置這個,所以我可以得到一個覆蓋地圖/報告?如何配置詹金斯的PHP覆蓋率報告?

我有一個運行的單元測試。我必須檢查哪些複選框:生成後操作? 我必須安裝一個插件嗎?單元測試是在PHP 5.3.2和我在運行腳本cibuild symfony的1.4.5

我運行:

php "test/unit/RbcTest.php" 

這裏實際的測試代碼:

<?php 
    require_once dirname(__FILE__).'/../bootstrap/unit.php'; 
    require_once 'PHP/CodeCoverage/Autoload.php'; 
    set_include_path ('phoenix/lib/'); 
    $coverage = new PHP_CodeCoverage; 
    $coverage->start('strtolowerTest.php'); 
    $coverage->stop(); 
    $writer = new PHP_CodeCoverage_Report_Clover; 
    $writer->process($coverage, 'phoenix/test/clover.xml'); 
    $writer = new PHP_CodeCoverage_Report_HTML; 
    $writer->process($coverage, 'phoenix/test/code-coverage-report'); 
?> 

<?php //strtolowerTest.php 
echo "1. for strlower"; 
require_once 'phoenix/lib/vendor/symfony/lib/vendor/lime/lime.php'; 
echo "2. for strlower"; 
require_once 'phoenix/lib/validator/myValidatorString.class.php'; 
echo "3. for strlower"; 
require_once 'phoenix/lib/vendor/symfony/lib/validator/sfValidatorString.class.php'; 
$t = new lime_test(2, new lime_output_color()); 
$t->is(myValidatorString::doCleanEmail('blabla-32.mtmail..com'), '[email protected]'); 
$t->is(myValidatorString::doClean('@#*+??%^!~blabla-===32.mtmail..com'), '[email protected]'); 
$t->is(myValidatorString::slugify('sensio labs'), 'sensio-labs'); 
$t->is(myValidatorString::slugify('paris,france'), 'paris-france'); 
$t->is(myValidatorString::slugify(' sensio'), 'sensio'); 
$t->is(myValidatorString::slugify('sensio '), 'sensio'); 
$t->is(myValidatorString::slugify(''), 'n-a', '::slugify() converts the empty string to n-a'); 
$t->is(myValidatorString::slugify(' - '), 'n-a', '::slugify() converts a string that only contains non-ASCII characters to n-a'); 

$t->diag('hello world'); 
$t->ok(true, 'test something'); 
?> 

請幫助 感謝

以下是輸出,當我在詹金斯查看控制檯編譯:

PHPUnit 3.6.10 by Sebastian Bergmann. 

Class test/phpunit/unit/RbcTest could not be found in /var/lib/jenkins/workspace/b32b733b59ba6be9884da7427bee5c95/phoenix/test/phpunit/unit/RbcTest.php.Publishing Clover coverage report... 
Publishing Clover HTML report... 
Publishing Clover XML report... 
Publishing Clover coverage results... 
Code coverage enforcement failed for the following metrics: 
    Methods 
    Conditionals 
Setting Build to unstable. 
Build step 'Publish Clover Coverage Report' changed build result to UNSTABLE 
Publishing Clover coverage report... 
Publishing Clover XML report... 
Publishing Clover coverage results... 
Code coverage enforcement failed for the following metrics: 
    Methods 
Setting Build to unstable. 
[ci-game] evaluating rule: Build result 
[ci-game] evaluating rule: Increased number of failed tests 
[ci-game] evaluating rule: Increased number of passed tests 
[ci-game] evaluating rule: Decreased number of failed tests 
[ci-game] evaluating rule: Decreased number of passed tests 
[ci-game] evaluating rule: PMD violation 
[ci-game] evaluating rule: pylint violation 
[ci-game] evaluating rule: CPD violation 
[ci-game] evaluating rule: Checkstyle violation 
[ci-game] evaluating rule: FindBugs violation 
[ci-game] evaluating rule: FXCop violation 
[ci-game] evaluating rule: Simian violation 
[ci-game] evaluating rule: StyleCop violation 
[ci-game] evaluating rule: HIGH priority PMD warnings 
[ci-game] evaluating rule: NORMAL priority PMD warnings 
[ci-game] evaluating rule: LOW priority PMD warnings 
[ci-game] evaluating rule: Changed number of compiler warnings 
[ci-game] evaluating rule: Changed number of checkstyle warnings 
Finished: UNSTABLE 



<?php 
class myValidatorString extends sfValidatorString 
{ 
    static public function slugify($text) 
    { 
     echo "in myvalidatorstring for class sfValidatorString.class.php"; 
     // replace all non letters or digits by - 
     $text = preg_replace('/\W+/', '-', $text); 

     // trim and lowercase 
     $text = strtolower(trim($text, '-')); 

     if (empty($text)) 
     { 
     return 'n-a'; 
     } 
     return $text; 
    } 
} 

感謝

回答

5

PHP本身並不生成代碼覆蓋率信息。 Xdebug擴展將收集哪些行在腳本運行時執行,但不會創建報告。您應該使用PHPUnitPHP_CodeCoverage來運行您的測試並輸出Jenkins可以提供的報告。

使用pecl爲其他兩個安裝Xdebug和pear。你也應該看看Template for Jenkins Jobs for PHP Projects

+0

謝謝你,安裝了PHP_CodeCoverage。我該從哪裏出發?下一步讓我的詹金斯出示代碼覆蓋率報告?謝謝 – 2012-02-27 11:39:37

+0

安裝PHPUnit並按照[docs](www.phpunit.de)設置CC。你需要爲它編寫你的單元測試,或者你可以嘗試在沒有它的情況下使用CC。雖然我沒有那樣做。 – 2012-02-27 17:07:03

+0

謝謝我有單元測試並安裝了PHPUnit。我配置jenkins生成clover.xml,但無論我如何定義路徑,它都會給出錯誤!請參閱主文章中的錯誤消息 – 2012-02-29 11:04:07

0

對於PHP,你可以使用Clover PHP plugin。安裝該插件後,您將擁有額外的作業配置選項來設置所有內容(請參閱插件的說明)。

+0

我跑了wget http://myhost.net:12343/jnlpJars/jenkins-cli.jar並且現在有文件。接下來我做:java -jar jenkins-cli.jar -s http://myhost.net:1234 install-plugin cloverphp並得到:無效或損壞的jarfile jenkins-cli.jar ???請求幫助?謝謝! – 2012-02-27 09:12:21

+1

您可以通過Web界面安裝插件。只需去管理詹金斯 - >管理插件。 – 2012-02-27 15:35:46