phpunit 和代码覆盖率

标签 php phpunit code-coverage

我正在运行一个带有简单灯组的流浪盒。我已经通过composer全局安装了phpunit:

composer global require "phpunit/phpunit=4.1.*"

当我运行 phpunit 时,出现以下错误:

PHP Warning:  require_once(PHP/CodeCoverage/Filter.php): failed to open stream: No such file or directory in /usr/share/php/PHPUnit/Autoload.php on line 46

HP Fatal error:  require_once(): Failed opening required 'PHP/CodeCoverage/Filter.php' (include_path='/home/vagrant/.composer/vendor/phpunit/php-text-template:/home/vagrant/.composer/vendor/phpunit/phpunit-mock-objects:/home/vagrant/.composer/vendor/phpunit/php-timer:/home/vagrant/.composer/vendor/phpunit/php-token-stream:/home/vagrant/.composer/vendor/phpunit/php-file-iterator:/home/vagrant/.composer/vendor/phpunit/php-code-coverage:/home/vagrant/.composer/vendor/phpunit/phpunit:/home/vagrant/.composer/vendor/symfony/yaml:.:/usr/share/php:/usr/share/pear') in /usr/share/php/PHPUnit/Autoload.php on line 46

我的研究似乎暗示这是 CodeCoverage 未安装的问题,但我在尝试安装它时遇到了问题。我尝试通过 Composer 安装但无法正常工作。

通过 Composer,我尝试添加到全局:

composer global require "phpunit/php-code-coverage": "3.0.*@dev"

我得到这个输出:

Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - The requested package phpunit/php-code-coverage could not be found in any version, there may be a typo in the package name.
  Problem 2
    - phpunit/phpunit 4.1.3 requires phpunit/php-code-coverage ~2.0 -> no matching package found.
    - phpunit/phpunit 4.1.3 requires phpunit/php-code-coverage ~2.0 -> no matching package found.
    - Installation request for phpunit/phpunit == 4.1.3.0 -> satisfiable by phpunit/phpunit[4.1.3].

Potential causes:
 - A typo in the package name
 - The package is not available in a stable-enough version according to your minimum-stability setting
   see <https://groups.google.com/d/topic/composer-dev/_g3ASeIFlrc/discussion> for more details.

Read <http://getcomposer.org/doc/articles/troubleshooting.md> for further common problems.

Installation failed, reverting ./composer.json to its original content.

不知道我做错了什么!

最佳答案

您需要先重新安装代码覆盖2.0

composer global require "phpunit/php-code-coverage":"2.0.*@dev"

然后安装 phpunit

composer global require "phpunit/phpunit=4.1.*"

关于phpunit 和代码覆盖率,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24518399/

相关文章:

php - Apache .htaccess : ErrorDocument and RewriteEngine not working together

php - 为引用 time() 的方法编写测试

php - 在 PHPUnit 中测试具有依赖关系的对象

.net - 即使执行了测试,测试覆盖率也为 0% (Opencover/xUnit)

python - 使用工作服测试 Jupyter/iPython?

php - 是否可以从 PHPUnit 运行 HTML 测试套件?

php - 在 PHP (Laravel) 中显示图像

php - 数据库错误 : [mysqli. mysqli]:用户已经有超过 'max_user_connections' 个事件连接

php - 日语文本输出为问号或 goobledy gook

php - 无法让 PHPunit 工作