From 1914d5fe238d0c2c191f71a773d4bc48d00e89a7 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sun, 11 Jun 2023 21:43:52 +0200 Subject: [PATCH] PHPUnit: add separate configuration for PHPUnit 10 PHPUnit 10 makes significant changes to the configuration file. While there is a `--migrate-configuration` option available in PHPUnit, that doesn't get us a well enough converted configuration file, so instead use a separate `phpunit10.xml.dist` file for running the tests on PHPUnit 10 with an optimal configuration. Includes * Adding separate scripts to the `composer.json` file to make this more obvious for contributors. * Updating the GH Actions workflows to take the new configuration file into account when appropriate. * Selectively not using the `--repeat` option, which was [removed without replacement](https://github.com/sebastianbergmann/phpunit/issues/5174) in PHPUnit 10. --- .github/workflows/quicktest.yml | 22 +++++++++- .github/workflows/test.yml | 41 +++++++++++++----- composer.json | 9 ++++ phpunit10.xml.dist | 75 +++++++++++++++++++++++++++++++++ 4 files changed, 134 insertions(+), 13 deletions(-) create mode 100644 phpunit10.xml.dist diff --git a/.github/workflows/quicktest.yml b/.github/workflows/quicktest.yml index 9e29ce9a..511f26d8 100644 --- a/.github/workflows/quicktest.yml +++ b/.github/workflows/quicktest.yml @@ -80,14 +80,32 @@ jobs: if: matrix.phpcs_version == 'dev-master' run: composer lint-lt72 + - name: Grab PHPUnit version + id: phpunit_version + # yamllint disable-line rule:line-length + run: echo "VERSION=$(vendor/bin/phpunit --version | grep --only-matching --max-count=1 --extended-regexp '\b[0-9]+\.[0-9]+')" >> $GITHUB_OUTPUT + + - name: Determine PHPUnit config file to use + id: phpunit_config + run: | + if [ "${{ startsWith( steps.phpunit_version.outputs.VERSION, '10.' ) }}" == "true" ]; then + echo 'FILE=phpunit10.xml.dist' >> $GITHUB_OUTPUT + echo 'EXTRA_ARGS=' >> $GITHUB_OUTPUT + else + echo 'FILE=phpunit.xml.dist' >> $GITHUB_OUTPUT + echo 'EXTRA_ARGS= --repeat 2' >> $GITHUB_OUTPUT + fi + - name: Run the unit tests without caching - run: vendor/bin/phpunit --no-coverage + run: vendor/bin/phpunit -c ${{ steps.phpunit_config.outputs.FILE }} --no-coverage env: PHPCS_VERSION: ${{ matrix.phpcs_version }} PHPCSUTILS_USE_CACHE: false - name: Run the unit tests with caching - run: vendor/bin/phpunit --testsuite PHPCSUtils --no-coverage --repeat 2 + run: > + vendor/bin/phpunit -c ${{ steps.phpunit_config.outputs.FILE }} + --testsuite PHPCSUtils --no-coverage ${{ steps.phpunit_config.outputs.EXTRA_ARGS }} env: PHPCS_VERSION: ${{ matrix.phpcs_version }} PHPCSUTILS_USE_CACHE: true diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index dbcc316f..40422292 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -201,16 +201,34 @@ jobs: if: ${{ matrix.phpcs_version == 'lowest' }} run: composer update squizlabs/php_codesniffer --prefer-lowest --no-scripts --no-interaction + - name: Grab PHPUnit version + id: phpunit_version + # yamllint disable-line rule:line-length + run: echo "VERSION=$(vendor/bin/phpunit --version | grep --only-matching --max-count=1 --extended-regexp '\b[0-9]+\.[0-9]+')" >> $GITHUB_OUTPUT + + - name: Determine PHPUnit config file to use + id: phpunit_config + run: | + if [ "${{ startsWith( steps.phpunit_version.outputs.VERSION, '10.' ) }}" == "true" ]; then + echo 'FILE=phpunit10.xml.dist' >> $GITHUB_OUTPUT + echo 'EXTRA_ARGS=' >> $GITHUB_OUTPUT + else + echo 'FILE=phpunit.xml.dist' >> $GITHUB_OUTPUT + echo 'EXTRA_ARGS= --repeat 2' >> $GITHUB_OUTPUT + fi + - name: Run the unit tests without caching (non-risky) if: ${{ matrix.risky == false }} - run: vendor/bin/phpunit --no-coverage + run: vendor/bin/phpunit -c ${{ steps.phpunit_config.outputs.FILE }} --no-coverage env: PHPCS_VERSION: ${{ matrix.phpcs_version == '4.0.x-dev' && '4.0.0' || matrix.phpcs_version }} PHPCSUTILS_USE_CACHE: false - name: Run the unit tests with caching (non-risky) if: ${{ matrix.risky == false }} - run: vendor/bin/phpunit --testsuite PHPCSUtils --no-coverage --repeat 2 + run: > + vendor/bin/phpunit -c ${{ steps.phpunit_config.outputs.FILE }} + --testsuite PHPCSUtils --no-coverage ${{ steps.phpunit_config.outputs.EXTRA_ARGS }} env: PHPCS_VERSION: ${{ matrix.phpcs_version == '4.0.x-dev' && '4.0.0' || matrix.phpcs_version }} PHPCSUTILS_USE_CACHE: true @@ -220,7 +238,7 @@ jobs: - name: Run the unit tests (risky, comparewithPHPCS) if: ${{ matrix.risky && matrix.phpcs_version == 'dev-master' }} # "nothing" is excluded to force PHPUnit to ignore the settings in phpunit.xml.dist. - run: vendor/bin/phpunit --no-coverage --group compareWithPHPCS --exclude-group nothing + run: vendor/bin/phpunit -c ${{ steps.phpunit_config.outputs.FILE }} --no-coverage --group compareWithPHPCS --exclude-group nothing env: PHPCS_VERSION: ${{ matrix.phpcs_version == '4.0.x-dev' && '4.0.0' || matrix.phpcs_version }} @@ -228,7 +246,7 @@ jobs: - name: Run the unit tests (risky, xtra) if: ${{ matrix.risky }} # "nothing" is excluded to force PHPUnit to ignore the settings in phpunit.xml.dist. - run: vendor/bin/phpunit --no-coverage --group xtra --exclude-group nothing + run: vendor/bin/phpunit -c ${{ steps.phpunit_config.outputs.FILE }} --no-coverage --group xtra --exclude-group nothing env: PHPCS_VERSION: ${{ matrix.phpcs_version == '4.0.x-dev' && '4.0.0' || matrix.phpcs_version }} @@ -312,20 +330,21 @@ jobs: # As of PHPUnit 9.3.4, a cache warming option is available. # Using that option prevents issues with PHP-Parser backfilling PHP tokens when PHPCS does not (yet), # which would otherwise cause tests to fail on tokens being available when they shouldn't be. + # As coverage is only run on high/low PHP, the high PHP version will use PHPUnit 10, so just check for that. - name: "Warm the PHPUnit cache (PHPUnit 9.3+)" - if: ${{ steps.phpunit_version.outputs.VERSION >= '9.3' }} - run: vendor/bin/phpunit --coverage-cache ./build/phpunit-cache --warm-coverage-cache + if: ${{ startsWith( steps.phpunit_version.outputs.VERSION, '10.' ) }} + run: vendor/bin/phpunit -c phpunit10.xml.dist --coverage-cache ./build/phpunit-cache --warm-coverage-cache - - name: "Run the unit tests without caching with code coverage (PHPUnit < 9.3)" - if: ${{ steps.phpunit_version.outputs.VERSION < '9.3' }} + - name: "Run the unit tests without caching with code coverage (PHPUnit < 10)" + if: ${{ ! startsWith( steps.phpunit_version.outputs.VERSION, '10.' ) }} run: vendor/bin/phpunit env: PHPCS_VERSION: ${{ matrix.phpcs_version }} PHPCSUTILS_USE_CACHE: false - - name: "Run the unit tests without caching with code coverage (PHPUnit 9.3+)" - if: ${{ steps.phpunit_version.outputs.VERSION >= '9.3' }} - run: vendor/bin/phpunit --coverage-cache ./build/phpunit-cache + - name: "Run the unit tests without caching with code coverage (PHPUnit 10+)" + if: ${{ startsWith( steps.phpunit_version.outputs.VERSION, '10.' ) }} + run: vendor/bin/phpunit -c phpunit10.xml.dist --coverage-cache ./build/phpunit-cache env: PHPCS_VERSION: ${{ matrix.phpcs_version }} PHPCSUTILS_USE_CACHE: false diff --git a/composer.json b/composer.json index 04f124b9..8c0e8d45 100644 --- a/composer.json +++ b/composer.json @@ -66,11 +66,20 @@ "test": [ "@php ./vendor/phpunit/phpunit/phpunit --no-coverage" ], + "test10": [ + "@php ./vendor/phpunit/phpunit/phpunit -c phpunit10.xml.dist --no-coverage" + ], "coverage": [ "@php ./vendor/phpunit/phpunit/phpunit" ], + "coverage10": [ + "@php ./vendor/phpunit/phpunit/phpunit -c phpunit10.xml.dist" + ], "coverage-local": [ "@php ./vendor/phpunit/phpunit/phpunit --coverage-html ./build/coverage-html" + ], + "coverage-local10": [ + "@php ./vendor/phpunit/phpunit/phpunit -c phpunit10.xml.dist --coverage-html ./build/coverage-html" ] }, "config": { diff --git a/phpunit10.xml.dist b/phpunit10.xml.dist new file mode 100644 index 00000000..d6f05c43 --- /dev/null +++ b/phpunit10.xml.dist @@ -0,0 +1,75 @@ + + + + + + ./Tests/Internal/Cache/GetClearTest.php + ./Tests/Internal/Cache/SetTest.php + ./Tests/Internal/NoFileCache/GetClearTest.php + ./Tests/Internal/NoFileCache/SetTest.php + + + ./Tests/Utils/Namespaces/NamespaceTypeTest.php + + + ./Tests/ + + Tests/Internal/Cache/GetClearTest.php + Tests/Internal/Cache/SetTest.php + Tests/Internal/NoFileCache/GetClearTest.php + Tests/Internal/NoFileCache/SetTest.php + + Tests/Utils/Namespaces/NamespaceTypeTest.php + + + + + + compareWithPHPCS + + xtra + + + + + + + ./PHPCSUtils/ + + + + + + + + + + +