diff --git a/.gitattributes b/.gitattributes index 170e0ed..3998791 100644 --- a/.gitattributes +++ b/.gitattributes @@ -5,13 +5,14 @@ # https://www.reddit.com/r/PHP/comments/2jzp6k/i_dont_need_your_tests_in_my_production # https://blog.madewithlove.be/post/gitattributes/ # -/.gitattributes export-ignore -/.gitignore export-ignore -/phpcs.xml.dist export-ignore -/phpstan.neon.dist export-ignore -/phpunit.xml.dist export-ignore -/.github export-ignore -/Tests/ export-ignore +/.gitattributes export-ignore +/.gitignore export-ignore +/phpcs.xml.dist export-ignore +/phpstan.neon.dist export-ignore +/phpunit.xml.dist export-ignore +/phpunitlte9.xml.dist export-ignore +/.github export-ignore +/Tests/ export-ignore # # Auto detect text files and perform LF normalization diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 7a5576b..b8c1b2a 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -111,8 +111,21 @@ jobs: composer-options: --ignore-platform-req=php custom-cache-suffix: $(date -u "+%Y-%m") + - name: Grab PHPUnit version + id: phpunit_version + 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.' ) || startsWith( steps.phpunit_version.outputs.VERSION, '11.' ) }}" == "true" ]; then + echo 'FILE=phpunit.xml.dist' >> $GITHUB_OUTPUT + else + echo 'FILE=phpunitlte9.xml.dist' >> $GITHUB_OUTPUT + fi + - name: Run the unit tests - run: composer test + run: vendor/bin/phpunit --no-coverage -c ${{ steps.phpunit_config.outputs.FILE }} #### CODE COVERAGE STAGE #### # N.B.: Coverage is only checked on the lowest and highest stable PHP versions @@ -178,21 +191,30 @@ jobs: - name: "DEBUG: Show grabbed version" run: echo ${{ steps.phpunit_version.outputs.VERSION }} + - name: Determine PHPUnit config file to use + id: phpunit_config + run: | + if [ "${{ startsWith( steps.phpunit_version.outputs.VERSION, '9.' ) && steps.phpunit_version.outputs.VERSION >= '9.3' }}" == "true" ]; then + echo 'FILE=phpunitlte9.xml.dist' >> $GITHUB_OUTPUT + echo 'EXTRA_ARGS=--coverage-cache ./build/phpunit-cache' >> $GITHUB_OUTPUT + elif [ "${{ startsWith( steps.phpunit_version.outputs.VERSION, '10.' ) || startsWith( steps.phpunit_version.outputs.VERSION, '11.' ) }}" == "true" ]; then + echo 'FILE=phpunit.xml.dist' >> $GITHUB_OUTPUT + echo 'EXTRA_ARGS=' >> $GITHUB_OUTPUT + else + echo 'FILE=phpunitlte9.xml.dist' >> $GITHUB_OUTPUT + echo 'EXTRA_ARGS=' >> $GITHUB_OUTPUT + fi + # PHPUnit 9.3 started using PHP-Parser for code coverage which can cause interference. # 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. - 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 - - - name: "Run the unit tests with code coverage (PHPUnit < 9.3)" - if: ${{ steps.phpunit_version.outputs.VERSION < '9.3' }} - run: composer coverage + run: vendor/bin/phpunit -c ${{ steps.phpunit_config.outputs.FILE }} ${{ steps.phpunit_config.outputs.EXTRA_ARGS }} --warm-coverage-cache - - name: "Run the unit tests with code coverage (PHPUnit 9.3+)" - if: ${{ steps.phpunit_version.outputs.VERSION >= '9.3' }} - run: composer coverage -- --coverage-cache ./build/phpunit-cache + - name: "Run the unit tests with code coverage" + run: vendor/bin/phpunit -c ${{ steps.phpunit_config.outputs.FILE }} ${{ steps.phpunit_config.outputs.EXTRA_ARGS }} - name: Upload coverage results to Coveralls if: ${{ success() }} diff --git a/.gitignore b/.gitignore index 34bee17..6f1be37 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ /vendor/ /build/ phpunit.xml +phpunitlte9.xml .phpunit.result.cache .phpcs.xml phpcs.xml diff --git a/Tests/VariableAnalysisSniff/UnusedFollowedByRequireTest.php b/Tests/VariableAnalysisSniff/UnusedFollowedByRequireTest.php index 2e158cb..2373b12 100644 --- a/Tests/VariableAnalysisSniff/UnusedFollowedByRequireTest.php +++ b/Tests/VariableAnalysisSniff/UnusedFollowedByRequireTest.php @@ -4,7 +4,7 @@ use VariableAnalysis\Tests\BaseTestCase; -class UnusedFollowedByRequire extends BaseTestCase +class UnusedFollowedByRequireTest extends BaseTestCase { public function testUnusedFollowedByRequireWarnsByDefault() { diff --git a/composer.json b/composer.json index 5ae1091..544bc3c 100644 --- a/composer.json +++ b/composer.json @@ -41,6 +41,8 @@ "scripts": { "test": "./vendor/bin/phpunit --no-coverage", "coverage": "./vendor/bin/phpunit", + "test-lte9": "./vendor/bin/phpunit -c phpunitlte9.xml.dist --no-coverage", + "coverage-lte9": "./vendor/bin/phpunit -c phpunitlte9.xml.dist", "lint": "./vendor/bin/phpcs", "fix": "./vendor/bin/phpcbf", "phpstan": "./vendor/bin/phpstan analyse", @@ -52,7 +54,7 @@ "squizlabs/php_codesniffer": "^3.5.6" }, "require-dev": { - "phpunit/phpunit": "^4.8.36 || ^5.7.21 || ^6.5 || ^7.0 || ^8.0 || ^9.0", + "phpunit/phpunit": "^4.8.36 || ^5.7.21 || ^6.5 || ^7.0 || ^8.0 || ^9.0 || ^10.5.32 || ^11.3.3", "sirbrillig/phpcs-import-detection": "^1.1", "phpcsstandards/phpcsdevcs": "^1.1", "phpstan/phpstan": "^1.7", diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 54fa099..c8763f3 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,12 +1,20 @@ @@ -14,14 +22,16 @@ - - + + ./VariableAnalysis/ - - + + - - - - + + + + + + diff --git a/phpunitlte9.xml.dist b/phpunitlte9.xml.dist new file mode 100644 index 0000000..54fa099 --- /dev/null +++ b/phpunitlte9.xml.dist @@ -0,0 +1,27 @@ + + + + + Tests + + + + + + ./VariableAnalysis/ + + + + + + + +