Change Xdebug Mode PHP Docker on Gitlab CI

Viewed 1373

I want run PHPUnit code coverage using GitLab CI but when i run the command vendor/bin/phpunit --coverage-text --colors=never is only show code test result and not generating code coverage.

When I test it on local using XAMPP with Xdebug enable the code coverage generated with using xdebug.mode=coverage. How to change the xdebug.mode on php.ini on docker setup script ?

I also override it via PHPUnit XML configuration like this also not work.

<ini name="xdebug.mode" value="coverage" />

Here is my .gitlab-ci.yml

image: php:7.4.14

cache:
  key: "$CI_JOB_NAME-$CI_COMMIT_REF_SLUG"
  paths:
    - vendor

before_script:
  # Install git
  - apt-get update -yqq
  - apt-get install git -yqq

  # Install packages
  - apt-get install libcurl4-openssl-dev

  # Install required php extension
  - docker-php-ext-install curl

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

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

  # Install dependencies
  - php composer.phar update --prefer-stable --prefer-dist --no-interaction --no-progress

run-test:
  script:
    - vendor/bin/phpunit --coverage-text --colors=never
2 Answers

After searching some article finally i can do it like this. Here my example .gitlab-ci.yml

image: php:7.4.14

cache:
  key: "$CI_JOB_NAME-$CI_COMMIT_REF_SLUG"
  paths:
    - vendor

before_script:
  # Install git
  - apt-get update -yqq
  - apt-get install git -yqq

  # Install packages
  - apt-get install libcurl4-openssl-dev

  # Install required php extension
  - docker-php-ext-install curl

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

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

  # Install dependencies
  - php composer.phar update --prefer-stable --prefer-dist --no-interaction --no-progress

  # Here to change xdebug mode
  - echo xdebug.mode=coverage > /usr/local/etc/php/conf.d/xdebug.ini 

run-test:
  script:
    - vendor/bin/phpunit --coverage-text --colors=never

In my dockerfile I added this lines :

RUN pecl install xdebug \
&& docker-php-ext-enable xdebug \
&& echo "xdebug.mode=debug" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
&& echo "xdebug.client_host=host.docker.internal" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini \
&& echo "xdebug.mode=coverage" >> /usr/local/etc/php/conf.d/xdebug.ini
Related