Skip to content

Commit

Permalink
Enhancement: Collect and report code coverage from running unit tests (
Browse files Browse the repository at this point in the history
  • Loading branch information
localheinz authored Feb 13, 2024
1 parent 33dd2a8 commit 8dcd9e9
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
50 changes: 50 additions & 0 deletions .github/workflows/integrate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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}'
Expand Down

0 comments on commit 8dcd9e9

Please sign in to comment.