Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/end-to-end-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/**'
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/performance.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/**'
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/phpunit-tests-full-matrix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/phpunit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/reusable-phpunit-tests-v1.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion .github/workflows/reusable-phpunit-tests-v2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 <exclude> settings in phpunit.xml.dist.
- name: Run (xDebug) tests
Expand Down
24 changes: 19 additions & 5 deletions .github/workflows/reusable-phpunit-tests-v3.yml
Original file line number Diff line number Diff line change
Expand Up @@ -317,18 +317,32 @@ jobs:
php -m | grep -i pcov
'

- 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 }}
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' || '' }}
continue-on-error: ${{ inputs.allow-errors }}
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' || '' }} \
Expand Down Expand Up @@ -397,18 +411,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 <exclude> 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 }}
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/test-build-processes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/**'
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/test-coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 * * *'
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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/*
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,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" ]
}
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,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",
Expand Down
85 changes: 85 additions & 0 deletions phpunit10.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.1/phpunit.xsd"
bootstrap="tests/phpunit/includes/bootstrap.php"
backupGlobals="false"
colors="true"
beStrictAboutTestsThatDoNotTestAnything="true"
beStrictAboutOutputDuringTests="true"
failOnRisky="true"
failOnWarning="true"
failOnNotice="true"
failOnDeprecation="true"
displayDetailsOnTestsThatTriggerErrors="true"
displayDetailsOnTestsThatTriggerWarnings="true"
displayDetailsOnTestsThatTriggerNotices="true"
displayDetailsOnTestsThatTriggerDeprecations="true"
cacheDirectory="tests/phpunit/build/.phpunit.cache"
>
<testsuites>
<!-- Default test suite to run all tests. -->
<testsuite name="default">
<directory suffix=".php">tests/phpunit/tests</directory>
<exclude>tests/phpunit/tests/rest-api/rest-autosaves-controller.php</exclude>
</testsuite>
<!-- Sets the DOING_AUTOSAVE constant, so needs to be run last. -->
<testsuite name="restapi-autosave">
<file>tests/phpunit/tests/rest-api/rest-autosaves-controller.php</file>
</testsuite>
</testsuites>
<groups>
<exclude>
<group>ajax</group>
<group>ms-files</group>
<group>ms-required</group>
<group>external-http</group>
<group>html-api-web-platform-tests</group>
</exclude>
</groups>
<source>
<include>
<directory suffix=".php">src</directory>
</include>
<exclude>
<!-- Third party library exclusions. -->
<directory suffix=".php">src/wp-includes/ID3</directory>
<directory suffix=".php">src/wp-includes/IXR</directory>
<directory suffix=".php">src/wp-includes/PHPMailer</directory>
<directory suffix=".php">src/wp-includes/Requests</directory>
<directory suffix=".php">src/wp-includes/php-ai-client</directory>
<directory suffix=".php">src/wp-includes/SimplePie</directory>
<directory suffix=".php">src/wp-includes/sodium_compat</directory>
<directory suffix=".php">src/wp-includes/Text</directory>

<!-- Plugins and themes. -->
<directory suffix=".php">src/wp-content</directory>

<file>src/wp-admin/includes/class-ftp.php</file>
<file>src/wp-admin/includes/class-ftp-pure.php</file>
<file>src/wp-admin/includes/class-ftp-sockets.php</file>
<file>src/wp-admin/includes/class-pclzip.php</file>
<file>src/wp-admin/includes/deprecated.php</file>
<file>src/wp-admin/includes/ms-deprecated.php</file>

<file>src/wp-includes/atomlib.php</file>
<file>src/wp-includes/class-IXR.php</file>
<file>src/wp-includes/class-json.php</file>
<file>src/wp-includes/class-phpass.php</file>
<file>src/wp-includes/class-pop3.php</file>
<file>src/wp-includes/class-requests.php</file>
<file>src/wp-includes/class-simplepie.php</file>
<file>src/wp-includes/class-snoopy.php</file>
<file>src/wp-includes/deprecated.php</file>
<file>src/wp-includes/ms-deprecated.php</file>
<file>src/wp-includes/pluggable-deprecated.php</file>
<file>src/wp-includes/rss.php</file>
</exclude>
</source>
<logging>
<junit outputFile="tests/phpunit/build/logs/junit.xml" />
</logging>
<php>
<const name="WP_RUN_CORE_TESTS" value="1" />
</php>
</phpunit>
17 changes: 17 additions & 0 deletions tests/phpunit/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 &lt; 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.
Expand Down
87 changes: 87 additions & 0 deletions tests/phpunit/multisite10.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.1/phpunit.xsd"
bootstrap="includes/bootstrap.php"
backupGlobals="false"
colors="true"
beStrictAboutTestsThatDoNotTestAnything="true"
beStrictAboutOutputDuringTests="true"
failOnRisky="true"
failOnWarning="true"
failOnNotice="true"
failOnDeprecation="true"
displayDetailsOnTestsThatTriggerErrors="true"
displayDetailsOnTestsThatTriggerWarnings="true"
displayDetailsOnTestsThatTriggerNotices="true"
displayDetailsOnTestsThatTriggerDeprecations="true"
cacheDirectory="build/.phpunit.cache"
>
<php>
<const name="WP_TESTS_MULTISITE" value="1" />
<const name="WP_RUN_CORE_TESTS" value="1" />
</php>
<testsuites>
<!-- Default test suite to run all tests. -->
<testsuite name="default">
<directory suffix=".php">tests</directory>
<exclude>tests/rest-api/rest-autosaves-controller.php</exclude>
</testsuite>
<!-- Sets the DOING_AUTOSAVE constant, so needs to be run last. -->
<testsuite name="restapi-autosave">
<file>tests/rest-api/rest-autosaves-controller.php</file>
</testsuite>
</testsuites>
<groups>
<exclude>
<group>ajax</group>
<group>ms-files</group>
<group>ms-excluded</group>
<group>external-http</group>
<group>oembed-headers</group>
<group>html-api-web-platform-tests</group>
</exclude>
</groups>
<source>
<include>
<directory suffix=".php">../../src</directory>
</include>
<exclude>
<!-- Third party library exclusions. -->
<directory suffix=".php">../../src/wp-includes/ID3</directory>
<directory suffix=".php">../../src/wp-includes/IXR</directory>
<directory suffix=".php">../../src/wp-includes/PHPMailer</directory>
<directory suffix=".php">../../src/wp-includes/Requests</directory>
<directory suffix=".php">../../src/wp-includes/php-ai-client</directory>
<directory suffix=".php">../../src/wp-includes/SimplePie</directory>
<directory suffix=".php">../../src/wp-includes/sodium_compat</directory>
<directory suffix=".php">../../src/wp-includes/Text</directory>

<!-- Plugins and themes. -->
<directory suffix=".php">../../src/wp-content</directory>

<file>../../src/wp-admin/includes/class-ftp.php</file>
<file>../../src/wp-admin/includes/class-ftp-pure.php</file>
<file>../../src/wp-admin/includes/class-ftp-sockets.php</file>
<file>../../src/wp-admin/includes/class-pclzip.php</file>
<file>../../src/wp-admin/includes/deprecated.php</file>
<file>../../src/wp-admin/includes/ms-deprecated.php</file>

<file>../../src/wp-includes/atomlib.php</file>
<file>../../src/wp-includes/class-IXR.php</file>
<file>../../src/wp-includes/class-json.php</file>
<file>../../src/wp-includes/class-phpass.php</file>
<file>../../src/wp-includes/class-pop3.php</file>
<file>../../src/wp-includes/class-requests.php</file>
<file>../../src/wp-includes/class-simplepie.php</file>
<file>../../src/wp-includes/class-snoopy.php</file>
<file>../../src/wp-includes/deprecated.php</file>
<file>../../src/wp-includes/ms-deprecated.php</file>
<file>../../src/wp-includes/pluggable-deprecated.php</file>
<file>../../src/wp-includes/rss.php</file>
</exclude>
</source>
<logging>
<junit outputFile="build/logs/junit.xml" />
</logging>
</phpunit>
Loading