[web-php] master: Enhancement: Collect and report code coverage from running unit tests (#944)
| From: | Andreas Möller via GitHub | Date: | Tue, 13 Feb 2024 14:37:01 +0000 |
| Subject: | [web-php] master: Enhancement: Collect and report code coverage from running unit tests (#944) | ||
| Groups: | php.webmaster | ||
| Request: | Send a blank email to php-webmaster+get-31469@lists.php.net to get a copy of this message | ||
Author: Andreas Möller (localheinz)
Committer: GitHub (web-flow)
Pusher: saundefined
Date: 2024-02-13T17:23:14+03:00
Commit: https://github.com/php/web-php/commit/8dcd9e94bd209fae8f44a72d4c9b0187338301f6
Raw diff: https://github.com/php/web-php/commit/8dcd9e94bd209fae8f44a72d4c9b0187338301f6.diff
Enhancement: Collect and report code coverage from running unit tests (#944)
Changed paths:
M .github/workflows/integrate.yaml
M Makefile
Diff:
diff --git a/.github/workflows/integrate.yaml b/.github/workflows/integrate.yaml
index 2e7b992d09..4c4718951c 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 9589d0f198..23b2f9c321 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}'