Skip to content

Commit 8dcd9e9

Browse files
authored
Enhancement: Collect and report code coverage from running unit tests (#944)
1 parent 33dd2a8 commit 8dcd9e9

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

.github/workflows/integrate.yaml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,56 @@ on:
99
- "master"
1010

1111
jobs:
12+
code-coverage:
13+
name: "Code Coverage"
14+
15+
runs-on: "ubuntu-latest"
16+
17+
strategy:
18+
matrix:
19+
php-version:
20+
- "8.2"
21+
22+
steps:
23+
- name: "Checkout"
24+
uses: "actions/checkout@v4"
25+
26+
- name: "Set up PHP"
27+
uses: "shivammathur/setup-php@v2"
28+
with:
29+
coverage: "xdebug"
30+
extensions: "none, curl, dom, json, mbstring, tokenizer, xml, xmlwriter"
31+
php-version: "${{ matrix.php-version }}"
32+
33+
- name: "Set up problem matchers for PHP"
34+
run: "echo \"::add-matcher::${{ runner.tool_cache }}/php.json\""
35+
36+
- name: "Set up problem matchers for phpunit/phpunit"
37+
run: "echo \"::add-matcher::${{ runner.tool_cache }}/phpunit.json\""
38+
39+
- name: "Determine composer cache directory"
40+
run: "echo \"COMPOSER_CACHE_DIR=$(composer config cache-dir)\" >> $GITHUB_ENV"
41+
42+
- name: "Cache dependencies installed with composer"
43+
uses: "actions/cache@v3"
44+
with:
45+
path: "${{ env.COMPOSER_CACHE_DIR }}"
46+
key: "php-${{ matrix.php-version }}-composer-${{ hashFiles('composer.lock') }}"
47+
restore-keys: "php-${{ matrix.php-version }}-composer-"
48+
49+
- name: "Install dependencies with composer"
50+
run: "composer install --ansi --no-interaction --no-progress"
51+
52+
- name: "Collect code coverage from running unit tests with phpunit/phpunit"
53+
env:
54+
XDEBUG_MODE: "coverage"
55+
run: "vendor/bin/phpunit --colors=always --configuration=tests/phpunit.xml --coverage-clover=.build/phpunit/logs/clover.xml --testsuite=unit"
56+
57+
- name: "Send code coverage report to codecov.io"
58+
uses: "codecov/[email protected]"
59+
with:
60+
files: ".build/phpunit/logs/clover.xml"
61+
1262
coding-standards:
1363
name: "Coding Standards"
1464

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ HTTP_HOST:=localhost:8080
55
.PHONY: it
66
it: coding-standards tests ## Runs all the targets
77

8+
.PHONY: code-coverage
9+
code-coverage: vendor ## Collects code coverage from running unit tests with phpunit/phpunit
10+
vendor/bin/phpunit --configuration=tests/phpunit.xml --coverage-text --testsuite=unit
11+
812
.PHONY: help
913
help: ## Displays this list of targets with descriptions
1014
@grep -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[32m%-30s\033[0m %s\n", $$1, $$2}'

0 commit comments

Comments
 (0)