df/php-coverfish

PHPUnit的CodeCoverage的类覆盖率检查的轻量级静态代码分析工具

1.0.1 2015-08-08 00:00 UTC

README

phpCoverFish (coverfish) 是一个开源的 php cli 静态代码验证器,用于代码覆盖率的预处理。coverFish将在大型代码覆盖率列车运行通过所有测试之前,分析你测试文件中的所有@covers注解,可能碰撞到沿着铁轨散落的糟糕覆盖率注解。Coverfish使用基于插件的验证器,易于扩展/满足代码覆盖率注解的更改或扩展。

Software License Software version Build Status Scrutinizer Code Quality Code Climate Code Coverage Project Status

安装

如果你使用Composer来管理项目的依赖关系,编辑你的项目的composer.json文件,并添加df/phpcoverfish依赖项。以下是一个composer.json文件的最小示例,它仅定义了PHPCoverFish(稳定版本)的开发时间依赖项。

...
{
    "require-dev": {
        "df/php-coverfish": "~1.0"
}
...

你还可以在控制台执行以下Composer命令

composer require df/php-coverfish

为了使用即将到来的PHPCoverFish beta版本,你需要将composer.json文件中的minimum-stability键设置下来(设置为"beta")。只需将此行放置在"extra"属性键之上即可。

...
"minimum-stability": "beta",
"extra": {
...

之后,只需调用composer install "df/phpcoverfish=~1.0"或使用composer update,然后从vendor/df/coverfish/bin/coverfish.php创建到你的Web应用程序工具目录的符号链接(此步骤是可选的)。

composer install "df/php-coverfish=~1.0"

要全局提供coverfish,请输入以下命令

composer global require "df/php-coverfish=~1.0"

别忘了确保你的composers vendor二进制路径已在你的全局shell路径中可用

PATH=$PATH:~/.composer/vendor/bin/

一旦coverfish达到稳定状态,我们不仅会提供额外的phar文件,还会为相关的wget安装提供对应的下载链接/安装程序。

使用方法

在安装后,从你的shell调用coverfish时,可以使用以下两种模式:如果coverfish已绑定到你的symfony应用程序,Composer将在你的bin/目录内创建一个符号链接,这样你就可以从这个路径直接调用此工具(如phpunit、...)。

PHPUnit模式 扫描(推荐的扫描模式),使用现有的phpunit.xml,而不是扫描路径、排除路径和autoload-file的"raw"参数

php ./bin/coverfish scan tests/phpunit.xml \
        --phpunit-config-suite "PHPCoverFish Suite" \ 
        --output-level 1 \
        --no-ansi

例如(使用没有任何测试套件名称的phpunit.xml将采用此扫描的第一个测试套件配置)

php ./bin/coverfish scan tests/phpunit.xml --output-level 1 --no-ansi

或(使用phpunit测试套件名称"PHPCoverFish Suite")

php ./bin/coverfish scan tests/phpunit.xml --phpunit-config-suite "PHPCoverFish Suite" --output-level 1 --no-ansi   

带有和没有调用测试套件的代码的屏幕结果应该相同

phpunit mode result

RAW模式 扫描(备选扫描模式),使用额外的参数来指定扫描路径、autoload-file(排除路径将在这里作为可选使用)

php <path/to/your/coverfish/vendor/>bin/coverfish.php *scan* \
        --raw-scan-path "<path/to/your/phpunit/tests>" \
        --raw-autoload-file "<path/to/your/autoload.php>" \
        --raw-exclude-path "<path/to/your/excluded/test/files>"

例如

php ./bin/coverfish scan --raw-scan-path tests/ --raw-autoload-file "vendor/autoload.php" --raw-exclude-path "tests/data" --output-level 1 --no-ansi

结果应该看起来像:raw mode result

PHPCoverfish参数和参数

要调用PHPCoverFish帮助页面,使用

php <path/to/your/coverfish/vendor/>bin/coverfish.php help scan

参数

scan                     scan/analyze command (currently the only available mode of coverfish)
phpunit-config           path to your project phpunit.xml config file (e.g. tests/phpunit.xml)
                         this argument override all raw-parameters (raw-scan-path, raw-autoload-path ...)

参数(可选)

raw-scan-path            path to your target php unit class test files or a single test file
raw-exclude-path         exclude a specific path from your planned scan 
raw-autoload-file        your application used autoload file (psr-0/psr-4 standard)
                         will be replaced by phpunit.xml file in our upcoming beta version
-f | --output-format     json, text (default) - rendering of scan result output format (json or text)
-l | --output-level      detail of scan result output (0=minimal, 1=normal(default), 2=detailed)
-n | --no-interaction    not necessary, no virtual interaction planned yet
-v | --verbose           will be handled by option '--output-level <n>'
-q | --quiet             if you fetch results in json format, you can hide direct output and analyse results as as a json object directly
        
--no-ansi                prevent colorful output of rendering results (default: false | 0)
--stop-on-error          stop on first application error | exception (default: false | 0)
--stop-on-failure        stop on first detected coverFish scan failure (default: false | 0)

缺失的功能、讨厌的bug和项目想法

对于缺失的功能、发现的bug或与此项目相关的美好想法,请随时联系我们 :)

我们目前正在进行的:

  • 文件/IO 扫描模式,目前使用 PHP 反射功能来识别代码覆盖率错误 - 未来版本将提供一种原始扫描模式以扫描自动加载上下文之外的文件
  • 覆盖率警告实现,识别 PHPUnit 代码覆盖率使用中的覆盖率问题或配置问题
  • 优化 coverFish 的输出模块;该模块“很糟糕”
  • 重构颜色输出模块,使用 symfony 输出格式化器
  • 掌握 coverfish 文档并构建一个有用的维基
  • 包含 @use 语句检查
  • 提高扫描器/分析器速度

一些结果屏幕的截图

根据选择的 --output-level 选项,coverfish 将提供不同的测试结果输出

使用最小输出级别(—output-level 0),未发现代码覆盖率错误 Level 0, test validated 相同模式,识别到代码覆盖率错误 Level 0, test failed

使用中等(默认)输出级别(—output-level 1Level 1, test validated 相同模式,识别到代码覆盖率错误并显示详细 Level 1, test failed

以及使用最大输出级别,显示大屏幕结果的部分输出(—output-level 2Level 2, test validated 相同模式,识别到代码覆盖率错误并显示更详细 Level 2, test failed

版本和兼容性

请使用我们最新的稳定版本 1.0.2 的 phpCoverFish 进行您的生产静态代码分析过程。本文档最后更新于 2018-05-15 (内部版本 1.0.2)

phpCoverFish (>= 1.0.2) 与 php7.0php7.1php7.2 兼容良好;phpCoverFish (<= 1.0.1) 与 php5.5php5.6php7.n 兼容

贡献

PHPCoverFish仍在开发中,欢迎贡献者加入!请自由加入我们的coverFish分销团队。请参阅CONTRIBUTING.md了解如何为PHPCoverFish项目做出贡献。

许可证

版权所有(c)2015 - 2018 Patrick Paechnatz patrick.paechnatz@gmail.com

特此免费授予任何获得本软件及其相关文档文件(以下简称“软件”)副本的个人在不限制条件下处理软件的权利,包括但不限于使用、复制、修改、合并、发布、分发、再许可和/或销售软件副本,并允许向软件提供方提供软件的个人进行上述行为,前提是必须遵守以下条件

上述版权声明和本许可声明应包含在软件的所有副本或主要部分中。

软件按“现状”提供,不提供任何明示或暗示的保证,包括但不限于适销性、针对特定目的的适用性和非侵权性保证。在任何情况下,作者或版权所有者不应对任何索赔、损害或其他责任承担责任,无论这些责任源于合同、侵权或其他方式,是否与软件或软件的使用或其他方式有关。