From db1251cae8efb28fa7d46cc783001c88fe9b30ec Mon Sep 17 00:00:00 2001 From: robelsust Date: Sat, 10 Oct 2026 11:34:47 +0600 Subject: [PATCH 1/7] Tests: Add a separate PHPUnit configuration file for PHPUnit 10.1 and later - Add phpunit10.xml.dist and tests/phpunit/multisite10.xml compliant with PHPUnit 10.1+ schema. - Update reusable-phpunit-tests-v3.yml with automated detection to select the PHPUnit 10+ configuration when running on PHPUnit 10+. - Fix hardcoded -c phpunit.xml.dist in reusable-phpunit-tests-v1.yml and v2.yml external-http step to use PHPUNIT_CONFIG. - Update workflow path triggers in phpunit-tests.yml, full matrix, test-coverage, and exclude from asset workflows. - Add test10 script in composer.json and test:php10 in package.json. - Add /phpunit10.xml to .gitignore and update configuration documentation in tests/phpunit/README.md. See #66210, #62004. --- .github/workflows/end-to-end-tests.yml | 1 + .github/workflows/performance.yml | 1 + .../workflows/phpunit-tests-full-matrix.yml | 1 + .github/workflows/phpunit-tests.yml | 1 + .../workflows/reusable-phpunit-tests-v1.yml | 2 +- .../workflows/reusable-phpunit-tests-v2.yml | 2 +- .../workflows/reusable-phpunit-tests-v3.yml | 14 +++ .github/workflows/test-build-processes.yml | 1 + .github/workflows/test-coverage.yml | 4 + .gitignore | 2 + composer.json | 3 +- package.json | 1 + phpunit10.xml.dist | 85 +++++++++++++++++++ tests/phpunit/README.md | 17 ++++ tests/phpunit/multisite10.xml | 84 ++++++++++++++++++ 15 files changed, 216 insertions(+), 3 deletions(-) create mode 100644 phpunit10.xml.dist create mode 100644 tests/phpunit/multisite10.xml diff --git a/.github/workflows/end-to-end-tests.yml b/.github/workflows/end-to-end-tests.yml index b3f9882fb8578..533fc72fd2437 100644 --- a/.github/workflows/end-to-end-tests.yml +++ b/.github/workflows/end-to-end-tests.yml @@ -32,6 +32,7 @@ on: - '!phpcs.xml.dist' - '!phpstan.neon.dist' - '!phpunit.xml.dist' + - '!phpunit10.xml.dist' - '!tsconfig.json' # Other test suites, tools, and workflows do not affect these tests. - '!tests/**' diff --git a/.github/workflows/performance.yml b/.github/workflows/performance.yml index 057fc827d14de..d67286e315009 100644 --- a/.github/workflows/performance.yml +++ b/.github/workflows/performance.yml @@ -32,6 +32,7 @@ on: - '!phpcs.xml.dist' - '!phpstan.neon.dist' - '!phpunit.xml.dist' + - '!phpunit10.xml.dist' - '!tsconfig.json' # Other test suites, tools, and workflows do not affect these tests. - '!tests/**' diff --git a/.github/workflows/phpunit-tests-full-matrix.yml b/.github/workflows/phpunit-tests-full-matrix.yml index eedbbdb087e4e..dcc0d82da71ab 100644 --- a/.github/workflows/phpunit-tests-full-matrix.yml +++ b/.github/workflows/phpunit-tests-full-matrix.yml @@ -42,6 +42,7 @@ on: - 'tools/vendors/**' - 'tools/webpack/**' - 'phpunit.xml.dist' + - 'phpunit10.xml.dist' - '.github/actions/setup-npm/**' - '.github/workflows/phpunit-tests.yml' - '.github/workflows/phpunit-tests-full-matrix.yml' diff --git a/.github/workflows/phpunit-tests.yml b/.github/workflows/phpunit-tests.yml index 632d81ea38b39..e08482d210f1b 100644 --- a/.github/workflows/phpunit-tests.yml +++ b/.github/workflows/phpunit-tests.yml @@ -46,6 +46,7 @@ on: - 'tools/vendors/**' - 'tools/webpack/**' - 'phpunit.xml.dist' + - 'phpunit10.xml.dist' - '.github/actions/setup-npm/**' - '.github/workflows/phpunit-tests.yml' - '.github/workflows/phpunit-tests-full-matrix.yml' diff --git a/.github/workflows/reusable-phpunit-tests-v1.yml b/.github/workflows/reusable-phpunit-tests-v1.yml index dc5a0d1edd982..a9a9fc5f6f584 100644 --- a/.github/workflows/reusable-phpunit-tests-v1.yml +++ b/.github/workflows/reusable-phpunit-tests-v1.yml @@ -247,4 +247,4 @@ jobs: - name: Run external HTTP tests if: ${{ ! inputs.multisite && ! inputs.split_slow && ! inputs.phpunit-test-groups }} - run: npm run "test:${PHPUNIT_SCRIPT}" -- --verbose -c phpunit.xml.dist --group external-http + run: npm run "test:${PHPUNIT_SCRIPT}" -- --verbose -c "${PHPUNIT_CONFIG}" --group external-http diff --git a/.github/workflows/reusable-phpunit-tests-v2.yml b/.github/workflows/reusable-phpunit-tests-v2.yml index 628b5387f0e4f..56767756f0315 100644 --- a/.github/workflows/reusable-phpunit-tests-v2.yml +++ b/.github/workflows/reusable-phpunit-tests-v2.yml @@ -254,7 +254,7 @@ jobs: - name: Run external HTTP tests if: ${{ ! inputs.multisite && ! inputs.split_slow && ! inputs.phpunit-test-groups }} - run: npm run "test:${PHPUNIT_SCRIPT}" -- --verbose -c phpunit.xml.dist --group external-http + run: npm run "test:${PHPUNIT_SCRIPT}" -- --verbose -c "${PHPUNIT_CONFIG}" --group external-http # __fakegroup__ is excluded to force PHPUnit to ignore the settings in phpunit.xml.dist. - name: Run (xDebug) tests diff --git a/.github/workflows/reusable-phpunit-tests-v3.yml b/.github/workflows/reusable-phpunit-tests-v3.yml index 01dd82e983940..6143862b00b05 100644 --- a/.github/workflows/reusable-phpunit-tests-v3.yml +++ b/.github/workflows/reusable-phpunit-tests-v3.yml @@ -293,6 +293,20 @@ jobs: - name: Install WordPress run: npm run env:install + - name: Select PHPUnit configuration + run: | + PHPUNIT_VERSION=$(node ./tools/local-env/scripts/docker.js run php ./vendor/bin/phpunit --version | grep -oE '\b[0-9]+\.[0-9]+' | head -n 1) + echo "Detected PHPUnit version: ${PHPUNIT_VERSION}" + MAJOR_VERSION=$(echo "${PHPUNIT_VERSION}" | cut -d. -f1) + if [ "${MAJOR_VERSION}" -ge 10 ]; then + if [ "${PHPUNIT_CONFIG}" = "tests/phpunit/multisite.xml" ]; then + NEW_CONFIG="tests/phpunit/multisite10.xml" + else + NEW_CONFIG="phpunit10.xml.dist" + fi + echo "Using PHPUnit 10+ configuration: ${NEW_CONFIG}" + echo "PHPUNIT_CONFIG=${NEW_CONFIG}" >> "$GITHUB_ENV" + fi - name: Run external HTTP tests if: ${{ ! inputs.multisite && ! inputs.phpunit-test-groups && ! inputs.coverage-report }} continue-on-error: ${{ inputs.allow-errors }} diff --git a/.github/workflows/test-build-processes.yml b/.github/workflows/test-build-processes.yml index a870685856fdb..5c10cefbfe372 100644 --- a/.github/workflows/test-build-processes.yml +++ b/.github/workflows/test-build-processes.yml @@ -34,6 +34,7 @@ on: - '!phpcs.xml.dist' - '!phpstan.neon.dist' - '!phpunit.xml.dist' + - '!phpunit10.xml.dist' - '!tsconfig.json' # Tests, unrelated tools, and other workflows do not affect the build. - '!tests/**' diff --git a/.github/workflows/test-coverage.yml b/.github/workflows/test-coverage.yml index b2692c10c0d0b..ee0cb360eca7b 100644 --- a/.github/workflows/test-coverage.yml +++ b/.github/workflows/test-coverage.yml @@ -15,7 +15,9 @@ on: - '.nvmrc' - 'docker-compose.yml' - 'phpunit.xml.dist' + - 'phpunit10.xml.dist' - 'tests/phpunit/multisite.xml' + - 'tests/phpunit/multisite10.xml' pull_request: branches: - trunk @@ -29,7 +31,9 @@ on: - '.nvmrc' - 'docker-compose.yml' - 'phpunit.xml.dist' + - 'phpunit10.xml.dist' - 'tests/phpunit/multisite.xml' + - 'tests/phpunit/multisite10.xml' # Once daily at 00:00 UTC. schedule: - cron: '0 0 * * *' diff --git a/.gitignore b/.gitignore index 94798d0a72702..01c9060ac602d 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,8 @@ wp-tests-config.php # Files and folders related to build/test tools .phpunit.result.cache /phpunit.xml +/phpunit10.xml +/phpunit-10.xml /.phpcs.xml /phpcs.xml .cache/* diff --git a/composer.json b/composer.json index e20f4c7806b6e..1d08656534843 100644 --- a/composer.json +++ b/composer.json @@ -81,6 +81,7 @@ "format": "@php ./vendor/squizlabs/php_codesniffer/bin/phpcbf --report=summary,source", "lint": "@php ./vendor/squizlabs/php_codesniffer/bin/phpcs --report=summary,source", "lint:errors": "@lint -n", - "test": [ "Composer\\Config::disableProcessTimeout", "@php ./vendor/phpunit/phpunit/phpunit" ] + "test": [ "Composer\\Config::disableProcessTimeout", "@php ./vendor/phpunit/phpunit/phpunit" ], + "test10": [ "Composer\\Config::disableProcessTimeout", "@php ./vendor/phpunit/phpunit/phpunit -c phpunit10.xml.dist" ] } } diff --git a/package.json b/package.json index d8e955f0d9809..215a8d3fd3a44 100644 --- a/package.json +++ b/package.json @@ -149,6 +149,7 @@ "env:pull": "node ./tools/local-env/scripts/docker.js pull", "test:performance": "wp-scripts test-playwright --config tests/performance/playwright.config.js", "test:php": "node ./tools/local-env/scripts/docker.js run --rm php ./vendor/bin/phpunit", + "test:php10": "node ./tools/local-env/scripts/docker.js run --rm php ./vendor/bin/phpunit -c phpunit10.xml.dist", "test:coverage": "npm run test:php -- --coverage-html ./coverage/html/ --coverage-php ./coverage/php/report.php --coverage-text=./coverage/text/report.txt", "test:e2e": "wp-scripts test-playwright --config tests/e2e/playwright.config.js", "test:visual": "wp-scripts test-playwright --config tests/visual-regression/playwright.config.js", diff --git a/phpunit10.xml.dist b/phpunit10.xml.dist new file mode 100644 index 0000000000000..937dc46e567e7 --- /dev/null +++ b/phpunit10.xml.dist @@ -0,0 +1,85 @@ + + + + + + tests/phpunit/tests + tests/phpunit/tests/rest-api/rest-autosaves-controller.php + + + + tests/phpunit/tests/rest-api/rest-autosaves-controller.php + + + + + ajax + ms-files + ms-required + external-http + html-api-web-platform-tests + + + + + src + + + + src/wp-includes/ID3 + src/wp-includes/IXR + src/wp-includes/PHPMailer + src/wp-includes/Requests + src/wp-includes/php-ai-client + src/wp-includes/SimplePie + src/wp-includes/sodium_compat + src/wp-includes/Text + + + src/wp-content + + src/wp-admin/includes/class-ftp.php + src/wp-admin/includes/class-ftp-pure.php + src/wp-admin/includes/class-ftp-sockets.php + src/wp-admin/includes/class-pclzip.php + src/wp-admin/includes/deprecated.php + src/wp-admin/includes/ms-deprecated.php + + src/wp-includes/atomlib.php + src/wp-includes/class-IXR.php + src/wp-includes/class-json.php + src/wp-includes/class-phpass.php + src/wp-includes/class-pop3.php + src/wp-includes/class-requests.php + src/wp-includes/class-simplepie.php + src/wp-includes/class-snoopy.php + src/wp-includes/deprecated.php + src/wp-includes/ms-deprecated.php + src/wp-includes/pluggable-deprecated.php + src/wp-includes/rss.php + + + + + + + + + diff --git a/tests/phpunit/README.md b/tests/phpunit/README.md index 679ed831112d2..9500fe60f551e 100644 --- a/tests/phpunit/README.md +++ b/tests/phpunit/README.md @@ -6,6 +6,23 @@ For more information, please review the relevant Core Handbook pages: - [PHP: PHPUnit](https://make.wordpress.org/core/handbook/testing/automated-testing/phpunit/) - [Writing PHP Tests](https://make.wordpress.org/core/handbook/testing/automated-testing/writing-phpunit-tests/) +## Configuration Files + +WordPress core maintains separate configuration files to support both PHPUnit 9 and PHPUnit 10.1+: + +- `phpunit.xml.dist` and `tests/phpunit/multisite.xml`: Used for PHPUnit 9 and earlier. +- `phpunit10.xml.dist` and `tests/phpunit/multisite10.xml`: Used for PHPUnit 10.1 and later. + +### Running Tests Locally + +When running tests via Composer: +- `composer test`: Runs tests using the default configuration (PHPUnit < 10). +- `composer test10`: Runs tests using `phpunit10.xml.dist` (PHPUnit 10+). + +When running tests via npm and Docker: +- `npm run test:php`: Runs tests using the default configuration. +- `npm run test:php10`: Runs tests using `phpunit10.xml.dist`. + ## Run the full matrix on a pull request Add the `Full PHPUnit Matrix` label to a pull request in `WordPress/wordpress-develop` to run the same PHP and database combinations as the weekly scheduled run. The label-triggered workflow uses the same path filters as normal PHPUnit runs. diff --git a/tests/phpunit/multisite10.xml b/tests/phpunit/multisite10.xml new file mode 100644 index 0000000000000..57d6d1b007069 --- /dev/null +++ b/tests/phpunit/multisite10.xml @@ -0,0 +1,84 @@ + + + + + + + + + + tests + tests/rest-api/rest-autosaves-controller.php + + + + tests/rest-api/rest-autosaves-controller.php + + + + + ajax + ms-files + ms-excluded + external-http + oembed-headers + html-api-web-platform-tests + + + + + ../../src + + + + ../../src/wp-includes/ID3 + ../../src/wp-includes/IXR + ../../src/wp-includes/PHPMailer + ../../src/wp-includes/Requests + ../../src/wp-includes/php-ai-client + ../../src/wp-includes/SimplePie + ../../src/wp-includes/sodium_compat + ../../src/wp-includes/Text + + + ../../src/wp-content + + ../../src/wp-admin/includes/class-ftp.php + ../../src/wp-admin/includes/class-ftp-pure.php + ../../src/wp-admin/includes/class-ftp-sockets.php + ../../src/wp-admin/includes/class-pclzip.php + ../../src/wp-admin/includes/deprecated.php + ../../src/wp-admin/includes/ms-deprecated.php + + ../../src/wp-includes/atomlib.php + ../../src/wp-includes/class-IXR.php + ../../src/wp-includes/class-json.php + ../../src/wp-includes/class-phpass.php + ../../src/wp-includes/class-pop3.php + ../../src/wp-includes/class-requests.php + ../../src/wp-includes/class-simplepie.php + ../../src/wp-includes/class-snoopy.php + ../../src/wp-includes/deprecated.php + ../../src/wp-includes/ms-deprecated.php + ../../src/wp-includes/pluggable-deprecated.php + ../../src/wp-includes/rss.php + + + From b8dbe9d99ebd7273aa505ef7468843e3b4ee7297 Mon Sep 17 00:00:00 2001 From: robelsust Date: Sat, 10 Oct 2026 20:48:01 +0600 Subject: [PATCH 2/7] Tests: Address review feedback on PHPUnit 10 configuration and workflow integration - Remove --verbose and -v options from reusable-phpunit-tests-v3.yml since PHPUnit 10 rejects them. - Pass -c "${PHPUNIT_CONFIG}" to the Xdebug test step in reusable-phpunit-tests-v3.yml. - Restore JUnit logging in tests/phpunit/multisite10.xml matching tests/phpunit/multisite.xml. See #66210, #62004. --- .github/workflows/reusable-phpunit-tests-v3.yml | 9 ++++----- tests/phpunit/multisite10.xml | 3 +++ 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/.github/workflows/reusable-phpunit-tests-v3.yml b/.github/workflows/reusable-phpunit-tests-v3.yml index 6143862b00b05..6cae9a7530568 100644 --- a/.github/workflows/reusable-phpunit-tests-v3.yml +++ b/.github/workflows/reusable-phpunit-tests-v3.yml @@ -310,7 +310,7 @@ jobs: - name: Run external HTTP tests if: ${{ ! inputs.multisite && ! inputs.phpunit-test-groups && ! inputs.coverage-report }} continue-on-error: ${{ inputs.allow-errors }} - run: node ./tools/local-env/scripts/docker.js run php ./vendor/bin/phpunit --verbose -c "${PHPUNIT_CONFIG}" --group external-http + run: node ./tools/local-env/scripts/docker.js run php ./vendor/bin/phpunit -c "${PHPUNIT_CONFIG}" --group external-http # PHPUnit versions used below PHP 7.3 do not support --fail-on-empty-test-suite. - name: Run PHPUnit tests${{ inputs.phpunit-test-groups && format( ' ({0} groups)', inputs.phpunit-test-groups ) || '' }}${{ inputs.coverage-report && ' with coverage report' || '' }} @@ -318,7 +318,6 @@ jobs: run: | node ./tools/local-env/scripts/docker.js ${{ inputs.coverage-report && 'exec' || 'run' }} \ php ./vendor/bin/phpunit \ - --verbose \ -c "${PHPUNIT_CONFIG}" \ ${{ inputs.phpunit-test-groups && '--group "${TEST_GROUPS}"' || '' }} \ ${{ inputs.phpunit-test-groups && inputs.php >= '7.3' && '--fail-on-empty-test-suite' || '' }} \ @@ -387,18 +386,18 @@ jobs: - name: Run AJAX tests if: ${{ ! inputs.phpunit-test-groups && ! inputs.coverage-report }} continue-on-error: ${{ inputs.allow-errors }} - run: node ./tools/local-env/scripts/docker.js run php ./vendor/bin/phpunit --verbose -c "${PHPUNIT_CONFIG}" --group ajax + run: node ./tools/local-env/scripts/docker.js run php ./vendor/bin/phpunit -c "${PHPUNIT_CONFIG}" --group ajax - name: Run ms-files tests as a multisite install if: ${{ inputs.multisite && ! inputs.phpunit-test-groups && ! inputs.coverage-report }} continue-on-error: ${{ inputs.allow-errors }} - run: node ./tools/local-env/scripts/docker.js run php ./vendor/bin/phpunit --verbose -c "${PHPUNIT_CONFIG}" --group ms-files + run: node ./tools/local-env/scripts/docker.js run php ./vendor/bin/phpunit -c "${PHPUNIT_CONFIG}" --group ms-files # __fakegroup__ is excluded to force PHPUnit to ignore the settings in phpunit.xml.dist. - name: Run (Xdebug) tests if: ${{ ! inputs.phpunit-test-groups && ! inputs.coverage-report }} continue-on-error: ${{ inputs.allow-errors }} - run: LOCAL_PHP_XDEBUG=true node ./tools/local-env/scripts/docker.js run php ./vendor/bin/phpunit -v --group xdebug --exclude-group __fakegroup__ + run: LOCAL_PHP_XDEBUG=true node ./tools/local-env/scripts/docker.js run php ./vendor/bin/phpunit -c "${PHPUNIT_CONFIG}" --group xdebug --exclude-group __fakegroup__ - name: Upload test coverage report to Codecov if: ${{ inputs.coverage-report }} diff --git a/tests/phpunit/multisite10.xml b/tests/phpunit/multisite10.xml index 57d6d1b007069..eed9c0540bcf9 100644 --- a/tests/phpunit/multisite10.xml +++ b/tests/phpunit/multisite10.xml @@ -81,4 +81,7 @@ ../../src/wp-includes/rss.php + + + From d926eb94241c4073500d14d9689def5b4ec36980 Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Tue, 10 Nov 2026 22:03:12 +0000 Subject: [PATCH 3/7] Build/Test Tools: Read the installed PHPUnit version from Composer instead of running it in Docker. Composer installs dependencies on the runner with the same PHP version as the container, so the version can be read with `Composer\InstalledVersions` straight after install. This removes a container start from every job. --- .../workflows/reusable-phpunit-tests-v3.yml | 29 ++++++++++--------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/.github/workflows/reusable-phpunit-tests-v3.yml b/.github/workflows/reusable-phpunit-tests-v3.yml index 6cae9a7530568..33191a290f6c6 100644 --- a/.github/workflows/reusable-phpunit-tests-v3.yml +++ b/.github/workflows/reusable-phpunit-tests-v3.yml @@ -247,6 +247,21 @@ jobs: with: custom-cache-suffix: $(/bin/date -u --date='last Mon' "+%F") + # The runner's PHP version matches the container's, so the PHPUnit version installed here is the one the tests use. + - name: Select PHPUnit configuration + run: | + PHPUNIT_VERSION=$(php -r 'require "vendor/autoload.php"; echo Composer\InstalledVersions::getVersion("phpunit/phpunit");') + echo "Detected PHPUnit version: ${PHPUNIT_VERSION}" + if [ "$(echo "${PHPUNIT_VERSION}" | cut -d. -f1)" -ge 10 ]; then + if [ "${PHPUNIT_CONFIG}" = "tests/phpunit/multisite.xml" ]; then + NEW_CONFIG="tests/phpunit/multisite10.xml" + else + NEW_CONFIG="phpunit10.xml.dist" + fi + echo "Using PHPUnit 10+ configuration: ${NEW_CONFIG}" + echo "PHPUNIT_CONFIG=${NEW_CONFIG}" >> "$GITHUB_ENV" + fi + - name: Install npm dependencies run: npm ci @@ -293,20 +308,6 @@ jobs: - name: Install WordPress run: npm run env:install - - name: Select PHPUnit configuration - run: | - PHPUNIT_VERSION=$(node ./tools/local-env/scripts/docker.js run php ./vendor/bin/phpunit --version | grep -oE '\b[0-9]+\.[0-9]+' | head -n 1) - echo "Detected PHPUnit version: ${PHPUNIT_VERSION}" - MAJOR_VERSION=$(echo "${PHPUNIT_VERSION}" | cut -d. -f1) - if [ "${MAJOR_VERSION}" -ge 10 ]; then - if [ "${PHPUNIT_CONFIG}" = "tests/phpunit/multisite.xml" ]; then - NEW_CONFIG="tests/phpunit/multisite10.xml" - else - NEW_CONFIG="phpunit10.xml.dist" - fi - echo "Using PHPUnit 10+ configuration: ${NEW_CONFIG}" - echo "PHPUNIT_CONFIG=${NEW_CONFIG}" >> "$GITHUB_ENV" - fi - name: Run external HTTP tests if: ${{ ! inputs.multisite && ! inputs.phpunit-test-groups && ! inputs.coverage-report }} continue-on-error: ${{ inputs.allow-errors }} From b294ed19ec8f309583ad39a1f86d4a3b1a44c888 Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Tue, 10 Nov 2026 22:05:17 +0000 Subject: [PATCH 4/7] Docs: Clarify which PHPUnit versions each test configuration file supports. --- tests/phpunit/README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/phpunit/README.md b/tests/phpunit/README.md index 9500fe60f551e..02bb817276682 100644 --- a/tests/phpunit/README.md +++ b/tests/phpunit/README.md @@ -8,16 +8,16 @@ For more information, please review the relevant Core Handbook pages: ## Configuration Files -WordPress core maintains separate configuration files to support both PHPUnit 9 and PHPUnit 10.1+: +WordPress core has separate configuration files for PHPUnit 9 and PHPUnit 10: - `phpunit.xml.dist` and `tests/phpunit/multisite.xml`: Used for PHPUnit 9 and earlier. -- `phpunit10.xml.dist` and `tests/phpunit/multisite10.xml`: Used for PHPUnit 10.1 and later. +- `phpunit10.xml.dist` and `tests/phpunit/multisite10.xml`: Used for PHPUnit 10 and later. These use the `` element, so PHPUnit 10.0 is not supported. ### Running Tests Locally When running tests via Composer: -- `composer test`: Runs tests using the default configuration (PHPUnit < 10). -- `composer test10`: Runs tests using `phpunit10.xml.dist` (PHPUnit 10+). +- `composer test`: Runs tests using the default configuration (PHPUnit 9 and earlier). +- `composer test10`: Runs tests using `phpunit10.xml.dist` (PHPUnit 10 and later). When running tests via npm and Docker: - `npm run test:php`: Runs tests using the default configuration. From f0287290a648e0b490a5af69b236f6592cde15c8 Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Tue, 10 Nov 2026 22:07:04 +0000 Subject: [PATCH 5/7] Build/Test Tools: Remove an unused PHPUnit configuration entry from .gitignore. --- .gitignore | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitignore b/.gitignore index 01c9060ac602d..74312255d037c 100644 --- a/.gitignore +++ b/.gitignore @@ -10,7 +10,6 @@ wp-tests-config.php .phpunit.result.cache /phpunit.xml /phpunit10.xml -/phpunit-10.xml /.phpcs.xml /phpcs.xml .cache/* From 543638d60a2b90b7bdd9bc3bbad8822e6f96ec11 Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Tue, 10 Nov 2026 22:24:41 +0000 Subject: [PATCH 6/7] Build/Test Tools: Pick the PHPUnit configuration file from the installed PHPUnit version. Adds tests/phpunit/phpunit-config.php, which prints the configuration file for the installed version. composer test, npm run test:php and CI use it, which removes the test10 and test:php10 scripts. --- .../workflows/reusable-phpunit-tests-v3.yml | 16 ++---- composer.json | 3 +- package.json | 3 +- tests/phpunit/README.md | 12 ++--- tests/phpunit/phpunit-config.php | 51 +++++++++++++++++++ 5 files changed, 62 insertions(+), 23 deletions(-) create mode 100644 tests/phpunit/phpunit-config.php diff --git a/.github/workflows/reusable-phpunit-tests-v3.yml b/.github/workflows/reusable-phpunit-tests-v3.yml index 33191a290f6c6..882ba5a715c86 100644 --- a/.github/workflows/reusable-phpunit-tests-v3.yml +++ b/.github/workflows/reusable-phpunit-tests-v3.yml @@ -247,20 +247,10 @@ jobs: with: custom-cache-suffix: $(/bin/date -u --date='last Mon' "+%F") - # The runner's PHP version matches the container's, so the PHPUnit version installed here is the one the tests use. + # Release branches run this workflow from trunk, but older branches lack this file. - name: Select PHPUnit configuration - run: | - PHPUNIT_VERSION=$(php -r 'require "vendor/autoload.php"; echo Composer\InstalledVersions::getVersion("phpunit/phpunit");') - echo "Detected PHPUnit version: ${PHPUNIT_VERSION}" - if [ "$(echo "${PHPUNIT_VERSION}" | cut -d. -f1)" -ge 10 ]; then - if [ "${PHPUNIT_CONFIG}" = "tests/phpunit/multisite.xml" ]; then - NEW_CONFIG="tests/phpunit/multisite10.xml" - else - NEW_CONFIG="phpunit10.xml.dist" - fi - echo "Using PHPUnit 10+ configuration: ${NEW_CONFIG}" - echo "PHPUNIT_CONFIG=${NEW_CONFIG}" >> "$GITHUB_ENV" - fi + if: ${{ hashFiles('tests/phpunit/phpunit-config.php') != '' }} + run: echo "PHPUNIT_CONFIG=$(php ./tests/phpunit/phpunit-config.php "${PHPUNIT_CONFIG}")" >> "$GITHUB_ENV" - name: Install npm dependencies run: npm ci diff --git a/composer.json b/composer.json index 1d08656534843..dcb058d3f5c21 100644 --- a/composer.json +++ b/composer.json @@ -81,7 +81,6 @@ "format": "@php ./vendor/squizlabs/php_codesniffer/bin/phpcbf --report=summary,source", "lint": "@php ./vendor/squizlabs/php_codesniffer/bin/phpcs --report=summary,source", "lint:errors": "@lint -n", - "test": [ "Composer\\Config::disableProcessTimeout", "@php ./vendor/phpunit/phpunit/phpunit" ], - "test10": [ "Composer\\Config::disableProcessTimeout", "@php ./vendor/phpunit/phpunit/phpunit -c phpunit10.xml.dist" ] + "test": [ "Composer\\Config::disableProcessTimeout", "@php ./vendor/phpunit/phpunit/phpunit -c \"$(php ./tests/phpunit/phpunit-config.php)\"" ] } } diff --git a/package.json b/package.json index 215a8d3fd3a44..bf0d8340c435d 100644 --- a/package.json +++ b/package.json @@ -148,8 +148,7 @@ "env:logs": "node ./tools/local-env/scripts/docker.js logs", "env:pull": "node ./tools/local-env/scripts/docker.js pull", "test:performance": "wp-scripts test-playwright --config tests/performance/playwright.config.js", - "test:php": "node ./tools/local-env/scripts/docker.js run --rm php ./vendor/bin/phpunit", - "test:php10": "node ./tools/local-env/scripts/docker.js run --rm php ./vendor/bin/phpunit -c phpunit10.xml.dist", + "test:php": "node ./tools/local-env/scripts/docker.js run --rm php composer test --", "test:coverage": "npm run test:php -- --coverage-html ./coverage/html/ --coverage-php ./coverage/php/report.php --coverage-text=./coverage/text/report.txt", "test:e2e": "wp-scripts test-playwright --config tests/e2e/playwright.config.js", "test:visual": "wp-scripts test-playwright --config tests/visual-regression/playwright.config.js", diff --git a/tests/phpunit/README.md b/tests/phpunit/README.md index 02bb817276682..01252d418f15a 100644 --- a/tests/phpunit/README.md +++ b/tests/phpunit/README.md @@ -15,13 +15,13 @@ WordPress core has separate configuration files for PHPUnit 9 and PHPUnit 10: ### Running Tests Locally -When running tests via Composer: -- `composer test`: Runs tests using the default configuration (PHPUnit 9 and earlier). -- `composer test10`: Runs tests using `phpunit10.xml.dist` (PHPUnit 10 and later). +`composer test` and `npm run test:php` use the single site configuration file that matches the installed version of PHPUnit. A local `phpunit.xml` file is used instead if one exists, so base it on the file that matches your version of PHPUnit. -When running tests via npm and Docker: -- `npm run test:php`: Runs tests using the default configuration. -- `npm run test:php10`: Runs tests using `phpunit10.xml.dist`. +`tests/phpunit/phpunit-config.php` prints the matching configuration file. Pass it either configuration file name to get the one for the installed version, for example to run the multisite tests: + +``` +./vendor/bin/phpunit -c "$(php tests/phpunit/phpunit-config.php tests/phpunit/multisite.xml)" +``` ## Run the full matrix on a pull request diff --git a/tests/phpunit/phpunit-config.php b/tests/phpunit/phpunit-config.php new file mode 100644 index 0000000000000..3b2a16ee970a8 --- /dev/null +++ b/tests/phpunit/phpunit-config.php @@ -0,0 +1,51 @@ +=' ); + +$swaps = array( + 'phpunit.xml.dist' => 'phpunit10.xml.dist', + 'tests/phpunit/multisite.xml' => 'tests/phpunit/multisite10.xml', +); + +if ( ! $is_phpunit_10 ) { + $swaps = array_flip( $swaps ); +} + +if ( ! isset( $argv[1] ) ) { + if ( file_exists( $root . '/phpunit.xml' ) ) { + echo 'phpunit.xml'; + } else { + echo $is_phpunit_10 ? 'phpunit10.xml.dist' : 'phpunit.xml.dist'; + } + exit; +} + +$config = $argv[1]; +$real = realpath( $config ); + +foreach ( $swaps as $from => $to ) { + if ( false !== $real && realpath( $root . '/' . $from ) === $real ) { + $config = $to; + break; + } +} + +echo $config; From 8d1845b867b0dde16b216da5f0ba489401caeb2b Mon Sep 17 00:00:00 2001 From: robelsust Date: Sun, 29 Nov 2026 22:03:01 +0600 Subject: [PATCH 7/7] Build/Test Tools: Run PHPUnit via a cross-platform PHP entry point for composer test. Replaces POSIX shell command substitution (`$(php ...)`) in `composer.json` with `@php ./tests/phpunit/run.php` so `composer test` works natively on Windows (`cmd.exe` and PowerShell) as well as macOS, Linux, and Docker. `tests/phpunit/run.php` uses `PHP_BINARY` via `proc_open()` (array command form, bypassing the shell), invokes `tests/phpunit/phpunit-config.php` when no explicit `-c`, `--configuration`, or `--no-configuration` option is provided, passes all PHPUnit arguments through, and returns PHPUnit's exact exit status. Trac ticket: https://core.trac.wordpress.org/ticket/66210 --- composer.json | 2 +- tests/phpunit/run.php | 101 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 102 insertions(+), 1 deletion(-) create mode 100644 tests/phpunit/run.php diff --git a/composer.json b/composer.json index 33e60ad9052d4..4e924d247fe14 100644 --- a/composer.json +++ b/composer.json @@ -88,6 +88,6 @@ "format": "@php ./vendor/squizlabs/php_codesniffer/bin/phpcbf --report=summary,source", "lint": "@php ./vendor/squizlabs/php_codesniffer/bin/phpcs --report=summary,source", "lint:errors": "@lint -n", - "test": [ "Composer\\Config::disableProcessTimeout", "@php ./vendor/phpunit/phpunit/phpunit -c \"$(php ./tests/phpunit/phpunit-config.php)\"" ] + "test": [ "Composer\\Config::disableProcessTimeout", "@php ./tests/phpunit/run.php" ] } } diff --git a/tests/phpunit/run.php b/tests/phpunit/run.php new file mode 100644 index 0000000000000..f2daf48506df1 --- /dev/null +++ b/tests/phpunit/run.php @@ -0,0 +1,101 @@ + array( 'pipe', 'w' ), + 2 => STDERR, + ), + $config_pipes + ); + + if ( ! is_resource( $config_process ) ) { + fwrite( STDERR, "Failed to determine the PHPUnit configuration file.\n" ); + exit( 1 ); + } + + $config = trim( (string) stream_get_contents( $config_pipes[1] ) ); + fclose( $config_pipes[1] ); + $config_exit = proc_close( $config_process ); + + if ( 0 !== $config_exit || '' === $config ) { + exit( 0 !== $config_exit ? $config_exit : 1 ); + } + + array_unshift( $phpunit_args, '-c', $config ); +} + +$process = proc_open( + array( PHP_BINARY, $phpunit, ...$phpunit_args ), + array( + 0 => STDIN, + 1 => STDOUT, + 2 => STDERR, + ), + $pipes +); + +if ( ! is_resource( $process ) ) { + fwrite( STDERR, "Failed to start PHPUnit.\n" ); + exit( 1 ); +} + +exit( proc_close( $process ) );