From d03c848562ad6a15547269993b23a21c6707e92e Mon Sep 17 00:00:00 2001 From: jrfnl Date: Thu, 11 Sep 2025 19:12:56 +0200 Subject: [PATCH 1/3] Drop support for PHP < 7.2 This commit is a plain version drop. This commit does **not** include: * Removing any work-arounds which _may_ exist in the codebase, to support PHP < 7.2. * Modernizing the codebase. These things can be addressed at will in follow up PRs. Fixes 2606 --- .github/CONTRIBUTING.md | 2 +- .github/workflows/quicktest.yml | 2 +- .github/workflows/unit-tests.yml | 14 +++++--------- .phpcs.xml.dist | 13 +------------ README.md | 4 ++-- composer.json | 4 ++-- phpstan.neon.dist | 2 +- phpunit.xml.dist | 2 +- 8 files changed, 14 insertions(+), 29 deletions(-) diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 93a23e59b1..53bdd051fd 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -65,7 +65,7 @@ When you introduce new `public` sniff properties, or your sniff extends a class * PHP_CodeSniffer 3.13.0 or higher * PHPCSUtils 1.1.0 or higher * PHPCSExtra 1.4.0 or higher -* PHPUnit 4.x - 9.x +* PHPUnit 8.x - 9.x The WordPress Coding Standards use the `PHP_CodeSniffer` native unit test framework for unit testing the sniffs. diff --git a/.github/workflows/quicktest.yml b/.github/workflows/quicktest.yml index 355bd3208b..e777483c59 100644 --- a/.github/workflows/quicktest.yml +++ b/.github/workflows/quicktest.yml @@ -23,7 +23,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - php: [ '5.4', 'latest' ] + php: [ '7.2', 'latest' ] dependencies: [ 'lowest', 'stable' ] name: QTest - PHP ${{ matrix.php }} on PHPCS ${{ matrix.dependencies }} diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index 33d5e713f0..f4fae9ceaa 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -26,7 +26,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - php: [ '5.5', '5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3', '8.5' ] + php: [ '7.3', '7.4', '8.0', '8.1', '8.2', '8.3', '8.5' ] dependencies: [ 'lowest', 'stable' ] extensions: [ '' ] coverage: [false] @@ -38,11 +38,11 @@ jobs: coverage: true # Make sure coverage is recorded for this too. # Run code coverage builds against high/low PHP and high/low PHPCS. - - php: '5.4' + - php: '7.2' dependencies: 'stable' extensions: '' coverage: true - - php: '5.4' + - php: '7.2' dependencies: 'lowest' extensions: '' coverage: true @@ -56,15 +56,11 @@ jobs: coverage: true # Test against dev versions of all dependencies with select PHP versions for early detection of issues. - - php: '5.4' - dependencies: 'dev' - extensions: '' - coverage: false - - php: '7.0' + - php: '7.2' dependencies: 'dev' extensions: '' coverage: false - - php: '7.4' + - php: '8.1' dependencies: 'dev' extensions: '' coverage: false diff --git a/.phpcs.xml.dist b/.phpcs.xml.dist index bc350b7977..ed1ea01065 100644 --- a/.phpcs.xml.dist +++ b/.phpcs.xml.dist @@ -50,24 +50,13 @@ - - - - + - - - - - - - - diff --git a/README.md b/README.md index eeb99a1422..02fef784bd 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ [![codecov.io](https://codecov.io/gh/WordPress/WordPress-Coding-Standards/graph/badge.svg?token=UzFYn0RzVG&branch=develop)](https://codecov.io/gh/WordPress/WordPress-Coding-Standards?branch=develop) [![Minimum PHP Version](https://img.shields.io/packagist/php-v/wp-coding-standards/wpcs.svg?maxAge=3600)](https://packagist.org/packages/wp-coding-standards/wpcs) -[![Tested on PHP 5.4 to 8.4](https://img.shields.io/badge/tested%20on-PHP%205.4%20|%205.5%20|%205.6%20|%207.0%20|%207.1%20|%207.2%20|%207.3%20|%207.4%20|%208.0%20|%208.1%20|%208.2%20|%208.3%20|%208.4-green.svg?maxAge=2419200)](https://github.com/WordPress/WordPress-Coding-Standards/actions/workflows/unit-tests.yml) +[![Tested on PHP 7.2 to 8.4](https://img.shields.io/badge/tested%20on-PHP%207.2%20|%207.3%20|%207.4%20|%208.0%20|%208.1%20|%208.2%20|%208.3%20|%208.4-green.svg?maxAge=2419200)](https://github.com/WordPress/WordPress-Coding-Standards/actions/workflows/unit-tests.yml) [![License: MIT](https://poser.pugx.org/wp-coding-standards/wpcs/license)](https://github.com/WordPress/WordPress-Coding-Standards/blob/develop/LICENSE) [![Total Downloads](https://poser.pugx.org/wp-coding-standards/wpcs/downloads)](https://packagist.org/packages/wp-coding-standards/wpcs/stats) @@ -53,7 +53,7 @@ This project is a collection of [PHP_CodeSniffer](https://github.com/PHPCSStanda ## Minimum Requirements The WordPress Coding Standards package requires: -* PHP 5.4 or higher with the following extensions enabled: +* PHP 7.2 or higher with the following extensions enabled: - [Filter](https://www.php.net/book.filter) - [libxml](https://www.php.net/book.libxml) - [Tokenizer](https://www.php.net/book.tokenizer) diff --git a/composer.json b/composer.json index 37a8c46252..a5afb55f6b 100644 --- a/composer.json +++ b/composer.json @@ -16,7 +16,7 @@ } ], "require": { - "php": ">=5.4", + "php": ">=7.2", "ext-filter": "*", "ext-libxml": "*", "ext-tokenizer": "*", @@ -27,7 +27,7 @@ }, "require-dev": { "phpcompatibility/php-compatibility": "^9.0", - "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0 || ^8.0 || ^9.0", + "phpunit/phpunit": "^8.0 || ^9.0", "phpcsstandards/phpcsdevtools": "^1.2.0", "php-parallel-lint/php-parallel-lint": "^1.4.0", "php-parallel-lint/php-console-highlighter": "^1.0.0" diff --git a/phpstan.neon.dist b/phpstan.neon.dist index e9edfc43bc..b69c29b925 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -1,5 +1,5 @@ parameters: - phpVersion: 70100 # Needs to be 70100 or higher... sigh... + phpVersion: 70200 level: 5 paths: - WordPress diff --git a/phpunit.xml.dist b/phpunit.xml.dist index a5f12e7386..a7a2b1401f 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,7 +1,7 @@ Date: Tue, 5 Aug 2025 16:47:51 -0300 Subject: [PATCH 2/3] Tests: use standardized fixture methods As support for PHPUnit < 8.0 will now be dropped, we no longer need to use the `@before`/`@after`[Class] annotations for fixture methods and can revert back to using the standard PHPUnit `setUp|tearDown[BeforeClass]()` fixture methods (with a `void` return type). --- WordPress/Tests/DB/RestrictedClassesUnitTest.php | 9 +++------ WordPress/Tests/DB/RestrictedFunctionsUnitTest.php | 9 ++------- 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/WordPress/Tests/DB/RestrictedClassesUnitTest.php b/WordPress/Tests/DB/RestrictedClassesUnitTest.php index dab29264cf..a07ace04d8 100644 --- a/WordPress/Tests/DB/RestrictedClassesUnitTest.php +++ b/WordPress/Tests/DB/RestrictedClassesUnitTest.php @@ -32,11 +32,10 @@ final class RestrictedClassesUnitTest extends AbstractSniffUnitTest { * Note: as that class extends the abstract FunctionRestrictions class, that's * where we are passing the parameters to. * - * @before - * * @return void */ - protected function enhanceGroups() { + protected function setUp(): void { + parent::setUp(); AbstractFunctionRestrictionsSniff::$unittest_groups = array( 'test' => array( 'type' => 'error', @@ -52,11 +51,9 @@ protected function enhanceGroups() { /** * Reset the $groups property. * - * @after - * * @return void */ - protected function resetGroups() { + protected function tearDown(): void { AbstractFunctionRestrictionsSniff::$unittest_groups = array(); parent::tearDown(); } diff --git a/WordPress/Tests/DB/RestrictedFunctionsUnitTest.php b/WordPress/Tests/DB/RestrictedFunctionsUnitTest.php index 73702af626..ad17fc9e67 100644 --- a/WordPress/Tests/DB/RestrictedFunctionsUnitTest.php +++ b/WordPress/Tests/DB/RestrictedFunctionsUnitTest.php @@ -27,13 +27,10 @@ final class RestrictedFunctionsUnitTest extends AbstractSniffUnitTest { * Add a number of extra restricted functions to unit test the abstract * AbstractFunctionRestrictionsSniff class. * - * @before - * * @return void */ - protected function enhanceGroups() { + protected function setUp(): void { parent::setUp(); - AbstractFunctionRestrictionsSniff::$unittest_groups = array( 'test-empty-functions-array' => array( 'type' => 'error', @@ -52,11 +49,9 @@ protected function enhanceGroups() { /** * Reset the $groups property. * - * @after - * * @return void */ - protected function resetGroups() { + protected function tearDown(): void { AbstractFunctionRestrictionsSniff::$unittest_groups = array(); parent::tearDown(); } From 781bb22e4b1ab2f96b2c3539f071140959e19d50 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Mon, 15 Sep 2025 22:49:17 +0200 Subject: [PATCH 3/3] GH Actions: remove build with special set of extensions There was a special build included which is supposed disable Mbstring and record code coverage, but the `extensions` key was missing from the `setup-php` action runner, so Mbstring was never disabled.... Another thing to know about this build is that Mbstring is a required extension for PHPUnit, but it is only really needed when PHPUnit is run with the `--testdox` CLI flag. In later PHPUnit versions, this requirement is enforced across the board (Composer + PHAR), but that's not yet the case for the PHPUnit 8 PHAR file. However, as we run the tests via a Composer install, that install will still fail on the PHPUnit `mbstring` requirement. All in all, this build adds nothing and can be removed. --- .github/workflows/unit-tests.yml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index f4fae9ceaa..9eefe81bd2 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -32,11 +32,6 @@ jobs: coverage: [false] include: - - php: '7.2' - dependencies: 'stable' - extensions: ':mbstring' # = Disable Mbstring. - coverage: true # Make sure coverage is recorded for this too. - # Run code coverage builds against high/low PHP and high/low PHPCS. - php: '7.2' dependencies: 'stable'