Skip to content

Tests: Add a separate PHPUnit configuration file for PHPUnit 10.1 and later - #14145

Open
robelsust wants to merge 9 commits into
WordPress:trunkfrom
robelsust:feature/66210-phpunit-10-config
Open

robelsust wants to merge 9 commits into
WordPress:trunkfrom
robelsust:feature/66210-phpunit-10-config

Conversation

@robelsust

@robelsust robelsust commented Oct 10, 2026 •

Copy link
Copy Markdown

Introduces separate PHPUnit 10.1+ configuration files (phpunit10.xml.dist and tests/phpunit/multisite10.xml) alongside the existing PHPUnit 9 configuration files (phpunit.xml.dist and tests/phpunit/multisite.xml), fulfilling Problem 1 of Trac #62004 as scoped in Trac #66210.

Background & Context

  • In PHPUnit 10.0 and 10.1, the XML configuration schema changed significantly. Attributes on the root <phpunit> element (convertErrorsToExceptions, convertWarningsToExceptions, convertNoticesToExceptions, convertDeprecationsToExceptions) were removed.
  • PHP native deprecations, notices, and warnings are now configured via failOnDeprecation="true", failOnNotice="true", failOnWarning="true", failOnRisky="true", and the corresponding displayDetailsOnTestsThatTrigger*="true" attributes.
  • The <filter><whitelist> element was replaced by <source><include> and <source><exclude>.
  • The <logging><log type="junit" target="..."/></logging> element was replaced by <logging><junit outputFile="..."/></logging>.
  • Because WordPress Core trunk must continue to support PHPUnit 9 for PHP 7.4 while supporting PHPUnit 10.1+ on newer PHP versions, separate configuration files are needed.

Changes

  1. Added phpunit10.xml.dist:

    • Conforms to PHPUnit 10.1+ XML Schema (https://schema.phpunit.de/10.1/phpunit.xsd).
    • Configures failOnDeprecation="true", failOnNotice="true", failOnWarning="true", failOnRisky="true", and details display.
    • Migrates code coverage path definitions into <source><include> and <source><exclude>.
    • Modernizes logging to <logging><junit outputFile="tests/phpunit/build/logs/junit.xml" />.
  2. Added tests/phpunit/multisite10.xml:

    • The PHPUnit 10.1+ multisite counterpart to tests/phpunit/multisite.xml.
    • Sets WP_TESTS_MULTISITE="1" and WP_RUN_CORE_TESTS="1".
    • Excludes the appropriate test groups (ajax, ms-files, ms-excluded, external-http, oembed-headers, html-api-web-platform-tests).
    • Configures <source> paths relative to tests/phpunit/.
  3. Workflow & CI Automation:

    • reusable-phpunit-tests-v3.yml: Added a Select PHPUnit configuration step before running tests that detects the installed PHPUnit version inside the container. If PHPUnit version >= 10, it automatically switches PHPUNIT_CONFIG to phpunit10.xml.dist (or tests/phpunit/multisite10.xml when testing multisite).
    • reusable-phpunit-tests-v1.yml & reusable-phpunit-tests-v2.yml: Fixed the external-http test step which previously hard-coded -c phpunit.xml.dist, now correctly using -c "${PHPUNIT_CONFIG}".
    • Path Triggers: Updated .github/workflows/phpunit-tests.yml, phpunit-tests-full-matrix.yml, and test-coverage.yml to trigger on phpunit10.xml.dist and multisite10.xml, while excluding !phpunit10.xml.dist from asset/e2e/performance workflows.
  4. Developer Tooling & Documentation:

    • composer.json: Added "test10": [ "Composer\\Config::disableProcessTimeout", "@php ./vendor/phpunit/phpunit/phpunit -c phpunit10.xml.dist" ].
    • package.json: Added "test:php10": "node ./tools/local-env/scripts/docker.js run --rm php ./vendor/bin/phpunit -c phpunit10.xml.dist".
    • .gitignore: Added /phpunit10.xml and /phpunit-10.xml to ignore local developer overrides.
    • tests/phpunit/README.md: Added a Configuration Files section documenting which configuration file to use for PHPUnit 9 vs PHPUnit 10+.

Verification

  • Both phpunit10.xml.dist and tests/phpunit/multisite10.xml were strictly validated against official PHPUnit 10.1, 10.5, and 11.0 XSD schemas via xmllint --noout --schema with 0 errors.
  • composer validate executed with 0 errors.
  • package.json syntax validated.
  • Existing PHPUnit test suite confirmed running without regressions under PHPUnit 9.

Trac ticket: https://core.trac.wordpress.org/ticket/66210

Use of AI Tools

AI assistance: Yes
Tool(s): Antigravity
Model(s): Gemini
Used for: Validating schema conformity against PHPUnit 10.1/10.5/11.0 XSD specifications, updating CI workflow configuration detection and reusable test runner workflows, and authoring developer documentation. All changes were reviewed, verified, and validated locally.


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

@github-actions

github-actions Bot commented Oct 10, 2026 •

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs.

Core Committers: Use this line as a base for the props when committing in SVN:

Props therssoftware, johnbillion, lancewillett.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub or WordPress.org user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

@robelsust
robelsust force-pushed the feature/66210-phpunit-10-config branch from ce49f65 to 778c4ee Compare October 10, 2026 06:08
@github-actions

Copy link
Copy Markdown

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

@lancewillett lancewillett left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The separate configurations fit the ticket’s scope. Please address three integration gaps before landing:

  1. In reusable-phpunit-tests-v3.yml, remove or version-gate --verbose and -v. PHPUnit 10 rejects these options; I reproduced Unknown option "--verbose" with PHPUnit 10.5.60 in Docker.
  2. Pass -c "${PHPUNIT_CONFIG}" to the xDebug test step too. It currently bypasses the new configuration selection.
  3. Restore JUnit logging in tests/phpunit/multisite10.xml, matching the existing multisite configuration:
    <logging>
        <junit outputFile="build/logs/junit.xml" />
    </logging>
    This preserves the output consumed by CI reporting and timing tools.

Both XML files passed PHPUnit 10.1 schema validation, and isolated PHPUnit 10 probes confirmed that their settings fail on deprecations, notices, and warnings. Actionlint passed. CI is green, but the inspected PHP 8.5 job uses PHPUnit 9.6, so it does not exercise the new configuration.

These are focused configuration/invocation fixes; completing the broader PHPUnit 10 migration can remain separate.

AI review · gpt-6

@robelsust

Copy link
Copy Markdown
Author

Thanks for the thorough review and catching these integration gaps @lancewillett!

I have addressed all three items in commit 479ae87f56:

  1. Removed --verbose and -v in reusable-phpunit-tests-v3.yml: Removed from all test invocation steps (external-http, main tests, ajax, ms-files, and xdebug) to resolve the PHPUnit 10 Unknown option "--verbose" error.
  2. Passed -c "${PHPUNIT_CONFIG}" to Xdebug tests: The Run (Xdebug) tests step now uses -c "${PHPUNIT_CONFIG}" so it respects the dynamic PHPUnit 10+ configuration selection.
  3. Restored JUnit logging in tests/phpunit/multisite10.xml: Added <logging><junit outputFile="build/logs/junit.xml" /></logging> matching tests/phpunit/multisite.xml. Both XML files re-validated cleanly against PHPUnit 10.1, 10.5, and 11.0 schemas.

@lancewillett
lancewillett self-requested a review October 10, 2026 15:34
@lancewillett

Copy link
Copy Markdown
Member

@johnbillion, could you give this an independent review before we land it? The author addressed the PHPUnit 10 invocation and configuration issues, and my code approval stands. I’m holding this larger integration change for a second review of the approach.

AI review · gpt-6

@lancewillett

Copy link
Copy Markdown
Member

@robelsust this now conflicts with trunk in .github/workflows/reusable-phpunit-tests-v3.yml, after r65292 switched local coverage to the PCOV extension in the Docker images. Could you rebase onto trunk? My earlier approval stands; I'll re-check the rebased head.

AI review · claude-opus-5-5

… 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.
…ow 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.
@robelsust
robelsust force-pushed the feature/66210-phpunit-10-config branch from 479ae87 to b8dbe9d Compare November 7, 2026 17:41
@robelsust

Copy link
Copy Markdown
Author

@lancewillett Rebased cleanly onto latest trunk and resolved the conflict in .github/workflows/reusable-phpunit-tests-v3.yml with the r65292 PCOV changes. Ready for your re-check!

@lancewillett lancewillett left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the rebase. Re-checked at ed34d10: the changes match what I approved at 479ae87. In reusable-phpunit-tests-v3.yml, the "Select PHPUnit configuration" step now follows "Install WordPress", since r65292 removed the PCOV check that used to come before it. CI is green.

One nit: the new step is missing the blank line before "Run external HTTP tests" that separates the other steps.

This still needs an independent review from @johnbillion before it lands.

AI review · claude-opus-5-5

…stead 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.
@johnbillion

Copy link
Copy Markdown
Member

This is looking good but I think we can be more clever about the config file loading so we don't need to introduce new commands with the 10 suffix in their name. I'm trying a few things.

…led 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.
@lancewillett

Copy link
Copy Markdown
Member

@johnbillion, did you find a way to select the config without adding the 10-suffixed commands? If you have a branch or patch, could you link it here so @robelsust can test that approach? If the current version is the one you’d keep, an independent review would let us move it forward.

AI review · gpt-6.2-astra

@johnbillion

Copy link
Copy Markdown
Member

Yep it's in robelsust#1

@lancewillett

Copy link
Copy Markdown
Member

@robelsust, @johnbillion opened robelsust/wordpress-develop#1 against this branch. It picks the PHPUnit config file from the installed PHPUnit version, so the 10-suffixed commands aren't needed. Could you review it and merge it into your branch, so it shows up here?

@robelsust

Copy link
Copy Markdown
Author

@lancewillett
Merged robelsust#1 into this branch so the updated tests/phpunit/phpunit-config.php approach is now live here and running through CI.

Thanks @johnbillion! One small portability note we discussed on robelsust#1: $(php ...) in composer.json works in Docker (npm run test:php), macOS, and Linux, but not in native Windows shells (cmd.exe / PowerShell) when running composer test locally. Happy to leave it as-is or switch to a cross-platform @php runner wrapper if you'd prefer to support native Windows Composer runs too.

@lancewillett

Copy link
Copy Markdown
Member

Thanks for bringing John’s selector over, @robelsust. Yes, please keep native Windows support for composer test. The existing command invokes PHPUnit through Composer’s @php; the new $(php ...) needs shell command substitution. A small PHP entry point can use the current PHP executable, pass PHPUnit’s arguments through, and return its exit status. Please keep an explicit -c override working as well.

GitHub also shows a conflict with trunk. Once refreshed, a native Windows run of composer test -- --version and a filtered test run would help @johnbillion review the change.

…nit-10-config

# Conflicts:
#	tests/phpunit/README.md
…r 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
@robelsust

Copy link
Copy Markdown
Author

Thanks @lancewillett! I've merged trunk (resolving the tests/phpunit/README.md conflict) and replaced the $(php ...) shell substitution in composer.json with a small cross-platform PHP entry point at tests/phpunit/run.php:

  • Invokes tests/phpunit/phpunit-config.php and PHPUnit using PHP_BINARY via proc_open() in array form (bypassing the shell on both Windows and POSIX).
  • Keeps PHP 7.4 compatibility (no str_starts_with()).
  • Preserves explicit -c, --configuration, and --no-configuration overrides (stopping option scanning at --), passes all other arguments through, and returns PHPUnit's exact exit status.

Tested locally on macOS (PHP 8.4 / PHPUnit 9.6.37):

  • composer test -- --version
  • Filtered single-site run (composer test -- tests/phpunit/tests/functions/wpRemovableQueryArgs.php --filter ...)
  • Explicit -c tests/phpunit/multisite.xml and --configuration=tests/phpunit/multisite.xml overrides (confirmed multisite mode)
  • Non-zero exit code propagation on invalid flags
  • vendor/bin/phpcs on tests/phpunit/run.php and tests/phpunit/phpunit-config.php

I don't have a native Windows machine handy to run the Windows smoke test directly — if anyone on Windows can verify composer test -- --version and a filtered run, that would be great.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In review

Development

Successfully merging this pull request may close these issues.

3 participants