From 05bb3450239022080ebfdcffb720584e6d77ae24 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sat, 16 Mar 2024 20:27:10 +0100 Subject: [PATCH 1/2] Tests: make dataproviders `static` As of PHPUnit 10, data providers are (again) expected to be `static` methods. This updates the test suite to respect that. Includes removing the use of `$this` from select data providers. Refs: * https://github.com/sebastianbergmann/phpunit/commit/9caafe2d49b33a21f87db248a8ad6ca7c7bdac09 * sebastianbergmann/phpunit 5100 --- tests/Unit/Errors/ParallelLintErrorTest.php | 4 ++-- tests/Unit/Errors/SyntaxErrorGetLineTest.php | 2 +- tests/Unit/Errors/SyntaxErrorGetNormalizeMessageTest.php | 4 ++-- tests/Unit/Errors/SyntaxErrorTranslateTokensTest.php | 2 +- tests/Unit/Outputs/OutputTest.php | 2 +- tests/Unit/SettingsAddPathsTest.php | 2 +- tests/Unit/SettingsParseArgumentsTest.php | 4 ++-- 7 files changed, 10 insertions(+), 10 deletions(-) diff --git a/tests/Unit/Errors/ParallelLintErrorTest.php b/tests/Unit/Errors/ParallelLintErrorTest.php index 8bda3cc..db69b55 100644 --- a/tests/Unit/Errors/ParallelLintErrorTest.php +++ b/tests/Unit/Errors/ParallelLintErrorTest.php @@ -31,7 +31,7 @@ public function testGetMessage($message, $expected) * * @return array */ - public function dataGetMessage() + public static function dataGetMessage() { return array( 'Message: empty string' => array( @@ -88,7 +88,7 @@ public function testGetShortFilePath($filePath, $expectedShort) * * @return array */ - public function dataGetFilePath() + public static function dataGetFilePath() { $cwd = getcwd(); diff --git a/tests/Unit/Errors/SyntaxErrorGetLineTest.php b/tests/Unit/Errors/SyntaxErrorGetLineTest.php index 86b824c..dd10e71 100644 --- a/tests/Unit/Errors/SyntaxErrorGetLineTest.php +++ b/tests/Unit/Errors/SyntaxErrorGetLineTest.php @@ -31,7 +31,7 @@ public function testGetLine($message, $expected) * * @return array */ - public function dataGetLine() + public static function dataGetLine() { return array( 'Message: empty string' => array( diff --git a/tests/Unit/Errors/SyntaxErrorGetNormalizeMessageTest.php b/tests/Unit/Errors/SyntaxErrorGetNormalizeMessageTest.php index 8eb47aa..7223cc4 100644 --- a/tests/Unit/Errors/SyntaxErrorGetNormalizeMessageTest.php +++ b/tests/Unit/Errors/SyntaxErrorGetNormalizeMessageTest.php @@ -31,7 +31,7 @@ public function testMessageNormalizationWithoutTokenTranslation($message, $expec * * @return array */ - public function dataMessageNormalization() + public static function dataMessageNormalization() { return array( 'Strip leading and trailing information - fatal error' => array( @@ -85,7 +85,7 @@ public function testFilePathHandling($filePath, $fileName) * * @return array */ - public function dataFilePathHandling() + public static function dataFilePathHandling() { return array( 'Plain file name' => array( diff --git a/tests/Unit/Errors/SyntaxErrorTranslateTokensTest.php b/tests/Unit/Errors/SyntaxErrorTranslateTokensTest.php index a991c63..a1b5c44 100644 --- a/tests/Unit/Errors/SyntaxErrorTranslateTokensTest.php +++ b/tests/Unit/Errors/SyntaxErrorTranslateTokensTest.php @@ -31,7 +31,7 @@ public function testTranslateTokens($message, $expected) * * @return array */ - public function dataTranslateTokens() + public static function dataTranslateTokens() { return array( 'No token name in message' => array( diff --git a/tests/Unit/Outputs/OutputTest.php b/tests/Unit/Outputs/OutputTest.php index 79b5b8e..8deed33 100644 --- a/tests/Unit/Outputs/OutputTest.php +++ b/tests/Unit/Outputs/OutputTest.php @@ -68,7 +68,7 @@ public function testCheckstyleOutput() $this->assertInstanceOf('SimpleXMLElement', $parsed); } - public function getGitLabOutputData() + public static function getGitLabOutputData() { return array( array( diff --git a/tests/Unit/SettingsAddPathsTest.php b/tests/Unit/SettingsAddPathsTest.php index 182e3f1..bd72c0d 100644 --- a/tests/Unit/SettingsAddPathsTest.php +++ b/tests/Unit/SettingsAddPathsTest.php @@ -36,7 +36,7 @@ public function testAddPaths($original, $extra, $expected) * * @return array */ - public function dataAddPaths() + public static function dataAddPaths() { return array( 'No paths passed on CLI, no extra paths' => array( diff --git a/tests/Unit/SettingsParseArgumentsTest.php b/tests/Unit/SettingsParseArgumentsTest.php index 6bd751d..55e5102 100644 --- a/tests/Unit/SettingsParseArgumentsTest.php +++ b/tests/Unit/SettingsParseArgumentsTest.php @@ -35,7 +35,7 @@ public function testParseArgumentsInvalidArgument($command, $unsupported) * * @return array */ - public function dataParseArgumentsInvalidArgument() + public static function dataParseArgumentsInvalidArgument() { return array( 'Unsupported short argument' => array( @@ -79,7 +79,7 @@ public function testParseArguments($command, array $expectedChanged) * * @return array */ - public function dataParseArguments() + public static function dataParseArguments() { return array( 'No arguments at all' => array( From 57f97e5d2ed97609e83aecbab59415956de8c5ae Mon Sep 17 00:00:00 2001 From: jrfnl Date: Sat, 16 Mar 2024 20:45:25 +0100 Subject: [PATCH 2/2] PHPUnit: allow for PHPUnit 10 + add separate configuration The PHPunit configuration file specification has undergone changes in PHPUnit 9.3, 10.0 and 10.1. Most notably: * In PHPUnit 9.3, the manner of specifying the code coverage configuration has changed. * In PHPUnit 10.0, a significant number of attributes of the `` element were removed or renamed. * In PHPUnit 10.1, there is another change related to the code coverage configuration + the ability to fail builds on deprecations/warnings/notices is brought back. While the `--migrate-configuration` command can upgrade a configuration for the changes in the format made in PHPUnit 9.3, some of the changes in the configuration format in PHPUnit 10 don't have one-on-one replacements and/or are not taken into account. As this package is used in the CI pipeline for other packages, it is important for this package to be ready for new PHP releases _early_, so failing the test suite on deprecatios/notices and warnings is appropriate. With that in mind, I deem it more appropriate to have a dedicated PHPUnit configuration file for PHPUnit 10 to ensure the test run will behave as intended. This commit adds this dedicated configuration file for PHPUnit 10.1+. Includes: * Ignoring the new file for package archives. * Allowing for a local override file. * Adding scripts to the `composer.json` file to run the tests using this new configuration file and make the use of the separate config make more obvious for contributors. * Updating the GH Actions `test` workflow to trigger the tests on PHPUnit 10 with this configuration file. Ref: * https://github.com/sebastianbergmann/phpunit/blob/main/ChangeLog-10.0.md#1000---2023-02-03 * sebastianbergmann/phpunit 5196 * https://github.com/sebastianbergmann/phpunit/commit/fb6673f06ef90b43667b7187722e2c840dcdb573 --- .gitattributes | 19 +++++++++--------- .github/workflows/test.yml | 11 ++++++++++- .gitignore | 1 + composer.json | 12 ++++++++---- phpunit10.xml.dist | 40 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 69 insertions(+), 14 deletions(-) create mode 100644 phpunit10.xml.dist diff --git a/.gitattributes b/.gitattributes index 2eb1a64..a0a6f39 100644 --- a/.gitattributes +++ b/.gitattributes @@ -5,15 +5,16 @@ # 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 -appveyor.yml export-ignore -box.json export-ignore -phpcs.xml.dist export-ignore -phpunit.xml.dist export-ignore -/.github/ export-ignore -/doc/ export-ignore -/tests/ export-ignore +.gitattributes export-ignore +.gitignore export-ignore +appveyor.yml export-ignore +box.json export-ignore +phpcs.xml.dist export-ignore +phpunit.xml.dist export-ignore +phpunit10.xml.dist export-ignore +/.github/ export-ignore +/doc/ 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 5157fba..24a750b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -152,9 +152,18 @@ jobs: - name: 'Integration test 2 - linting own code' run: ./parallel-lint --exclude vendor --exclude tests/fixtures . - - name: 'Run unit tests' + - 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: "Run unit tests (PHPUnit < 10)" + if: ${{ ! startsWith( steps.phpunit_version.outputs.VERSION, '10.' ) }} run: composer test + - name: "Run unit tests (PHPUnit < 10)" + if: ${{ startsWith( steps.phpunit_version.outputs.VERSION, '10.' ) }} + run: composer test10 + - uses: actions/download-artifact@v4 with: name: parallel-lint-phar diff --git a/.gitignore b/.gitignore index 4c1c0ec..5938b53 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ composer.lock phpcs.xml .phpunit.result.cache phpunit.xml +phpunit10.xml diff --git a/composer.json b/composer.json index 2e3caac..334e2eb 100644 --- a/composer.json +++ b/composer.json @@ -22,7 +22,7 @@ "jakub-onderka/php-parallel-lint": "*" }, "require-dev": { - "phpunit/phpunit": "^4.8.36 || ^5.7.21 || ^6.0 || ^7.0 || ^8.0 || ^9.0", + "phpunit/phpunit": "^4.8.36 || ^5.7.21 || ^6.0 || ^7.0 || ^8.0 || ^9.0 || ^10.1", "php-parallel-lint/php-console-highlighter": "0.* || ^1.0", "php-parallel-lint/php-code-style": "^2.0" }, @@ -50,10 +50,14 @@ ], "scripts": { "test": "@php ./vendor/phpunit/phpunit/phpunit --no-coverage", - "coverage": "@php ./vendor/phpunit/phpunit/phpunit" + "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" }, "scripts-descriptions": { - "test": "Run all tests!", - "coverage": "Run all tests *with code coverage*" + "test": "Run all tests! ( PHPUnit < 10)", + "test10": "Run all tests! ( PHPUnit 10+)", + "coverage": "Run all tests *with code coverage* ( PHPUnit < 10)", + "coverage10": "Run all tests *with code coverage* ( PHPUnit 10+)" } } diff --git a/phpunit10.xml.dist b/phpunit10.xml.dist new file mode 100644 index 0000000..140810b --- /dev/null +++ b/phpunit10.xml.dist @@ -0,0 +1,40 @@ + + + + + + tests/Unit + + + + + + ./src/ + + + + + + + + + + +