WordPress の PHPUnit テストをみなさんのインフラで実行していただいてありがとうございます! 私たちは、ユーザーのために WordPress との互換性を維持することを手助けしてくださることに感謝しています。
まだ、実行していない場合は、まずはじめにこちらのドキュメントをお読みください。(日本語ドキュメンテーション)
テストランナーは、ファイルの編集等を必要とすること無く利用できるように設計されています。初期設定はいくつかの環境変数で構成されています。(.env.default をご覧ください。)
詳しく説明すると:
- Prepares the test environment for the test suite.
- Runs the PHPUnit tests in the test environment.
- Reports the PHPUnit test results to WordPress.org
- Cleans up the test suite environment.
The test suite runner can be used in one of two ways:
- With Travis (or Circle or some other CI service) as the controller that connects to the remote test environment.
- With the runner cloned to and run directly within the test environment.
The test runner is configured through environment variables, documented in .env.default
. It shouldn't need any code modifications; in fact, please refrain from editing the scripts entirely, as it will make it easier to stay up to date.
With a direct Git clone, you can:
# Copy the default .env file.
cp .env.default .env
# Edit the .env file to define your variables.
vim .env
# Load your variables into scope.
source .env
In a CI service, you can set these environment variables through the service's web console. Importantly, the WPT_SSH_CONNECT
environment variable determines whether the test suite is run locally or against a remote environment.
Concurrently run tests in the same environment by appending build ids to the test directory and table prefix:
export WPT_TEST_DIR=wp-test-runner-$TRAVIS_BUILD_NUMBER
export WPT_TABLE_PREFIX=wptests_$TRAVIS_BUILD_NUMBER\_
Connect to a remote environment over SSH by having the CI job provision the SSH key:
# 1. Create a SSH key pair for the controller to use
ssh-keygen -t rsa -b 4096 -C "travis@travis-ci.org"
# 2. base64 encode the private key for use with the environment variable
cat ~/.ssh/id_rsa | base64 --wrap=0
# 3. Append id_rsa.pub to authorized_keys so the CI service can SSH in
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
Use a more complex SSH connection process by creating a SSH alias:
# 1. Add the following to ~/.ssh/config to create a 'wpt' alias
Host wpt
Hostname 123.45.67.89
User wpt
Port 1234
# 2. Use 'wpt' wherever you might normally use a SSH connection string
ssh wpt
The test suite runner is run in four steps.
Both the prep and test environments must meet some basic requirements.
Prep environment:
- PHP 5.6 or greater (to run scripts).
- Utilities:
git
,rsync
,wget
,unzip
.
Test environment:
- PHP 5.6 or greater with Phar support enabled (for PHPUnit).
- MySQL or MariaDB with access to a writable database.
- Writable filesystem for the entire test directory (see #40910 for details on why).
The prepare.php
step:
- Extracts the base64-encoded SSH private key, if necessary.
- Clones the master branch of the WordPress develop git repo into the preparation directory.
- Downloads
phpunit.phar
to the preparation directory. - Generates
wp-tests-config.php
and puts it into the preparation directory. - Delivers the prepared test directory to the test environment.
The test.php
step:
- Calls
php phpunit.phar
to producetests/phpunit/build/logs/junit.xml
.
The report.php
step:
- Processes PHPUnit XML log into a JSON blob.
- Sends the JSON to WordPress.org.
The cleanup.php
step:
- Resets the database.
- Deletes all files delivered to the test environment.
tk
See LICENSE for project license.