Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Unit testing GitLab中的代码覆盖率始终未知_Unit Testing_Gitlab_Code Coverage_Gitlab Ci_Gitlab Ci Runner - Fatal编程技术网

Unit testing GitLab中的代码覆盖率始终未知

Unit testing GitLab中的代码覆盖率始终未知,unit-testing,gitlab,code-coverage,gitlab-ci,gitlab-ci-runner,Unit Testing,Gitlab,Code Coverage,Gitlab Ci,Gitlab Ci Runner,我试图理解GitLab管道,经过几次尝试,我成功地实现了单元测试的自动化。现在我试图将代码覆盖率标记添加到我的项目和/或自述文件中,但它似乎总是显示未知 文件: + application + system - unit-tests - tests UtilTest.php autoload.php phpunit .gitignore .gitlab-ci.yml .htaccess index.php readme.md image: p

我试图理解GitLab管道,经过几次尝试,我成功地实现了单元测试的自动化。现在我试图将代码覆盖率标记添加到我的项目和/或自述文件中,但它似乎总是显示
未知

文件:

+ application
+ system
- unit-tests
  - tests
      UtilTest.php
    autoload.php
    phpunit
  .gitignore
  .gitlab-ci.yml
  .htaccess
  index.php
  readme.md
image: php:5.6

stages:
  - test

app:unit-tests:
  stage: test
  script:
    - php ./unit-tests/phpunit --bootstrap ./unit-tests/autoload.php ./unit-tests/tests
  coverage: '/Code Coverage: \d+\.\d+/'
image: php:7.2

stages:
  - test

before_script:
  - pecl install xdebug
  - docker-php-ext-enable xdebug

app:unit-tests:
  stage: test
  script:
  - php ./unit-tests/phpunit --bootstrap ./unit-tests/autoload.php ./unit-tests/tests --coverage-text --colors=never
  coverage: '/^\s*Lines:\s*\d+.\d+\%/'
.gitlab ci.yml:

+ application
+ system
- unit-tests
  - tests
      UtilTest.php
    autoload.php
    phpunit
  .gitignore
  .gitlab-ci.yml
  .htaccess
  index.php
  readme.md
image: php:5.6

stages:
  - test

app:unit-tests:
  stage: test
  script:
    - php ./unit-tests/phpunit --bootstrap ./unit-tests/autoload.php ./unit-tests/tests
  coverage: '/Code Coverage: \d+\.\d+/'
image: php:7.2

stages:
  - test

before_script:
  - pecl install xdebug
  - docker-php-ext-enable xdebug

app:unit-tests:
  stage: test
  script:
  - php ./unit-tests/phpunit --bootstrap ./unit-tests/autoload.php ./unit-tests/tests --coverage-text --colors=never
  coverage: '/^\s*Lines:\s*\d+.\d+\%/'
在项目的
测试覆盖率分析
部分,我设置了以下内容:


如果您需要更多信息,请告诉我,我会将其添加进来。谢谢你的帮助,谢谢

因此,我能够通过使用PHP7.2作为Docker映像并在
before_脚本调用上安装
xdebug
来解决这个问题

.gitlab ci.yml:

+ application
+ system
- unit-tests
  - tests
      UtilTest.php
    autoload.php
    phpunit
  .gitignore
  .gitlab-ci.yml
  .htaccess
  index.php
  readme.md
image: php:5.6

stages:
  - test

app:unit-tests:
  stage: test
  script:
    - php ./unit-tests/phpunit --bootstrap ./unit-tests/autoload.php ./unit-tests/tests
  coverage: '/Code Coverage: \d+\.\d+/'
image: php:7.2

stages:
  - test

before_script:
  - pecl install xdebug
  - docker-php-ext-enable xdebug

app:unit-tests:
  stage: test
  script:
  - php ./unit-tests/phpunit --bootstrap ./unit-tests/autoload.php ./unit-tests/tests --coverage-text --colors=never
  coverage: '/^\s*Lines:\s*\d+.\d+\%/'
我不得不使用PHP7.2,因为当我尝试运行
pecl安装xdebug
时,它说它需要PHP7。理想情况下,我希望使用PHP5.6,因为这是我们当前服务器的功能,所以测试在类似的版本上进行,但我暂时不使用它

我不得不在
脚本
上添加
--覆盖文本--colors=never
,让它输出数字。然后在
coverage
调用中,我将其更改为
'/^\s*行:\s*\d+。\d+\%/'
,我还在项目设置的
测试覆盖率分析
部分中使用了它


现在代码覆盖率正确地显示了我的期望值。

您能添加控制台日志吗?@TalhaJunaid控制台上没有错误。它只是说测试成功完成了。没有提到代码覆盖率。不过昨天我还是想出了一个解决办法。谢谢
pecl安装xdebug-2.5.5
应与PHP5一起使用。6@SaschaFrinken出于好奇,是否有一种方法可以让我只安装一次扩展名
xdebug
,而不是每次触发管道时都安装扩展名?创建一个额外的Gitlab项目,在其中构建一个php-56 docker映像,扩展默认的php56映像,并安装所有额外的模块(pecl等)您需要并将其发布到gitlab注册表。现在您可以在ci中使用此图像了。我创建了一个gitlab项目()来说明我的意思。HTH@SaschaFrinken我收到此
页面找不到或您没有查看它的权限。
。这个项目是公开的吗?