From 8934ecad0672739311cede5132dd2090fb4f8c2e Mon Sep 17 00:00:00 2001 From: hbhalodia Date: Wed, 29 Apr 2026 12:46:19 +0530 Subject: [PATCH 01/14] Fix test and install.sh script to make test work --- composer.json | 2 +- phpunit/install.sh | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/composer.json b/composer.json index 7b4f5fc7..c8cb0f21 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,7 @@ "wp-coding-standards/wpcs": "^3.1", "phpcompatibility/phpcompatibility-wp": "^2.1", "yoast/phpunit-polyfills": "^1.0.1", - "phpunit/phpunit": "^5.7.21 || ^6.5 || ^7.5" + "phpunit/phpunit": "^5.7.21 || ^6.5 || ^7.5 || ^9" }, "scripts": { "e2e": "npx -y playwright test --timeout 300000" diff --git a/phpunit/install.sh b/phpunit/install.sh index 321c5c06..41a39401 100755 --- a/phpunit/install.sh +++ b/phpunit/install.sh @@ -55,11 +55,11 @@ install_wp_and_test_suite() { mv git-clone/wp-tests-config-sample.php $WP_TESTS_DIR/wp-tests-config.php # remove all forward slashes in the end WP_CORE_DIR=$(echo $WP_CORE_DIR | sed "s:/\+$::") - sed -i "s:dirname( __FILE__ ) . '/src/':'$WP_CORE_DIR/':" "$WP_TESTS_DIR"/wp-tests-config.php - sed -i "s/youremptytestdbnamehere/$DB_NAME/" "$WP_TESTS_DIR"/wp-tests-config.php - sed -i "s/yourusernamehere/$DB_USER/" "$WP_TESTS_DIR"/wp-tests-config.php - sed -i "s/yourpasswordhere/$DB_PASS/" "$WP_TESTS_DIR"/wp-tests-config.php - sed -i "s|localhost|${DB_HOST}|" "$WP_TESTS_DIR"/wp-tests-config.php + sed -i '' "s:dirname( __FILE__ ) . '/src/':'$WP_CORE_DIR/':" "$WP_TESTS_DIR"/wp-tests-config.php + sed -i '' "s/youremptytestdbnamehere/$DB_NAME/" "$WP_TESTS_DIR"/wp-tests-config.php + sed -i '' "s/yourusernamehere/$DB_USER/" "$WP_TESTS_DIR"/wp-tests-config.php + sed -i '' "s/yourpasswordhere/$DB_PASS/" "$WP_TESTS_DIR"/wp-tests-config.php + sed -i '' "s|localhost|${DB_HOST}|" "$WP_TESTS_DIR"/wp-tests-config.php fi rm -rf git-clone From e1eb21b2ab8113a5f29d2617d97aea98a35e2292 Mon Sep 17 00:00:00 2001 From: hbhalodia Date: Wed, 29 Apr 2026 12:52:49 +0530 Subject: [PATCH 02/14] Remove install.sh updates --- phpunit/install.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/phpunit/install.sh b/phpunit/install.sh index 41a39401..321c5c06 100755 --- a/phpunit/install.sh +++ b/phpunit/install.sh @@ -55,11 +55,11 @@ install_wp_and_test_suite() { mv git-clone/wp-tests-config-sample.php $WP_TESTS_DIR/wp-tests-config.php # remove all forward slashes in the end WP_CORE_DIR=$(echo $WP_CORE_DIR | sed "s:/\+$::") - sed -i '' "s:dirname( __FILE__ ) . '/src/':'$WP_CORE_DIR/':" "$WP_TESTS_DIR"/wp-tests-config.php - sed -i '' "s/youremptytestdbnamehere/$DB_NAME/" "$WP_TESTS_DIR"/wp-tests-config.php - sed -i '' "s/yourusernamehere/$DB_USER/" "$WP_TESTS_DIR"/wp-tests-config.php - sed -i '' "s/yourpasswordhere/$DB_PASS/" "$WP_TESTS_DIR"/wp-tests-config.php - sed -i '' "s|localhost|${DB_HOST}|" "$WP_TESTS_DIR"/wp-tests-config.php + sed -i "s:dirname( __FILE__ ) . '/src/':'$WP_CORE_DIR/':" "$WP_TESTS_DIR"/wp-tests-config.php + sed -i "s/youremptytestdbnamehere/$DB_NAME/" "$WP_TESTS_DIR"/wp-tests-config.php + sed -i "s/yourusernamehere/$DB_USER/" "$WP_TESTS_DIR"/wp-tests-config.php + sed -i "s/yourpasswordhere/$DB_PASS/" "$WP_TESTS_DIR"/wp-tests-config.php + sed -i "s|localhost|${DB_HOST}|" "$WP_TESTS_DIR"/wp-tests-config.php fi rm -rf git-clone From c4df7c472f83dbb9a064de335ed4aae4cdd2c6da Mon Sep 17 00:00:00 2001 From: hbhalodia Date: Wed, 29 Apr 2026 12:58:25 +0530 Subject: [PATCH 03/14] Update composer.json to add phpunit 8.5 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index c8cb0f21..49a2be6f 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,7 @@ "wp-coding-standards/wpcs": "^3.1", "phpcompatibility/phpcompatibility-wp": "^2.1", "yoast/phpunit-polyfills": "^1.0.1", - "phpunit/phpunit": "^5.7.21 || ^6.5 || ^7.5 || ^9" + "phpunit/phpunit": "^5.7.21 || ^6.5 || ^7.5 || ^8.5 || ^9" }, "scripts": { "e2e": "npx -y playwright test --timeout 300000" From cca371cb7981a4f49e786cccf4440facd5f24eb3 Mon Sep 17 00:00:00 2001 From: hbhalodia Date: Wed, 29 Apr 2026 13:17:21 +0530 Subject: [PATCH 04/14] Update install.sh script to resolve errors --- phpunit/install.sh | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/phpunit/install.sh b/phpunit/install.sh index 321c5c06..5f29b8ac 100755 --- a/phpunit/install.sh +++ b/phpunit/install.sh @@ -32,26 +32,25 @@ fi set -ex install_wp_and_test_suite() { - mkdir git-clone - # setup up WordPress if [ ! -d $WP_CORE_DIR ]; then mkdir -p $WP_CORE_DIR - checkout_wordpress_develop + checkout_wordpress_develop "$WP_TESTS_TAG" mv git-clone/src/* $WP_CORE_DIR fi # set up testing suite if it doesn't yet exist + # Always use trunk to ensure the test suite supports PHPUnit 8+ via the Yoast PHPUnit Polyfills. if [ ! -d $WP_TESTS_DIR ]; then # set up testing suite mkdir -p $WP_TESTS_DIR - checkout_wordpress_develop + checkout_wordpress_develop "trunk" mv git-clone/tests/phpunit/includes $WP_TESTS_DIR/includes mv git-clone/tests/phpunit/data $WP_TESTS_DIR/data fi if [ ! -f wp-tests-config.php ]; then - checkout_wordpress_develop + checkout_wordpress_develop "trunk" mv git-clone/wp-tests-config-sample.php $WP_TESTS_DIR/wp-tests-config.php # remove all forward slashes in the end WP_CORE_DIR=$(echo $WP_CORE_DIR | sed "s:/\+$::") @@ -87,9 +86,9 @@ install_db() { } checkout_wordpress_develop() { - if [ ! -d "git-clone/.git" ]; then - git clone --depth=1 --branch "${WP_TESTS_TAG}" https://github.com/WordPress/wordpress-develop.git git-clone - fi + local BRANCH="${1:-$WP_TESTS_TAG}" + rm -rf git-clone + git clone --depth=1 --branch "${BRANCH}" https://github.com/WordPress/wordpress-develop.git git-clone } install_wp_and_test_suite From 9e8300dd483b09f604dd181eac6abc50ae4d37b4 Mon Sep 17 00:00:00 2001 From: hbhalodia Date: Wed, 29 Apr 2026 14:53:04 +0530 Subject: [PATCH 05/14] Revert install.sh script --- phpunit/install.sh | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/phpunit/install.sh b/phpunit/install.sh index 5f29b8ac..321c5c06 100755 --- a/phpunit/install.sh +++ b/phpunit/install.sh @@ -32,25 +32,26 @@ fi set -ex install_wp_and_test_suite() { + mkdir git-clone + # setup up WordPress if [ ! -d $WP_CORE_DIR ]; then mkdir -p $WP_CORE_DIR - checkout_wordpress_develop "$WP_TESTS_TAG" + checkout_wordpress_develop mv git-clone/src/* $WP_CORE_DIR fi # set up testing suite if it doesn't yet exist - # Always use trunk to ensure the test suite supports PHPUnit 8+ via the Yoast PHPUnit Polyfills. if [ ! -d $WP_TESTS_DIR ]; then # set up testing suite mkdir -p $WP_TESTS_DIR - checkout_wordpress_develop "trunk" + checkout_wordpress_develop mv git-clone/tests/phpunit/includes $WP_TESTS_DIR/includes mv git-clone/tests/phpunit/data $WP_TESTS_DIR/data fi if [ ! -f wp-tests-config.php ]; then - checkout_wordpress_develop "trunk" + checkout_wordpress_develop mv git-clone/wp-tests-config-sample.php $WP_TESTS_DIR/wp-tests-config.php # remove all forward slashes in the end WP_CORE_DIR=$(echo $WP_CORE_DIR | sed "s:/\+$::") @@ -86,9 +87,9 @@ install_db() { } checkout_wordpress_develop() { - local BRANCH="${1:-$WP_TESTS_TAG}" - rm -rf git-clone - git clone --depth=1 --branch "${BRANCH}" https://github.com/WordPress/wordpress-develop.git git-clone + if [ ! -d "git-clone/.git" ]; then + git clone --depth=1 --branch "${WP_TESTS_TAG}" https://github.com/WordPress/wordpress-develop.git git-clone + fi } install_wp_and_test_suite From 626a82619ebe519cb1b89e4c5dbdce82b5e72eb4 Mon Sep 17 00:00:00 2001 From: hbhalodia Date: Wed, 29 Apr 2026 14:54:12 +0530 Subject: [PATCH 06/14] Add phpunit polyfill path --- phpunit/bootstrap.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/phpunit/bootstrap.php b/phpunit/bootstrap.php index b2090202..165550c2 100644 --- a/phpunit/bootstrap.php +++ b/phpunit/bootstrap.php @@ -42,5 +42,13 @@ function _manually_load_importer() { // Include the PHPUnit Polyfills autoloader. require dirname( __DIR__ ) . '/vendor/yoast/phpunit-polyfills/phpunitpolyfills-autoload.php'; +// Patch old WP test suites (< 5.9) that reject PHPUnit 8+. +// The version check lives in the test suite's bootstrap. If it only allows up to +// PHPUnit 7.x, we override it by defining WP_TESTS_PHPUNIT_POLYFILLS_PATH so the +// WP test suite knows polyfills are available and skips its hard version gate. +if ( ! defined( 'WP_TESTS_PHPUNIT_POLYFILLS_PATH' ) ) { + define( 'WP_TESTS_PHPUNIT_POLYFILLS_PATH', dirname( __DIR__ ) . '/vendor/yoast/phpunit-polyfills/' ); +} + // Start up the WP testing environment. require $_tests_dir . '/includes/bootstrap.php'; From e46621351214eb3b6738b9f6d10eda483664c046 Mon Sep 17 00:00:00 2001 From: hbhalodia Date: Wed, 29 Apr 2026 14:58:47 +0530 Subject: [PATCH 07/14] Fix composer failed test issue --- composer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 49a2be6f..a91c3028 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,8 @@ "wp-coding-standards/wpcs": "^3.1", "phpcompatibility/phpcompatibility-wp": "^2.1", "yoast/phpunit-polyfills": "^1.0.1", - "phpunit/phpunit": "^5.7.21 || ^6.5 || ^7.5 || ^8.5 || ^9" + "phpunit/phpunit": "^5.7.21 || ^6.5 || ^7.5 || ^8.5 || ^9", + "doctrine/instantiator": "^1.0" }, "scripts": { "e2e": "npx -y playwright test --timeout 300000" From 7c21ada3a6a847ade81b9d994863dd1a578057f4 Mon Sep 17 00:00:00 2001 From: hbhalodia Date: Wed, 29 Apr 2026 15:02:39 +0530 Subject: [PATCH 08/14] Fix remaining unit test issues --- phpunit/bootstrap.php | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/phpunit/bootstrap.php b/phpunit/bootstrap.php index 165550c2..c721bfb3 100644 --- a/phpunit/bootstrap.php +++ b/phpunit/bootstrap.php @@ -43,12 +43,21 @@ function _manually_load_importer() { require dirname( __DIR__ ) . '/vendor/yoast/phpunit-polyfills/phpunitpolyfills-autoload.php'; // Patch old WP test suites (< 5.9) that reject PHPUnit 8+. -// The version check lives in the test suite's bootstrap. If it only allows up to -// PHPUnit 7.x, we override it by defining WP_TESTS_PHPUNIT_POLYFILLS_PATH so the -// WP test suite knows polyfills are available and skips its hard version gate. +// WP 5.9+ checks WP_TESTS_PHPUNIT_POLYFILLS_PATH and skips the version gate. if ( ! defined( 'WP_TESTS_PHPUNIT_POLYFILLS_PATH' ) ) { define( 'WP_TESTS_PHPUNIT_POLYFILLS_PATH', dirname( __DIR__ ) . '/vendor/yoast/phpunit-polyfills/' ); } +// For WP < 5.9 test suites: the compat.php file has a hard version check that +// rejects PHPUnit 8+ and doesn't know about WP_TESTS_PHPUNIT_POLYFILLS_PATH. +// Replace it with a no-op so the polyfills can handle compatibility instead. +$_compat_file = $_tests_dir . '/includes/phpunit6/compat.php'; +if ( file_exists( $_compat_file ) ) { + $_compat_contents = file_get_contents( $_compat_file ); + if ( false === strpos( $_compat_contents, 'WP_TESTS_PHPUNIT_POLYFILLS_PATH' ) ) { + file_put_contents( $_compat_file, " Date: Wed, 29 Apr 2026 15:11:14 +0530 Subject: [PATCH 09/14] Fix unit test --- phpunit/bootstrap.php | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/phpunit/bootstrap.php b/phpunit/bootstrap.php index c721bfb3..7164bbe3 100644 --- a/phpunit/bootstrap.php +++ b/phpunit/bootstrap.php @@ -48,16 +48,26 @@ function _manually_load_importer() { define( 'WP_TESTS_PHPUNIT_POLYFILLS_PATH', dirname( __DIR__ ) . '/vendor/yoast/phpunit-polyfills/' ); } -// For WP < 5.9 test suites: the compat.php file has a hard version check that -// rejects PHPUnit 8+ and doesn't know about WP_TESTS_PHPUNIT_POLYFILLS_PATH. -// Replace it with a no-op so the polyfills can handle compatibility instead. +// For WP < 5.9 test suites: the compat.php has a hard PHPUnit version gate +// that calls exit(1) for PHPUnit 8+. Comment out exit() calls to let the +// Yoast polyfills handle compatibility, while preserving any compat shims. $_compat_file = $_tests_dir . '/includes/phpunit6/compat.php'; if ( file_exists( $_compat_file ) ) { $_compat_contents = file_get_contents( $_compat_file ); - if ( false === strpos( $_compat_contents, 'WP_TESTS_PHPUNIT_POLYFILLS_PATH' ) ) { - file_put_contents( $_compat_file, " Date: Wed, 29 Apr 2026 15:14:19 +0530 Subject: [PATCH 10/14] Revert bootstrap file --- phpunit/bootstrap.php | 27 --------------------------- 1 file changed, 27 deletions(-) diff --git a/phpunit/bootstrap.php b/phpunit/bootstrap.php index 7164bbe3..b2090202 100644 --- a/phpunit/bootstrap.php +++ b/phpunit/bootstrap.php @@ -42,32 +42,5 @@ function _manually_load_importer() { // Include the PHPUnit Polyfills autoloader. require dirname( __DIR__ ) . '/vendor/yoast/phpunit-polyfills/phpunitpolyfills-autoload.php'; -// Patch old WP test suites (< 5.9) that reject PHPUnit 8+. -// WP 5.9+ checks WP_TESTS_PHPUNIT_POLYFILLS_PATH and skips the version gate. -if ( ! defined( 'WP_TESTS_PHPUNIT_POLYFILLS_PATH' ) ) { - define( 'WP_TESTS_PHPUNIT_POLYFILLS_PATH', dirname( __DIR__ ) . '/vendor/yoast/phpunit-polyfills/' ); -} - -// For WP < 5.9 test suites: the compat.php has a hard PHPUnit version gate -// that calls exit(1) for PHPUnit 8+. Comment out exit() calls to let the -// Yoast polyfills handle compatibility, while preserving any compat shims. -$_compat_file = $_tests_dir . '/includes/phpunit6/compat.php'; -if ( file_exists( $_compat_file ) ) { - $_compat_contents = file_get_contents( $_compat_file ); - if ( false === strpos( $_compat_contents, 'WP_TESTS_PHPUNIT_POLYFILLS_PATH' ) && false !== strpos( $_compat_contents, 'exit' ) ) { - $_compat_contents = str_replace( 'exit( 1 );', '// exit( 1 );', $_compat_contents ); - $_compat_contents = str_replace( 'exit(1);', '// exit(1);', $_compat_contents ); - file_put_contents( $_compat_file, $_compat_contents ); - } -} - -// Provide a stub for PHPUnit\Util\Getopt which was removed in PHPUnit 9.x -// but referenced by old WP test suite compat files. -if ( ! class_exists( 'PHPUnit\Util\Getopt' ) ) { - // phpcs:ignore Generic.Files.OneObjectStructurePerFile.MultipleFound - class PHPUnit_Util_Getopt_Stub {} - class_alias( 'PHPUnit_Util_Getopt_Stub', 'PHPUnit\Util\Getopt' ); -} - // Start up the WP testing environment. require $_tests_dir . '/includes/bootstrap.php'; From 8378d017239ab7031c28c88f07bd587f0b3f4815 Mon Sep 17 00:00:00 2001 From: hbhalodia Date: Wed, 29 Apr 2026 15:16:31 +0530 Subject: [PATCH 11/14] Remove doctrine instantiator --- composer.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/composer.json b/composer.json index a91c3028..49a2be6f 100644 --- a/composer.json +++ b/composer.json @@ -18,8 +18,7 @@ "wp-coding-standards/wpcs": "^3.1", "phpcompatibility/phpcompatibility-wp": "^2.1", "yoast/phpunit-polyfills": "^1.0.1", - "phpunit/phpunit": "^5.7.21 || ^6.5 || ^7.5 || ^8.5 || ^9", - "doctrine/instantiator": "^1.0" + "phpunit/phpunit": "^5.7.21 || ^6.5 || ^7.5 || ^8.5 || ^9" }, "scripts": { "e2e": "npx -y playwright test --timeout 300000" From d2cdad05a4ba80bf1fda820459c40e0f9cb96f03 Mon Sep 17 00:00:00 2001 From: hbhalodia Date: Wed, 29 Apr 2026 15:39:19 +0530 Subject: [PATCH 12/14] Update test suite and patch bootstrap --- .github/workflows/tests.yml | 24 +++++++++++------------- phpunit/bootstrap.php | 24 ++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 13 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 9adeff03..6cca55b1 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -122,10 +122,8 @@ jobs: run: phpunit/install.sh wordpress_test root '' 127.0.0.1:3306 ${{ matrix.wp }} # Determine the type of Composer install which is needed. - # 1. WP 5.9 or higher - all PHPUnit versions needed are supported, use the most appropriate one. - # 2. WP 5.9 or higher with PHP 8.2 (RC) - not all dependencies of PHPUnit have declared PHP 8.2 compatibility, so needs ignore platform. - # 3. WP < 5.9 with PHP < 8.0 - PHPUnit 5 - 7 supported, use the most appropriate one. - # 4. WP < 5.9 with PHP 8.0 or higher - PHPUnit 5 - 7 supported, needs ignore platform reqs to install PHPUnit 7 for PHP >= 8.0. + # 1. Normal - most PHP/WP combinations. + # 2. Ignore platform reqs - needed for PHP 8.0+ on WP < 5.9 or PHP 8.2 on WP >= 5.9. - name: Determine the type of Composer install to use id: composer_toggle run: | @@ -136,30 +134,30 @@ jobs: echo 'TYPE=2' >> $GITHUB_OUTPUT fi elif [[ "${{ matrix.php }}" > "7.4" ]]; then - echo 'TYPE=4' >> $GITHUB_OUTPUT + echo 'TYPE=2' >> $GITHUB_OUTPUT else - echo 'TYPE=3' >> $GITHUB_OUTPUT + echo 'TYPE=1' >> $GITHUB_OUTPUT fi - # Remove the PHPUnit requirement for WP 5.9 and higher in favour of letting the Polyfills manage it. - # The Composer command will exit with error code 2 as the package is not removed, so ignore "failure" of this step. - - name: Conditionally remove PHPUnit requirement - if: ${{ steps.composer_toggle.outputs.TYPE == '1' || steps.composer_toggle.outputs.TYPE == '2' }} + # Remove the PHPUnit requirement in favour of letting the Polyfills manage it. + # PHPUnit 5.x-7.x can no longer be resolved from Packagist, so this must + # be done for all PHP/WP combinations. + - name: Remove PHPUnit requirement continue-on-error: true run: composer remove --dev phpunit/phpunit --no-update --no-interaction || true # Install dependencies and handle caching in one go. # @link https://github.com/marketplace/actions/install-php-dependencies-with-composer - name: Install Composer dependencies - normal - if: ${{ steps.composer_toggle.outputs.TYPE == '1' || steps.composer_toggle.outputs.TYPE == '3' }} + if: ${{ steps.composer_toggle.outputs.TYPE == '1' }} uses: "ramsey/composer-install@v3" with: # Bust the cache at least once a month - output format: YYYY-MM-DD. custom-cache-suffix: $(date -u -d "-0 month -$(($(date +%d)-1)) days" "+%F") - # For PHP 8.0 and above on WP 5.2 - 5.8, we need to install with ignore platform reqs as not all dependencies allow it. + # For PHP 8.0+ on WP < 5.9 or PHP 8.2 on WP >= 5.9, we need to install with ignore platform reqs. - name: Install Composer dependencies with ignore platform reqs - if: ${{ steps.composer_toggle.outputs.TYPE == '2' || steps.composer_toggle.outputs.TYPE == '4' }} + if: ${{ steps.composer_toggle.outputs.TYPE == '2' }} uses: "ramsey/composer-install@v3" with: composer-options: --ignore-platform-req=php diff --git a/phpunit/bootstrap.php b/phpunit/bootstrap.php index b2090202..66b35216 100644 --- a/phpunit/bootstrap.php +++ b/phpunit/bootstrap.php @@ -42,5 +42,29 @@ function _manually_load_importer() { // Include the PHPUnit Polyfills autoloader. require dirname( __DIR__ ) . '/vendor/yoast/phpunit-polyfills/phpunitpolyfills-autoload.php'; +// Define WP_TESTS_PHPUNIT_POLYFILLS_PATH for WP 5.9+ test suites. +if ( ! defined( 'WP_TESTS_PHPUNIT_POLYFILLS_PATH' ) ) { + define( 'WP_TESTS_PHPUNIT_POLYFILLS_PATH', dirname( __DIR__ ) . '/vendor/yoast/phpunit-polyfills/' ); +} + +// For WP < 5.9 test suites: the bootstrap.php has a hard PHPUnit version check +// that rejects PHPUnit 8+ and exits BEFORE checking for polyfills. Patch it at +// runtime by commenting out the exit call in the version gate block. +$_wp_bootstrap = $_tests_dir . '/includes/bootstrap.php'; +if ( file_exists( $_wp_bootstrap ) ) { + $_wp_bootstrap_contents = file_get_contents( $_wp_bootstrap ); + if ( false !== strpos( $_wp_bootstrap_contents, "only compatible with PHPUnit up to 7.x" ) + && false === strpos( $_wp_bootstrap_contents, 'WP_TESTS_PHPUNIT_POLYFILLS_PATH' ) + ) { + // Remove the version gate that rejects PHPUnit 8+. + $_wp_bootstrap_contents = preg_replace( + '/\bif\s*\(\s*version_compare\s*\(\s*\$phpunit_version\s*,\s*[\'"]5\.7\.21[\'"]\s*,\s*[\'"]<[\'"]\s*\)\s*\|\|\s*version_compare\s*\(\s*\$phpunit_version\s*,\s*[\'"]8\.0[\'"]\s*,\s*[\'"]>=[\'"]\s*\)\s*\)\s*\{[^}]+\}/s', + '/* PHPUnit version gate removed by wordpress-importer - using Yoast PHPUnit Polyfills instead. */', + $_wp_bootstrap_contents + ); + file_put_contents( $_wp_bootstrap, $_wp_bootstrap_contents ); + } +} + // Start up the WP testing environment. require $_tests_dir . '/includes/bootstrap.php'; From e50e4f012383b49b8022e896ac2c71192095560f Mon Sep 17 00:00:00 2001 From: hbhalodia Date: Wed, 29 Apr 2026 15:41:12 +0530 Subject: [PATCH 13/14] Revert bootstrap and tests.yml --- .github/workflows/tests.yml | 24 +++++++++++++----------- phpunit/bootstrap.php | 24 ------------------------ 2 files changed, 13 insertions(+), 35 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 6cca55b1..9adeff03 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -122,8 +122,10 @@ jobs: run: phpunit/install.sh wordpress_test root '' 127.0.0.1:3306 ${{ matrix.wp }} # Determine the type of Composer install which is needed. - # 1. Normal - most PHP/WP combinations. - # 2. Ignore platform reqs - needed for PHP 8.0+ on WP < 5.9 or PHP 8.2 on WP >= 5.9. + # 1. WP 5.9 or higher - all PHPUnit versions needed are supported, use the most appropriate one. + # 2. WP 5.9 or higher with PHP 8.2 (RC) - not all dependencies of PHPUnit have declared PHP 8.2 compatibility, so needs ignore platform. + # 3. WP < 5.9 with PHP < 8.0 - PHPUnit 5 - 7 supported, use the most appropriate one. + # 4. WP < 5.9 with PHP 8.0 or higher - PHPUnit 5 - 7 supported, needs ignore platform reqs to install PHPUnit 7 for PHP >= 8.0. - name: Determine the type of Composer install to use id: composer_toggle run: | @@ -134,30 +136,30 @@ jobs: echo 'TYPE=2' >> $GITHUB_OUTPUT fi elif [[ "${{ matrix.php }}" > "7.4" ]]; then - echo 'TYPE=2' >> $GITHUB_OUTPUT + echo 'TYPE=4' >> $GITHUB_OUTPUT else - echo 'TYPE=1' >> $GITHUB_OUTPUT + echo 'TYPE=3' >> $GITHUB_OUTPUT fi - # Remove the PHPUnit requirement in favour of letting the Polyfills manage it. - # PHPUnit 5.x-7.x can no longer be resolved from Packagist, so this must - # be done for all PHP/WP combinations. - - name: Remove PHPUnit requirement + # Remove the PHPUnit requirement for WP 5.9 and higher in favour of letting the Polyfills manage it. + # The Composer command will exit with error code 2 as the package is not removed, so ignore "failure" of this step. + - name: Conditionally remove PHPUnit requirement + if: ${{ steps.composer_toggle.outputs.TYPE == '1' || steps.composer_toggle.outputs.TYPE == '2' }} continue-on-error: true run: composer remove --dev phpunit/phpunit --no-update --no-interaction || true # Install dependencies and handle caching in one go. # @link https://github.com/marketplace/actions/install-php-dependencies-with-composer - name: Install Composer dependencies - normal - if: ${{ steps.composer_toggle.outputs.TYPE == '1' }} + if: ${{ steps.composer_toggle.outputs.TYPE == '1' || steps.composer_toggle.outputs.TYPE == '3' }} uses: "ramsey/composer-install@v3" with: # Bust the cache at least once a month - output format: YYYY-MM-DD. custom-cache-suffix: $(date -u -d "-0 month -$(($(date +%d)-1)) days" "+%F") - # For PHP 8.0+ on WP < 5.9 or PHP 8.2 on WP >= 5.9, we need to install with ignore platform reqs. + # For PHP 8.0 and above on WP 5.2 - 5.8, we need to install with ignore platform reqs as not all dependencies allow it. - name: Install Composer dependencies with ignore platform reqs - if: ${{ steps.composer_toggle.outputs.TYPE == '2' }} + if: ${{ steps.composer_toggle.outputs.TYPE == '2' || steps.composer_toggle.outputs.TYPE == '4' }} uses: "ramsey/composer-install@v3" with: composer-options: --ignore-platform-req=php diff --git a/phpunit/bootstrap.php b/phpunit/bootstrap.php index 66b35216..b2090202 100644 --- a/phpunit/bootstrap.php +++ b/phpunit/bootstrap.php @@ -42,29 +42,5 @@ function _manually_load_importer() { // Include the PHPUnit Polyfills autoloader. require dirname( __DIR__ ) . '/vendor/yoast/phpunit-polyfills/phpunitpolyfills-autoload.php'; -// Define WP_TESTS_PHPUNIT_POLYFILLS_PATH for WP 5.9+ test suites. -if ( ! defined( 'WP_TESTS_PHPUNIT_POLYFILLS_PATH' ) ) { - define( 'WP_TESTS_PHPUNIT_POLYFILLS_PATH', dirname( __DIR__ ) . '/vendor/yoast/phpunit-polyfills/' ); -} - -// For WP < 5.9 test suites: the bootstrap.php has a hard PHPUnit version check -// that rejects PHPUnit 8+ and exits BEFORE checking for polyfills. Patch it at -// runtime by commenting out the exit call in the version gate block. -$_wp_bootstrap = $_tests_dir . '/includes/bootstrap.php'; -if ( file_exists( $_wp_bootstrap ) ) { - $_wp_bootstrap_contents = file_get_contents( $_wp_bootstrap ); - if ( false !== strpos( $_wp_bootstrap_contents, "only compatible with PHPUnit up to 7.x" ) - && false === strpos( $_wp_bootstrap_contents, 'WP_TESTS_PHPUNIT_POLYFILLS_PATH' ) - ) { - // Remove the version gate that rejects PHPUnit 8+. - $_wp_bootstrap_contents = preg_replace( - '/\bif\s*\(\s*version_compare\s*\(\s*\$phpunit_version\s*,\s*[\'"]5\.7\.21[\'"]\s*,\s*[\'"]<[\'"]\s*\)\s*\|\|\s*version_compare\s*\(\s*\$phpunit_version\s*,\s*[\'"]8\.0[\'"]\s*,\s*[\'"]>=[\'"]\s*\)\s*\)\s*\{[^}]+\}/s', - '/* PHPUnit version gate removed by wordpress-importer - using Yoast PHPUnit Polyfills instead. */', - $_wp_bootstrap_contents - ); - file_put_contents( $_wp_bootstrap, $_wp_bootstrap_contents ); - } -} - // Start up the WP testing environment. require $_tests_dir . '/includes/bootstrap.php'; From a80c08b3aa458ec181d9dfd97f7ae2ab768d51e4 Mon Sep 17 00:00:00 2001 From: hbhalodia Date: Wed, 29 Apr 2026 15:48:20 +0530 Subject: [PATCH 14/14] Fix unit test cases --- composer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 49a2be6f..a91c3028 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,8 @@ "wp-coding-standards/wpcs": "^3.1", "phpcompatibility/phpcompatibility-wp": "^2.1", "yoast/phpunit-polyfills": "^1.0.1", - "phpunit/phpunit": "^5.7.21 || ^6.5 || ^7.5 || ^8.5 || ^9" + "phpunit/phpunit": "^5.7.21 || ^6.5 || ^7.5 || ^8.5 || ^9", + "doctrine/instantiator": "^1.0" }, "scripts": { "e2e": "npx -y playwright test --timeout 300000"