Skip to content

Commit 55f53ab

Browse files
aristathclaude
andcommitted
Fix PHPUnit code coverage generation in GitHub Actions
This commit resolves critical issues preventing PHPUnit coverage from being generated correctly in the CI workflow. Key Changes: 1. Fixed invalid composer install syntax in code-coverage.yml (line 59) - was incorrectly passing package name as composer option 2. Updated PHP version from 8.2 to 8.3 to match composer.json platform requirement, eliminating need to unset platform.php 3. Removed unnecessary Codecov integration - PR comments and artifacts are sufficient 4. Added ext-pcov and ext-xdebug to composer.json suggest section for documentation 5. Added 'composer coverage' script for local coverage generation 6. Updated README.md with coverage badge and contributor documentation 7. Documented the -0.5% coverage threshold requirement Root Cause Analysis: - The composer-options parameter was incorrectly set to "yoast/wp-test-utils --with-dependencies" instead of valid composer flags - PHP version mismatch between workflow (8.2) and composer.json (8.3) required workarounds - Codecov integration added unnecessary complexity without providing value for the stated requirements The workflow will now: - Generate coverage.xml correctly - Post automated PR comments showing coverage changes - Enforce -0.5% coverage threshold - Upload HTML coverage reports as artifacts 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 891f95f commit 55f53ab

File tree

3 files changed

+43
-14
lines changed

3 files changed

+43
-14
lines changed

.github/workflows/code-coverage.yml

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,22 +41,19 @@ jobs:
4141
- name: Install PHP
4242
uses: shivammathur/setup-php@v2
4343
with:
44-
php-version: '8.2'
44+
php-version: '8.3'
4545
ini-values: zend.assertions=1, error_reporting=-1, display_errors=On
4646
coverage: pcov # Use PCOV for faster code coverage (5x faster than Xdebug)
4747
tools: composer
4848

4949
- name: Install SVN
5050
run: sudo apt-get install subversion
5151

52-
- name: "Composer: remove the PHP platform requirement"
53-
run: composer config --unset platform.php
54-
5552
- name: Install Composer dependencies
5653
uses: ramsey/composer-install@v2
5754
with:
5855
dependency-versions: "highest"
59-
composer-options: "yoast/wp-test-utils --with-dependencies"
56+
composer-options: "--prefer-dist --with-dependencies"
6057
custom-cache-suffix: $(date -u -d "-0 month -$(($(date +%d)-1)) days" "+%F")-codecov-v2
6158

6259
- name: Install WordPress Test Suite
@@ -100,15 +97,6 @@ jobs:
10097
fi
10198
continue-on-error: false
10299

103-
- name: Upload coverage to Codecov
104-
uses: codecov/codecov-action@v4
105-
with:
106-
files: ./coverage.xml
107-
flags: unittests
108-
name: codecov-progress-planner
109-
fail_ci_if_error: false
110-
token: ${{ secrets.CODECOV_TOKEN }}
111-
112100
- name: Generate coverage report summary
113101
id: coverage
114102
run: |

README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
[![Test](https://github.com/ProgressPlanner/progress-planner/actions/workflows/phpunit.yml/badge.svg)](https://github.com/ProgressPlanner/progress-planner/actions/workflows/phpunit.yml)
2+
[![Code Coverage](https://github.com/ProgressPlanner/progress-planner/actions/workflows/code-coverage.yml/badge.svg)](https://github.com/ProgressPlanner/progress-planner/actions/workflows/code-coverage.yml)
23
[![CS](https://github.com/ProgressPlanner/progress-planner/actions/workflows/cs.yml/badge.svg)](https://github.com/ProgressPlanner/progress-planner/actions/workflows/cs.yml)
34
[![PHPStan](https://github.com/ProgressPlanner/progress-planner/actions/workflows/phpstan.yml/badge.svg)](https://github.com/ProgressPlanner/progress-planner/actions/workflows/phpstan.yml)
45
[![Lint](https://github.com/ProgressPlanner/progress-planner/actions/workflows/lint.yml/badge.svg)](https://github.com/ProgressPlanner/progress-planner/actions/workflows/lint.yml)
@@ -24,6 +25,39 @@ This post explains what Progress Planner does and how to use it: [What does Prog
2425

2526
You can find [installation instructions here](https://prpl.fyi/install).
2627

28+
## Contributing
29+
30+
### Running Tests
31+
32+
To run the test suite:
33+
34+
```bash
35+
composer test
36+
```
37+
38+
### Code Coverage
39+
40+
To generate code coverage reports locally, you need either [PCOV](https://pecl.php.net/package/PCOV) (recommended) or [Xdebug](https://xdebug.org/) installed:
41+
42+
```bash
43+
composer coverage
44+
```
45+
46+
This will generate:
47+
- An HTML coverage report in the `coverage-html/` directory
48+
- A text-based coverage summary in your terminal
49+
50+
**Coverage Requirements:** Pull requests must maintain code coverage within 0.5% of the base branch. PRs that drop coverage by more than 0.5% will be blocked until additional tests are added.
51+
52+
### Other Quality Commands
53+
54+
```bash
55+
composer check-cs # Check coding standards
56+
composer fix-cs # Auto-fix coding standards
57+
composer phpstan # Run static analysis
58+
composer lint # Check PHP syntax
59+
```
60+
2761
## Branches on this repository
2862

2963
We use a couple of branches in this repository to keep things clean:

composer.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020
"yoast/yoastcs": "^3.0",
2121
"friendsofphp/php-cs-fixer": "^3.75"
2222
},
23+
"suggest": {
24+
"ext-pcov": "Recommended for fast code coverage generation (5x faster than Xdebug)",
25+
"ext-xdebug": "Alternative for code coverage and debugging"
26+
},
2327
"scripts": {
2428
"check-cs": [
2529
"@php ./vendor/bin/phpcs -s"
@@ -38,6 +42,9 @@
3842
"test": [
3943
"@php ./vendor/phpunit/phpunit/phpunit --dont-report-useless-tests"
4044
],
45+
"coverage": [
46+
"@php ./vendor/phpunit/phpunit/phpunit --coverage-html=coverage-html --coverage-text"
47+
],
4148
"phpstan": [
4249
"@php ./vendor/bin/phpstan analyse --memory-limit=2048M"
4350
]

0 commit comments

Comments
 (0)