Skip to content

Commit e8a9180

Browse files
Streamlines CI coverage generation
Removes a conditional test execution path, allowing `npm run test` to consistently handle code coverage collection across all test matrix configurations, including PHP 8.3 with the latest WordPress. Eliminates unnecessary debugging output for `xdebug.mode` and `clover.xml` content to declutter CI logs. Refines comments for improved clarity regarding Composer platform requirements and `docker cp` usage.
1 parent 68452bd commit e8a9180

1 file changed

Lines changed: 7 additions & 28 deletions

File tree

.github/workflows/test.yml

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,9 @@ jobs:
123123
- name: Composer install
124124
run: |
125125
rm composer.lock || true # We need to install fresh.
126-
# On PHP 8+, the composer.json platform override (php: 7.2.24) causes PHPUnit 8.5 to
127-
# be installed. PHPUnit 8.5 explicitly refuses to generate code coverage on PHP 8 with
128-
# the message "This version of PHPUnit does not support code coverage on PHP 8". Pass
129-
# --ignore-platform-req=php so Composer resolves against the actual PHP runtime and
130-
# installs PHPUnit 9.6, which supports coverage on PHP 8.x.
126+
# The composer.json platform override (php: 7.2.24) installs PHPUnit 8.5, which does
127+
# not support code coverage on PHP 8. Use --ignore-platform-req=php on PHP 8+ so
128+
# Composer installs PHPUnit 9.6, which supports coverage on PHP 8.x.
131129
if [[ "${WP_ENV_PHP_VERSION}" == 8.* ]]; then
132130
npm run composer -- install --ignore-platform-req=php
133131
else
@@ -142,41 +140,22 @@ jobs:
142140
- name: Test
143141
run: |
144142
npm run env run tests-cli --env-cwd=wp-content/plugins/two-factor -- mkdir -p tests/logs
145-
# For the coverage matrix cell, set XDEBUG_MODE=coverage explicitly via env var
146-
# (Xdebug 3 feature) rather than relying on the ini configuration that wp-env
147-
# applies to persistent containers — ephemeral wp-env run containers may not
148-
# inherit it. Pass --coverage-clover in addition to what phpunit.xml.dist configures
149-
# so the clover output is guaranteed regardless of XML config format differences
150-
# between PHPUnit versions.
151-
if [[ "${{ matrix.php }}" == "8.3" && "${{ matrix.wp }}" == "latest" ]]; then
152-
# Call wp-env directly (not via npm run) to avoid npm re-splitting the argument
153-
# list. env sets XDEBUG_MODE=coverage and execs composer, which resolves phpunit
154-
# from vendor/bin — the same path used by npm run test.
155-
./node_modules/.bin/wp-env run tests-cli --env-cwd=wp-content/plugins/two-factor \
156-
-- env XDEBUG_MODE=coverage composer test
157-
else
158-
npm run test
159-
fi
143+
npm run test
160144
161145
- name: Retrieve coverage report from container
162146
if: ${{ matrix.php == '8.3' && matrix.wp == 'latest' }}
163147
run: |
164148
# PHPUnit writes clover.xml into the Docker volume shared between tests-cli and
165-
# tests-wordpress. We use docker cp (not 'docker exec cat > file') because docker cp
166-
# is an atomic Docker API call that avoids a shell redirect pre-truncating the
167-
# destination — which would zero-out the file before cat can read it.
149+
# tests-wordpress. Use docker cp (not 'docker exec cat > file'): docker cp is an
150+
# atomic API call that avoids a shell redirect pre-truncating the destination file,
151+
# which would zero it out before cat can read it (self-overwrite).
168152
CONTAINER=$(docker ps --filter "name=tests-wordpress" --format "{{.Names}}" | head -1)
169153
if [ -z "$CONTAINER" ]; then
170154
echo "Error: tests-wordpress container not found"
171155
exit 1
172156
fi
173157
mkdir -p tests/logs
174158
docker cp "$CONTAINER:/var/www/html/wp-content/plugins/two-factor/tests/logs/clover.xml" tests/logs/clover.xml
175-
echo "=== xdebug mode in tests-wordpress ==="
176-
docker exec "$CONTAINER" php -r "echo ini_get('xdebug.mode') . PHP_EOL;"
177-
echo "=== clover.xml size and first 10 lines ==="
178-
wc -c tests/logs/clover.xml
179-
head -10 tests/logs/clover.xml
180159
if [ ! -s tests/logs/clover.xml ]; then
181160
echo "Error: clover.xml is empty — coverage was not generated"
182161
exit 1

0 commit comments

Comments
 (0)