Make WordPress Core

Opened 7 weeks ago

Last modified 6 days ago

#66210 new task (blessed)

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

Reported by: lancewillett Owned by:
Priority: normal Milestone: Future Release
Component: Build/Test Tools Version:
Severity: normal Keywords: has-patch has-unit-tests
Cc: Focuses: tests

Description

Split from #62004 (problem 1 there).

PHPUnit 10.0 and 10.1 changed the XML configuration file, and --migrate-configuration doesn't carry over the top-level <phpunit> settings. Trunk still has to run on PHPUnit 9 for PHP 7.4, so it needs two files: the current phpunit.xml.dist for PHPUnit 9 and earlier, and a new one for PHPUnit 10.1 and later.

Scope:

  • add the second configuration file
  • pick the right file in CI based on the installed PHPUnit version
  • document which file to use: Composer scripts and the handbook

A draft of this sits on the Build/Test Tools project board.

Change History (8)

#1 @lancewillett
7 weeks ago

Scope notes from trunk:

  • There are two configuration files, not one: phpunit.xml.dist and tests/phpunit/multisite.xml. .github/workflows/phpunit-tests.yml picks between them, so each needs a PHPUnit 10.1+ counterpart.
  • The external-http step hard-codes -c phpunit.xml.dist in reusable-phpunit-tests-v1.yml and reusable-phpunit-tests-v2.yml.
  • phpunit.xml.dist sets convertErrorsToExceptions, convertWarningsToExceptions, convertNoticesToExceptions and convertDeprecationsToExceptions. PHPUnit 10.0 removed all four, along with the behavior they controlled, so the new file needs another way to keep failing on PHP deprecations. See #54183.

This ticket was mentioned in ​PR #14145 on ​WordPress/wordpress-develop by ​@therssoftware.


5 weeks ago
#2

  • Keywords has-patch has-unit-tests added; needs-patch removed

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 #62004 as scoped in #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" />.
  1. 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/.
  1. 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.
  1. 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.

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.

#3 @therssoftware
5 weeks ago

I have created a pull request addressing all items in the scope:
PR: ​https://github.com/WordPress/wordpress-develop/pull/14145

Summary of work done:

  1. Created phpunit10.xml.dist and tests/phpunit/multisite10.xml complying strictly with PHPUnit 10.1+ XML Schema (validated against official 10.1, 10.5, and 11.0 XSDs with xmllint).
  2. Configured failOnDeprecation="true", failOnNotice="true", failOnWarning="true", failOnRisky="true" and display details attributes to maintain strict error and deprecation handling as discussed in #54183 and #62004.
  3. Updated CI workflows:
    • Added automatic detection in reusable-phpunit-tests-v3.yml to switch PHPUNIT_CONFIG to the PHPUnit 10+ counterpart when running on PHPUnit 10+.
    • Replaced hard-coded -c phpunit.xml.dist with -c "${PHPUNIT_CONFIG}" for the external-http step in reusable-phpunit-tests-v1.yml and reusable-phpunit-tests-v2.yml.
    • Updated path triggers in phpunit-tests.yml, phpunit-tests-full-matrix.yml, and test-coverage.yml.
  4. Added composer test10 and npm run test:php10 scripts, added /phpunit10.xml to .gitignore, and documented configuration usage in tests/phpunit/README.md.

​@therssoftware commented on ​PR #14145:


5 weeks ago
#4

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

I have addressed all three items in commit ​https://github.com/WordPress/wordpress-develop/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 commented on ​PR #14145:


2 weeks ago
#5

@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.

<sub>AI review · <code>gpt-6</code></sub>

​@lancewillett commented on ​PR #14145:


9 days ago
#6

@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.

<sub>AI review · <code>claude-opus-5-5</code></sub>

​@therssoftware commented on ​PR #14145:


9 days ago
#7

@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!

​@johnbillion commented on ​PR #14145:


6 days ago
#8

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.

Note: See TracTickets for help on using tickets.