gpt4 book ai didi

php - 如何为 php 覆盖率报告配置 Jenkins?

转载 作者:可可西里 更新时间:2023-10-31 22:46:28 25 4
gpt4 key购买 nike

我正在努力设置代码覆盖率。我必须做什么,我该如何设置才能获得覆盖 map /报告?

我有一个运行的单元测试。我必须检查哪些复选框:构建后操作?我必须安装插件吗?单元测试在 php 5.3.2 中,我运行 symfony 1.4.5

在我运行的 cibuild 脚本中:

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'), 'blabla@mtmail.com');
$t->is(myValidatorString::doClean('@#*+??%^!~blabla-===32.mtmail..com'), 'blabla@mtmail.com');
$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');
?>

请帮忙谢谢

这是我在 jenkins 中查看控制台构建时的输出:

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;
}
}

谢谢

最佳答案

PHP 本身不会生成代码覆盖率信息。 Xdebug扩展将收集脚本运行时执行的行,但不会创建报告。你应该使用 PHPUnitPHP_CodeCoverage运行您的测试并输出 Jenkins 可以提供的报告。

使用pecl 安装Xdebug,使用pear 安装另外两个。您还应该看看 Template for Jenkins Jobs for PHP Projects .

关于php - 如何为 php 覆盖率报告配置 Jenkins?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9461366/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com