1919 */
2020check_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.
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
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
12094perform_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.
135109log_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