Skip to content

Commit 9d7f065

Browse files
committed
Merge branch 'master' into documentation-changes
2 parents 4225006 + 5e35b46 commit 9d7f065

8 files changed

Lines changed: 127 additions & 121 deletions

File tree

.env.default

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,16 @@ export WPT_SSH_OPTIONS=""
5757
# SSH private key, base64 encoded.
5858
export WPT_SSH_PRIVATE_KEY_BASE64=""
5959

60-
# Output logging
61-
# Use 'verbose' to increase verbosity
62-
export WPT_DEBUG=""
60+
# Whether to enable debug Mode.
61+
#
62+
# Enabling debug mode will output verbose logging and details about each part
63+
# of the test runner.
64+
#
65+
# 0 = Debug mode off
66+
# 1 = Debug mode on
67+
#
68+
# Any other truthy value will also enable debug mode.
69+
export WPT_DEBUG=
6370

6471
# Certificate validation
6572
# Use 1 to validate, and 0 to not validate
@@ -68,7 +75,7 @@ export WPT_CERTIFICATE_VALIDATION=1
6875
# WordPress flavor
6976
# 0 = WordPress (simple version)
7077
# 1 = WordPress Multisite
71-
export WPT_FLAVOR=1
78+
export WPT_FLAVOR=0
7279

7380
# Extra tests (groups)
7481
# 0 = none

.github/workflows/props-bot.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ jobs:
7676
format: 'git'
7777

7878
- name: Remove the props-bot label
79-
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
79+
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
8080
if: ${{ github.event.action == 'labeled' && 'props-bot' == github.event.label.name }}
8181
with:
8282
retries: 2

.github/workflows/tests.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,13 @@ jobs:
6767
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
6868

6969
- name: Set up PHP
70-
uses: shivammathur/setup-php@20529878ed81ef8e78ddf08b480401e6101a850f # v2.35.3
70+
uses: shivammathur/setup-php@ec406be512d7077f68eed36e63f4d91bc006edc4 # v2.35.4
7171
with:
7272
php-version: '7.4'
7373
coverage: none
7474

7575
- name: Install NodeJS
76-
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
76+
uses: actions/setup-node@a0853c24544627f65ddf259abe73b1d18a591444 # v5.0.0
7777
with:
7878
node-version: 20
7979

cleanup.php

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,10 @@
2222
*/
2323
check_required_env();
2424

25-
/*
26-
* Retrieve environment variables falling back to defaults.
27-
*
28-
* These variables are used to configure SSH connections, file paths, and
29-
* executable commands needed for setting up the test environment.
25+
/**
26+
* Ensure that all environment variables are present with default values.
3027
*/
31-
$WPT_PREPARE_DIR = trim( getenv( 'WPT_PREPARE_DIR' ) );
32-
$WPT_SSH_CONNECT = trim( getenv( 'WPT_SSH_CONNECT' ) );
33-
$WPT_SSH_OPTIONS = trim( getenv( 'WPT_SSH_OPTIONS' ) ) ? : '-o StrictHostKeyChecking=no';
34-
$WPT_TEST_DIR = trim( getenv( 'WPT_TEST_DIR' ) );
35-
$WPT_RM_TEST_DIR_CMD = trim( getenv( 'WPT_RM_TEST_DIR_CMD' ) ) ? : 'rm -r ' . $WPT_TEST_DIR;
28+
$runner_vars = setup_runner_env_vars();
3629

3730
/*
3831
* Clean up the test preparation directory.
@@ -47,9 +40,9 @@
4740
* - Remove the entire preparation directory.
4841
*/
4942
perform_operations( array(
50-
'rm -rf ' . escapeshellarg( $WPT_PREPARE_DIR . '/.git' ),
51-
'rm -rf ' . escapeshellarg( $WPT_PREPARE_DIR . '/node_modules/.cache' ),
52-
'rm -r ' . escapeshellarg( $WPT_PREPARE_DIR ),
43+
'rm -rf ' . escapeshellarg( $runner_vars['WPT_PREPARE_DIR'] . '/.git' ),
44+
'rm -rf ' . escapeshellarg( $runner_vars['WPT_PREPARE_DIR'] . '/node_modules/.cache' ),
45+
'rm -r ' . escapeshellarg( $runner_vars['WPT_PREPARE_DIR'] ),
5346
) );
5447

5548
/*
@@ -58,8 +51,8 @@
5851
* This ensures a clean slate on the remote server the next time the test
5952
* runner is executed.
6053
*/
61-
if ( ! empty( $WPT_SSH_CONNECT ) ) {
54+
if ( ! empty( $runner_vars['WPT_SSH_CONNECT'] ) ) {
6255
perform_operations( array(
63-
'ssh ' . $WPT_SSH_OPTIONS . ' ' . escapeshellarg( $WPT_SSH_CONNECT ) . ' ' . escapeshellarg( $WPT_RM_TEST_DIR_CMD ),
56+
'ssh ' . $runner_vars['WPT_SSH_OPTIONS'] . ' ' . escapeshellarg( $runner_vars['WPT_SSH_CONNECT'] ) . ' ' . escapeshellarg( $runner_vars['WPT_RM_TEST_DIR_CMD'] ),
6457
) );
6558
}

functions.php

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,68 @@ function check_required_env( $check_db = true ) {
4444

4545
log_message( 'Environment variables pass checks.' );
4646
}
47+
48+
/**
49+
* Parses environment variables used to configure the test runner.
50+
*
51+
* @return array[] {
52+
* Test runner configuration options.
53+
*
54+
* @type array ...$0 {
55+
* An associative array of test runner configuration options.
56+
*
57+
* @type string $WPT_TEST_DIR Path to the directory where wordpress-develop is placed for testing
58+
* after being prepared. Default '/tmp/wp-test-runner'.
59+
* @type string $WPT_PREPARE_DIR Path to the temporary directory where wordpress-develop is cloned
60+
* and configured. Default '/tmp/wp-test-runner'.
61+
* @type string $WPT_SSH_CONNECT List of inner blocks. An array of arrays that
62+
* have the same structure as this one.
63+
* @type string $WPT_SSH_OPTIONS HTML from inside block comment delimiters.
64+
* @type string $WPT_PHP_EXECUTABLE List of string fragments and null markers where
65+
* inner blocks were found.
66+
* @type string $WPT_RM_TEST_DIR_CMD Command for removing the test directory.
67+
* @type string $WPT_REPORT_API_KEY API key for submitting test results.
68+
* @type bool $WPT_CERTIFICATE_VALIDATION Whether to validate TLS certificates. Default true.
69+
* @type bool $WPT_DEBUG_MODE Whether debug mode is enabled.
70+
* }
71+
* }
72+
*/
73+
function setup_runner_env_vars() {
74+
// Set the test directory first as it's needed for processing other variables.
75+
$runner_configuration = array(
76+
'WPT_TEST_DIR' => trim( getenv( 'WPT_TEST_DIR' ) ) ?: '/tmp/wp-test-runner',
77+
);
78+
79+
/*
80+
* When no value is provided for WPT_CERTIFICATE_VALIDATION, assume that the default of true (validate certificates)
81+
* is desired.
82+
*/
83+
if ( false === getenv( 'WPT_CERTIFICATE_VALIDATION' ) ) {
84+
$runner_configuration['WPT_CERTIFICATE_VALIDATION'] = true;
85+
} else {
86+
$runner_configuration['WPT_CERTIFICATE_VALIDATION'] = (bool) getenv( 'WPT_CERTIFICATE_VALIDATION' );
87+
}
88+
89+
return array_merge(
90+
$runner_configuration,
91+
array(
92+
// Directory configuration
93+
'WPT_PREPARE_DIR' => trim( getenv( 'WPT_PREPARE_DIR' ) ) ?: '/tmp/wp-test-runner',
94+
// SSH connection configuration
95+
'WPT_SSH_CONNECT' => trim( getenv( 'WPT_SSH_CONNECT' ) ),
96+
'WPT_SSH_OPTIONS' => trim( getenv( 'WPT_SSH_OPTIONS' ) ) ?: '-o StrictHostKeyChecking=no',
97+
// Test execution configuration
98+
'WPT_PHP_EXECUTABLE' => trim( getenv( 'WPT_PHP_EXECUTABLE' ) ) ?: 'php',
99+
// Cleanup configuration
100+
'WPT_RM_TEST_DIR_CMD' => trim( getenv( 'WPT_RM_TEST_DIR_CMD' ) ) ?: 'rm -r ' . $runner_configuration['WPT_TEST_DIR'],
101+
// Reporting configuration
102+
'WPT_REPORT_API_KEY' => trim( getenv( 'WPT_REPORT_API_KEY' ) ),
103+
// Miscellaneous
104+
'WPT_DEBUG' => (bool) getenv( 'WPT_DEBUG' ),
105+
)
106+
);
107+
}
108+
47109
/**
48110
* Executes a set of shell commands.
49111
*

prepare.php

Lines changed: 20 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -19,36 +19,10 @@
1919
*/
2020
check_required_env();
2121

22-
/*
23-
* Retrieve environment variables falling back to defaults.
24-
*
25-
* These variables are used to configure SSH connections, file paths, and
26-
* executable commands needed for setting up the test environment.
22+
/**
23+
* Ensure that optional environment variables are present with default values.
2724
*/
28-
$WPT_PREPARE_DIR = trim( getenv( 'WPT_PREPARE_DIR' ) );
29-
$WPT_SSH_CONNECT = trim( getenv( 'WPT_SSH_CONNECT' ) );
30-
$WPT_SSH_OPTIONS = trim( getenv( 'WPT_SSH_OPTIONS' ) ) ? : '-o StrictHostKeyChecking=no';
31-
$WPT_TEST_DIR = trim( getenv( 'WPT_TEST_DIR' ) );
32-
$WPT_PHP_EXECUTABLE = trim( getenv( 'WPT_PHP_EXECUTABLE' ) ) ? : 'php';
33-
$WPT_CERTIFICATE_VALIDATION = trim( getenv( 'WPT_CERTIFICATE_VALIDATION' ) );
34-
35-
// Configure debug mode based on the WPT_DEBUG environment variable.
36-
$WPT_DEBUG_INI = getenv( 'WPT_DEBUG' );
37-
switch( $WPT_DEBUG_INI ) {
38-
case 0:
39-
case 'false':
40-
$WPT_DEBUG = false;
41-
break;
42-
case 1:
43-
case 'true':
44-
case 'verbose':
45-
$WPT_DEBUG = 'verbose';
46-
break;
47-
default:
48-
$WPT_DEBUG = false;
49-
break;
50-
}
51-
unset( $WPT_DEBUG_INI );
25+
$runner_vars = setup_runner_env_vars();
5226

5327
/*
5428
* Configure a private SSH key for remote testing.
@@ -85,15 +59,15 @@
8559
// When am SSH connection string is not provided, add a local operation to the array.
8660
// When an SSH connection string is provided, add a remote operation to the array.
8761
// Execute the operations defined in the operations array.
88-
if( empty( $WPT_SSH_CONNECT ) ) {
62+
if( empty( $runner_vars['WPT_SSH_CONNECT'] ) ) {
8963
perform_operations( array(
9064
'chmod 600 ~/.ssh/id_rsa',
9165
'wp cli info'
9266
) );
9367
} else {
9468
perform_operations( array(
9569
'chmod 600 ~/.ssh/id_rsa',
96-
'ssh -q ' . $WPT_SSH_OPTIONS . ' ' . escapeshellarg( $WPT_SSH_CONNECT ) . ' wp cli info'
70+
'ssh -q ' . $runner_vars['WPT_SSH_OPTIONS'] . ' ' . escapeshellarg( $runner_vars['WPT_SSH_CONNECT'] ) . ' wp cli info'
9771
) );
9872
}
9973

@@ -104,7 +78,7 @@
10478
* Useful for local environments
10579
*/
10680
$certificate_validation = '';
107-
if( ! $WPT_CERTIFICATE_VALIDATION ) {
81+
if( ! $runner_vars['WPT_CERTIFICATE_VALIDATION'] ) {
10882
$certificate_validation .= ' --no-check-certificate';
10983
}
11084

@@ -120,22 +94,22 @@
12094
perform_operations( array(
12195

12296
// Create the preparation directory if it doesn't exist. The '-p' flag creates intermediate directories as required.
123-
'mkdir -p ' . escapeshellarg( $WPT_PREPARE_DIR ),
97+
'mkdir -p ' . escapeshellarg( $runner_vars['WPT_PREPARE_DIR'] ),
12498

12599
// Clone the WordPress develop repository from GitHub into the preparation directory.
126100
// The '--depth=1' flag creates a shallow clone with a history truncated to the last commit.
127-
'git clone --depth=1 https://github.com/WordPress/wordpress-develop.git ' . escapeshellarg( $WPT_PREPARE_DIR ),
101+
'git clone --depth=1 https://github.com/WordPress/wordpress-develop.git ' . escapeshellarg( $runner_vars['WPT_PREPARE_DIR'] ),
128102

129103
// Change directory to the preparation directory, install npm dependencies, and build the project.
130-
'cd ' . escapeshellarg( $WPT_PREPARE_DIR ) . '; npm install && npm run build'
104+
'cd ' . escapeshellarg( $runner_vars['WPT_PREPARE_DIR'] ) . '; npm install && npm run build'
131105

132106
) );
133107

134108
// Log a message indicating the start of the variable replacement process for configuration.
135109
log_message( 'Replacing variables in wp-tests-config.php' );
136110

137111
// Don't validate the TLS certificate. Useful for local environments.
138-
$contents = file_get_contents( $WPT_PREPARE_DIR . '/wp-tests-config-sample.php' );
112+
$contents = file_get_contents( $runner_vars['WPT_PREPARE_DIR'] . '/wp-tests-config-sample.php' );
139113

140114
/*
141115
* Prepare a script for logging system information.
@@ -250,7 +224,7 @@ function curl_selected_bits(\$k) { return in_array(\$k, array('version', 'ssl_ve
250224
$system_logger = $logger_replace_string . $system_logger;
251225

252226
// Define a string that will set the 'WP_PHP_BINARY' constant to the path of the PHP executable.
253-
$php_binary_string = 'define( \'WP_PHP_BINARY\', \''. $WPT_PHP_EXECUTABLE . '\' );';
227+
$php_binary_string = 'define( \'WP_PHP_BINARY\', \''. $runner_vars['WPT_PHP_EXECUTABLE'] . '\' );';
254228

255229
/*
256230
* Map configuration file placeholders to environment-specific values.
@@ -272,21 +246,21 @@ function curl_selected_bits(\$k) { return in_array(\$k, array('version', 'ssl_ve
272246
$contents = str_replace( array_keys( $search_replace ), array_values( $search_replace ), $contents );
273247

274248
// Write the modified content to the wp-tests-config.php file, which will be used by the test suite.
275-
file_put_contents( $WPT_PREPARE_DIR . '/wp-tests-config.php', $contents );
249+
file_put_contents( $runner_vars['WPT_PREPARE_DIR'] . '/wp-tests-config.php', $contents );
276250

277251
/*
278252
* Construct a command that generates a PHP version string compatible with
279253
* PHPUnit version requirements.
280254
*/
281-
$php_version_cmd = $WPT_PHP_EXECUTABLE . " -r \"print PHP_MAJOR_VERSION . '.' . PHP_MINOR_VERSION . '.' . PHP_RELEASE_VERSION;\"";
255+
$php_version_cmd = $runner_vars['WPT_PHP_EXECUTABLE'] . " -r \"print PHP_MAJOR_VERSION . '.' . PHP_MINOR_VERSION . '.' . PHP_RELEASE_VERSION;\"";
282256

283257
/**
284258
* This command will differ when running on a remote server via SSH.
285259
*/
286-
if ( ! empty( $WPT_SSH_CONNECT ) ) {
260+
if ( ! empty( $runner_vars['WPT_SSH_CONNECT'] ) ) {
287261
// The PHP version check command is prefixed with the SSH command, including SSH options,
288262
// and the connection string, ensuring the command is executed on the remote machine.
289-
$php_version_cmd = 'ssh ' . $WPT_SSH_OPTIONS . ' ' . escapeshellarg( $WPT_SSH_CONNECT ) . ' ' . escapeshellarg( $php_version_cmd );
263+
$php_version_cmd = 'ssh ' . $runner_vars['WPT_SSH_OPTIONS'] . ' ' . escapeshellarg( $runner_vars['WPT_SSH_CONNECT'] ) . ' ' . escapeshellarg( $php_version_cmd );
290264
}
291265

292266
// Initialize return value variable for the exec function call.
@@ -322,7 +296,7 @@ function curl_selected_bits(\$k) { return in_array(\$k, array('version', 'ssl_ve
322296

323297

324298
// Check if Composer is installed and available in the PATH.
325-
$composer_cmd = 'cd ' . escapeshellarg( $WPT_PREPARE_DIR ) . ' && ';
299+
$composer_cmd = 'cd ' . escapeshellarg( $runner_vars['WPT_PREPARE_DIR'] ) . ' && ';
326300
$retval = 0;
327301
$composer_path = escapeshellarg( system( 'which composer', $retval ) );
328302

@@ -337,7 +311,7 @@ function curl_selected_bits(\$k) { return in_array(\$k, array('version', 'ssl_ve
337311
log_message( 'Local Composer not found. Downloading latest stable ...' );
338312

339313
perform_operations( array(
340-
'wget -O ' . escapeshellarg( $WPT_PREPARE_DIR . '/composer.phar' ) . ' https://getcomposer.org/composer-stable.phar',
314+
'wget -O ' . escapeshellarg( $runner_vars['WPT_PREPARE_DIR'] . '/composer.phar' ) . ' https://getcomposer.org/composer-stable.phar',
341315
) );
342316

343317
// Update the command to use the downloaded Composer phar file.
@@ -359,20 +333,20 @@ function curl_selected_bits(\$k) { return in_array(\$k, array('version', 'ssl_ve
359333
* The -r option for rsync enables recursive copying to handle nested directory
360334
* structures.
361335
*/
362-
if ( ! empty( $WPT_SSH_CONNECT ) ) {
336+
if ( ! empty( $runner_vars['WPT_SSH_CONNECT'] ) ) {
363337
// Initialize rsync options with recursive copying.
364338
$rsync_options = '-r';
365339

366340
// If debug mode is set to verbose, append 'v' to rsync options for verbose output.
367-
if ( 'verbose' === $WPT_DEBUG ) {
341+
if ( $runner_vars['WPT_DEBUG'] ) {
368342
$rsync_options = $rsync_options . 'v';
369343
}
370344

371345
// Perform the rsync operation with the configured options and exclude patterns.
372346
// This operation synchronizes the test environment with the prepared files, excluding version control directories
373347
// and other non-essential files for test execution.
374348
perform_operations( array(
375-
'rsync ' . $rsync_options . ' --exclude=".git/" --exclude="node_modules/" --exclude="composer.phar" -e "ssh ' . $WPT_SSH_OPTIONS . '" ' . escapeshellarg( trailingslashit( $WPT_PREPARE_DIR ) ) . ' ' . escapeshellarg( $WPT_SSH_CONNECT . ':' . $WPT_TEST_DIR ),
349+
'rsync ' . $rsync_options . ' --exclude=".git/" --exclude="node_modules/" --exclude="composer.phar" -e "ssh ' . $runner_vars['WPT_SSH_OPTIONS'] . '" ' . escapeshellarg( trailingslashit( $runner_vars['WPT_PREPARE_DIR'] ) ) . ' ' . escapeshellarg( $runner_vars['WPT_SSH_CONNECT'] . ':' . $runner_vars['WPT_TEST_DIR'] ),
376350
) );
377351
}
378352

0 commit comments

Comments
 (0)