Skip to content

Instantly share code, notes, and snippets.

@n1c0l4stournier
Created March 9, 2021 10:51
Show Gist options
  • Save n1c0l4stournier/74d5ff2595f4c8abf501eb4f9df186b3 to your computer and use it in GitHub Desktop.
Save n1c0l4stournier/74d5ff2595f4c8abf501eb4f9df186b3 to your computer and use it in GitHub Desktop.
Code quality testing with SonarQube and Gitlab CI for PHP applications - 07
stages:
- phpunit
- sonarqube
phpunit:
stage: phpunit
image:
name: php:8.0
before_script:
- apt-get update -yqq
- apt-get install git unzip -yqq
- php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
- php composer-setup.php --install-dir=/usr/bin --filename=composer --version=2.0.11
- php -r "unlink('composer-setup.php');"
- pecl install xdebug-3.0.0
- docker-php-ext-enable xdebug
cache:
key: ${CI_JOB_NAME}
paths:
- vendor
variables:
XDEBUG_MODE: "coverage"
script:
- composer install
- |
./vendor/bin/phpunit \
--whitelist src/Domain \
--log-junit build/phpunit.xml \
--coverage-text \
--coverage-clover build/coverage.xml \
--colors=never \
tests
artifacts:
paths:
- build
reports:
junit: build/phpunit.xml
expire_in: 30 min
only:
- merge_requests
- master
sonarqube:
stage: sonarqube
image:
name: sonarsource/sonar-scanner-cli:4.6
entrypoint: [""]
variables:
IP_SONAR_MACHINE: "10.1.1.1"
cache:
key: "${CI_JOB_NAME}"
paths:
- .sonar/cache
- .scannerwork
script:
- |
sonar-scanner \
-Dsonar.language=php \
-Dsonar.qualitygate.wait=true \
-Dsonar.sources=src/Domain \
-Dsonar.host.url=http://${IP_SONAR_MACHINE}:9000 \
-Dsonar.php.tests.reportPath=build/phpunit.xml \
-Dsonar.php.coverage.reportPaths=build/coverage.xml \
-Dsonar.projectKey=demo-php-code-quality-testing-sonar-gitlab-ci \
-Dsonar.login=227f5c5b4f4e11e587b9b2e93f2a9f14c1fa71df
only:
- merge_requests
- master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment