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
14 changes: 9 additions & 5 deletions .github/workflows/reusable-phpunit-tests-v3.yml
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,11 @@ jobs:
with:
custom-cache-suffix: $(/bin/date -u --date='last Mon' "+%F")

# Release branches run this workflow from trunk, but older branches lack this file.
- name: Select PHPUnit configuration
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

Expand Down Expand Up @@ -296,15 +301,14 @@ 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' || '' }}
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 @@ -373,18 +377,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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ wp-tests-config.php
# Files and folders related to build/test tools
.phpunit.result.cache
/phpunit.xml
/phpunit10.xml
/.phpcs.xml
/phpcs.xml
.cache/*
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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" ]
"test": [ "Composer\\Config::disableProcessTimeout", "@php ./tests/phpunit/run.php" ]
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +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: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",
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 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 and later. These use the `<source>` element, so PHPUnit 10.0 is not supported.

### Running Tests Locally

`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. Passing an explicit `-c`, `--configuration`, or `--no-configuration` option overrides the automatic selection.

`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 on a host that prohibits loopback listening

Set `WP_TESTS_SKIP_HTTP_LOOPBACK=1` in the PHPUnit process environment if the host prohibits listening on a local TCP port. When PHP cannot reserve a port, PHPUnit skips only the HTTP transport tests that need the local fixture server. If PHP reserves a port, the tests run normally and server startup errors still fail.
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
Loading