Skip to content

Commit f58a158

Browse files
authored
Merge pull request #245 from PHPCSStandards/feature/ci-prevent-issues-with-code-coverage
GH Actions: warm PHPUnit cache on PHPUnit 9.3+
2 parents cbb5548 + 7341d76 commit f58a158

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

.github/workflows/test.yml

+22-1
Original file line numberDiff line numberDiff line change
@@ -234,12 +234,33 @@ jobs:
234234
# Bust the cache at least once a month - output format: YYYY-MM.
235235
custom-cache-suffix: $(date -u "+%Y-%m")
236236

237+
- name: Grab PHPUnit version
238+
id: phpunit_version
239+
# yamllint disable-line rule:line-length
240+
run: echo "VERSION=$(vendor/bin/phpunit --version | grep --only-matching --max-count=1 --extended-regexp '\b[0-9]+\.[0-9]+')" >> $GITHUB_OUTPUT
241+
242+
- name: "DEBUG: Show grabbed version"
243+
run: echo ${{ steps.phpunit_version.outputs.VERSION }}
244+
237245
- name: 'PHPCS: set the path to PHP'
238246
run: php bin/phpcs --config-set php_path php
239247

240-
- name: 'PHPUnit: run the tests with code coverage'
248+
# PHPUnit 9.3 started using PHP-Parser for code coverage, which can cause issues due to Parser
249+
# also polyfilling PHP tokens.
250+
# As of PHPUnit 9.3.4, a cache warming option is available.
251+
# Using that option prevents issues with PHP-Parser backfilling PHP tokens during our test runs.
252+
- name: "Warm the PHPUnit cache (PHPUnit 9.3+)"
253+
if: ${{ steps.phpunit_version.outputs.VERSION >= '9.3' }}
254+
run: vendor/bin/phpunit --coverage-cache ./build/phpunit-cache --warm-coverage-cache
255+
256+
- name: "Run the unit tests with code coverage (PHPUnit < 9.3)"
257+
if: ${{ steps.phpunit_version.outputs.VERSION < '9.3' }}
241258
run: vendor/bin/phpunit tests/AllTests.php
242259

260+
- name: "Run the unit tests with code coverage (PHPUnit 9.3+)"
261+
if: ${{ steps.phpunit_version.outputs.VERSION >= '9.3' }}
262+
run: vendor/bin/phpunit tests/AllTests.php --coverage-cache ./build/phpunit-cache
263+
243264
- name: Upload coverage results to Coveralls
244265
if: ${{ success() }}
245266
uses: coverallsapp/github-action@v2

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"ext-xmlwriter": "*"
3737
},
3838
"require-dev": {
39-
"phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0 || ^8.0 || ^9.0"
39+
"phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0 || ^8.0 || ^9.3.4"
4040
},
4141
"bin": [
4242
"bin/phpcbf",

0 commit comments

Comments
 (0)