From 8dcd9e94bd209fae8f44a72d4c9b0187338301f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Tue, 13 Feb 2024 15:23:14 +0100 Subject: [PATCH] Enhancement: Collect and report code coverage from running unit tests (#944) --- .github/workflows/integrate.yaml | 50 ++++++++++++++++++++++++++++++++ Makefile | 4 +++ 2 files changed, 54 insertions(+) diff --git a/.github/workflows/integrate.yaml b/.github/workflows/integrate.yaml index 2e7b992d0..4c4718951 100644 --- a/.github/workflows/integrate.yaml +++ b/.github/workflows/integrate.yaml @@ -9,6 +9,56 @@ on: - "master" jobs: + code-coverage: + name: "Code Coverage" + + runs-on: "ubuntu-latest" + + strategy: + matrix: + php-version: + - "8.2" + + steps: + - name: "Checkout" + uses: "actions/checkout@v4" + + - name: "Set up PHP" + uses: "shivammathur/setup-php@v2" + with: + coverage: "xdebug" + extensions: "none, curl, dom, json, mbstring, tokenizer, xml, xmlwriter" + php-version: "${{ matrix.php-version }}" + + - name: "Set up problem matchers for PHP" + run: "echo \"::add-matcher::${{ runner.tool_cache }}/php.json\"" + + - name: "Set up problem matchers for phpunit/phpunit" + run: "echo \"::add-matcher::${{ runner.tool_cache }}/phpunit.json\"" + + - name: "Determine composer cache directory" + run: "echo \"COMPOSER_CACHE_DIR=$(composer config cache-dir)\" >> $GITHUB_ENV" + + - name: "Cache dependencies installed with composer" + uses: "actions/cache@v3" + with: + path: "${{ env.COMPOSER_CACHE_DIR }}" + key: "php-${{ matrix.php-version }}-composer-${{ hashFiles('composer.lock') }}" + restore-keys: "php-${{ matrix.php-version }}-composer-" + + - name: "Install dependencies with composer" + run: "composer install --ansi --no-interaction --no-progress" + + - name: "Collect code coverage from running unit tests with phpunit/phpunit" + env: + XDEBUG_MODE: "coverage" + run: "vendor/bin/phpunit --colors=always --configuration=tests/phpunit.xml --coverage-clover=.build/phpunit/logs/clover.xml --testsuite=unit" + + - name: "Send code coverage report to codecov.io" + uses: "codecov/codecov-action@v4.0.1" + with: + files: ".build/phpunit/logs/clover.xml" + coding-standards: name: "Coding Standards" diff --git a/Makefile b/Makefile index 9589d0f19..23b2f9c32 100644 --- a/Makefile +++ b/Makefile @@ -5,6 +5,10 @@ HTTP_HOST:=localhost:8080 .PHONY: it it: coding-standards tests ## Runs all the targets +.PHONY: code-coverage +code-coverage: vendor ## Collects code coverage from running unit tests with phpunit/phpunit + vendor/bin/phpunit --configuration=tests/phpunit.xml --coverage-text --testsuite=unit + .PHONY: help help: ## Displays this list of targets with descriptions @grep -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[32m%-30s\033[0m %s\n", $$1, $$2}'