编程语言
首页 > 编程语言> > 如何在gitlab.com上的PHP项目的作业列表中启用代码覆盖率输出

如何在gitlab.com上的PHP项目的作业列表中启用代码覆盖率输出

作者:互联网

对于在https://www.gitlab.com托管的项目,我想在CI设置中设置代码覆盖率,因此它可以显示在作业列表中

job list in gitlab.com project

我的配置如下所示:

.gitlab-ci.yml

image: php:7.1.1

cache:
  paths:
  - vendor/

before_script:
# Install git, the php image doesn't have installed
- apt-get update -yqq
- apt-get install git -yqq

# Install composer
- curl -sS https://getcomposer.org/installer | php

# Install all project dependencies
- php composer.phar install

# Run our tests
test:
    only:
        - master
        - develop
    script:
        - vendor/bin/phpunit --configuration phpunit.xml --coverage-text --colors=never

作业成功,但显示错误消息

错误:没有可用的代码覆盖率驱动程序

no code coverage found job output

我更新了setting for Test coverage parsing并将正则表达式设置为

^\s*Lines:\s*\d+.\d+\%

PHP / PHPUnit的示例.

当我运行命令

vendor/bin/phpunit --coverage-text --colors=never

在本地,我得到以下输出:

Code Coverage Report:     
  2017-06-21 14:52:55     

 Summary:                 
  Classes: 100.00% (4/4)  
  Methods: 100.00% (14/14)
  Lines:   100.00% (43/43)

\Rodacker\CartExample::Article
  Methods: 100.00% ( 6/ 6)   Lines: 100.00% ( 11/ 11)
\Rodacker\CartExample::ArticleLoader
  Methods: 100.00% ( 2/ 2)   Lines: 100.00% ( 21/ 21)
\Rodacker\CartExample::ArticleRepository
  Methods: 100.00% ( 3/ 3)   Lines: 100.00% (  6/  6)
\Rodacker\CartExample::Image
  Methods: 100.00% ( 3/ 3)   Lines: 100.00% (  5/  5)

解决方法:

问题是Docker镜像中缺少Xdebug安装.我无法使用apt-get安装正确的版本,所以我必须在before_script部分添加一个pecl install xdebug调用:

image: php:7.1.1

cache:
  paths:
  - vendor/

before_script:
# Install git, the php image doesn't have installed
- apt-get update -yqq
- apt-get install git -yqq

# Install Xdebug
- pecl install xdebug
- docker-php-ext-enable xdebug

# Install composer
- curl -sS https://getcomposer.org/installer | php

# Install all project dependencies
- php composer.phar install

# Run our tests
test:
    only:
        - master
    script:
        - vendor/bin/phpunit --configuration phpunit.xml --coverage-text --colors=never

标签:php,code-coverage,phpunit,gitlab,gitlab-ci
来源: https://codeday.me/bug/20190522/1154007.html