From 551c1f4cda77d853e254dd32d9179703e10ac62c Mon Sep 17 00:00:00 2001 From: Antonio Spinelli Date: Mon, 3 Jul 2023 11:37:11 -0300 Subject: [PATCH] Send code coverage to SonarCloud --- .github/workflows/sonarcloud.yml | 28 +++++++++++ .gitignore | 2 +- composer.json | 7 ++- phpunit.xml | 63 ++++++++++++++++-------- sonar-project.properties | 1 + tests/integration/CreatesApplication.php | 2 +- 6 files changed, 78 insertions(+), 25 deletions(-) diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml index a1a34fa24f1..e9ba1b9b27d 100644 --- a/.github/workflows/sonarcloud.yml +++ b/.github/workflows/sonarcloud.yml @@ -1,5 +1,6 @@ name: Sonarcloud on: + pull_request: push: branches: - main @@ -12,6 +13,33 @@ jobs: - uses: actions/checkout@v3 with: fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis + + - name: Checkout + uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: Setup PHP with Xdebug + uses: shivammathur/setup-php@v2 + with: + php-version: '8.2' + coverage: xdebug + + - name: Install Composer dependencies + run: composer install --prefer-dist --no-interaction --no-progress --no-scripts + + - name: Copy environment file + run: cp .env.example .env + + - name: Generate app key + run: php artisan key:generate + + - name: "Run tests with coverage" + run: composer coverage + + - name: Fix code coverage paths + run: sed -i 's@'$GITHUB_WORKSPACE'@/github/workspace/@g' coverage.xml + - name: SonarCloud Scan uses: SonarSource/sonarcloud-github-action@master env: diff --git a/.gitignore b/.gitignore index 220b48d300b..ab681f4f44a 100644 --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,4 @@ npm-debug.log yarn-error.log .env /.ci/php-cs-fixer/vendor -/.ci/coverage +coverage.xml diff --git a/composer.json b/composer.json index 0b8810c5153..1c6c62f1ba2 100644 --- a/composer.json +++ b/composer.json @@ -170,10 +170,13 @@ "@php artisan firefly-iii:verify-security-alerts" ], "unit-test": [ - "@php vendor/bin/phpunit -c phpunit.xml --testsuite unit" + "@php vendor/bin/phpunit -c phpunit.xml --testsuite unit --no-coverage" ], "integration-test": [ - "@php vendor/bin/phpunit -c phpunit.xml --testsuite integration" + "@php vendor/bin/phpunit -c phpunit.xml --testsuite integration --no-coverage" + ], + "coverage": [ + "@php vendor/bin/phpunit -c phpunit.xml --testsuite unit" ] }, "config": { diff --git a/phpunit.xml b/phpunit.xml index 575dac224f9..aa51a02e216 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -18,25 +18,46 @@ ~ You should have received a copy of the GNU Affero General Public License ~ along with this program. If not, see . --> - - - - - ./tests/unit - - - ./tests/integration - - - - - - - - - - - ./app - - + + + + + + + + + + + ./tests + + + ./tests/unit + + + ./tests/integration + + + + + app + + + + + + + diff --git a/sonar-project.properties b/sonar-project.properties index 72777406a0a..30a426dd314 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -15,3 +15,4 @@ sonar.organization=firefly-iii sonar.projectVersion=6.0.11 sonar.sources=app,bootstrap,database,resources/assets,resources/views,routes,tests sonar.sourceEncoding=UTF-8 +sonar.php.coverage.reportPaths=coverage.xml diff --git a/tests/integration/CreatesApplication.php b/tests/integration/CreatesApplication.php index 1900ee8eb1a..6dbc977700c 100644 --- a/tests/integration/CreatesApplication.php +++ b/tests/integration/CreatesApplication.php @@ -38,7 +38,7 @@ trait CreatesApplication */ public function createApplication() { - $app = require __DIR__ . '/../bootstrap/app.php'; + $app = require_once __DIR__ . '/../../bootstrap/app.php'; $app->make(Kernel::class)->bootstrap();