From 110c5b7c77254461bd25f18c0c2223e3ab93a781 Mon Sep 17 00:00:00 2001 From: Alain Schlesser Date: Mon, 2 Nov 2026 16:10:27 +0000 Subject: [PATCH] Collect coverage with Xdebug when the locked php-code-coverage cannot use PCOV Co-Authored-By: Claude Opus 5.5 --- .github/workflows/reusable-testing.yml | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/.github/workflows/reusable-testing.yml b/.github/workflows/reusable-testing.yml index 0f9fc31..cae776e 100644 --- a/.github/workflows/reusable-testing.yml +++ b/.github/workflows/reusable-testing.yml @@ -523,10 +523,24 @@ jobs: SHARDS=$(( (SCENARIOS + SCENARIOS_PER_SHARD - 1) / SCENARIOS_PER_SHARD )) SHARDS=$(( SHARDS < 1 ? 1 : SHARDS > COVERAGE_SHARDS ? COVERAGE_SHARDS : SHARDS )) echo "Splitting the Behat tests with code coverage across ${SHARDS} runners, for ${SCENARIOS} scenarios." - COVERAGE=$(jq -c --argjson shards "${SHARDS}" ' + + # PCOV needs phpunit/php-code-coverage 9.1 or later, which picks the driver that is + # loaded. Older versions, as locked by a package that supports PHP 7.2, only use Xdebug. + DRIVER=pcov + if [ -f composer.lock ]; then + LOCKED=$(jq -r '[.packages[]?, .["packages-dev"][]? | select(.name == "phpunit/php-code-coverage") | .version][0] // empty' composer.lock) + LOCKED=${LOCKED#v} + if [ -n "${LOCKED}" ] && [ "$(printf '%s\n' "${LOCKED}" 9.1 | sort -V | head -n 1)" != 9.1 ]; then + echo "Collecting code coverage with Xdebug, as composer.lock has phpunit/php-code-coverage ${LOCKED}." + DRIVER=xdebug + fi + fi + + COVERAGE=$(jq -c --argjson shards "${SHARDS}" --arg driver "${DRIVER}" ' [ .include[] | select(.coverage == true) | . as $entry | ($entry.coverage_shards // $shards) as $total | + ($entry | .coverage_driver //= $driver) as $entry | if $total > 1 then range(1; $total + 1) | $entry + { shard: "\(.)/\($total)" } else