hi,
I use php without framework
Integrates Bitbucket and Sonarcloud
I can’t activate coverage in sonarcloud. I need help.
I did it as follows:
bitbucket-pipeline.yaml
image: php:8.2.7
clone:
depth: full
definitions:
services:
docker:
memory: 3072
caches:
sonar: ~/.sonar/cache
steps:
- step: &build-test-sonarcloud
name: Build, test and analyze on SonarCloud
caches:
- docker
- sonar
size: 2x
script:
- echo "Manual triggers for Sonar are awesome!"
- apt-get update
- install xdebug
- install composer
- composer require phpunit/phpunit
- vendor/bin/phpunit
- php -n -dzend_extension=xdebug -dxdebug.mode=coverage vendor/bin/phpunit --log-junit test-reports/junit.xml
- pipe: sonarsource/sonarcloud-scan:2.0.0
variables:
SONAR_TOKEN: ${VARIABLETOKEN}
DEBUG: 'false'
EXTRA_ARGS:
- sonar-scanner -Dsonar.projectKey=$VARIABLEKEY
-Dsonar.organization=$VARIABLEORG
-Dsonar.sources=. -Dsonar.host.url=https://sonarcloud.io
-Dsonar.login=$VARIABLETOKEN
-Dsonar.php.lcov.reportPaths=coverage/lcov.info -X
-Dsonar.coverage.exclusions=**/tests/Unit//**/*.*
artifacts:
- test-reports/junit.xml -coverage.txt
- step: &check-quality-gate-sonarcloud
name: Check the Quality Gate on SonarCloud
size: 2x # Double resources available for this step.
script:
- pipe: sonarsource/sonarcloud-quality-gate:0.1.4
variables:
SONAR_TOKEN: ${VARIABLEORG}
SONAR_QUALITY_GATE_TIMEOUT: '180'
pipelines:
custom:
sonar-scan:
- step: *build-test-sonarcloud
sonar-quality:
- step: *check-quality-gate-sonarcloud
[...]
phpunit.xml
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.3/phpunit.xsd" bootstrap="vendor/autoload.php" backupGlobals="false" colors="true" stopOnFailure="false" >
<testsuites>
<testsuite name="default">
<directory>tests/Unit/</directory>
</testsuite>
</testsuites>
<coverage>
<include>
<directory suffix=".php">src</directory>
</include>
<exclude>
[...]
</exclude>
<report>
<xml outputDirectory="test-reports"/>
</report>
</coverage>
<php>
<ini name="xdebug.mode" value="coverage"/>
[...]
</php>
<logging>
<junit outputFile="test-reports/junit.xml"/>
</logging>
</phpunit>