1818check_required_env ();
1919
2020/**
21- * Retrieves environment variables and sets defaults for test preparation.
22- * These variables are used to configure SSH connections, file paths, and
23- * executable commands needed for setting up the test environment.
21+ * Ensure that optional environment variables are present with default values.
2422 */
25- $ WPT_PREPARE_DIR = trim ( getenv ( 'WPT_PREPARE_DIR ' ) );
26- $ WPT_SSH_CONNECT = trim ( getenv ( 'WPT_SSH_CONNECT ' ) );
27- $ WPT_SSH_OPTIONS = trim ( getenv ( 'WPT_SSH_OPTIONS ' ) ) ? : '-o StrictHostKeyChecking=no ' ;
28- $ WPT_TEST_DIR = trim ( getenv ( 'WPT_TEST_DIR ' ) );
29- $ WPT_PHP_EXECUTABLE = trim ( getenv ( 'WPT_PHP_EXECUTABLE ' ) ) ? : 'php ' ;
30- $ WPT_CERTIFICATE_VALIDATION = trim ( getenv ( 'WPT_CERTIFICATE_VALIDATION ' ) );
31-
32- /**
33- * Determines if the debug mode is enabled based on the 'WPT_DEBUG' environment variable.
34- * The debug mode can affect error reporting and other debug-related settings.
35- */
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 );
23+ $ runner_vars = setup_runner_env_vars ();
5224
5325/**
5426 * Sets up the SSH private key for use in the test environment if provided.
8254 // If no SSH connection string is provided, add a local operation to the array.
8355 // If an SSH connection string is provided, add a remote operation to the array.
8456 // Execute the operations defined in the operations array.
85- if ( empty ( $ WPT_SSH_CONNECT ) ) {
57+ if ( empty ( $ runner_vars [ ' WPT_SSH_CONNECT ' ] ) ) {
8658 perform_operations ( array (
8759 'chmod 600 ~/.ssh/id_rsa ' ,
8860 'wp cli info '
8961 ) );
9062 } else {
9163 perform_operations ( array (
9264 'chmod 600 ~/.ssh/id_rsa ' ,
93- 'ssh -q ' . $ WPT_SSH_OPTIONS . ' ' . escapeshellarg ( $ WPT_SSH_CONNECT ) . ' wp cli info '
65+ 'ssh -q ' . $ runner_vars [ ' WPT_SSH_OPTIONS ' ] . ' ' . escapeshellarg ( $ runner_vars [ ' WPT_SSH_CONNECT ' ] ) . ' wp cli info '
9466 ) );
9567 }
9668
10173 * Useful for local environments
10274 */
10375$ certificate_validation = '' ;
104- if ( ! $ WPT_CERTIFICATE_VALIDATION ) {
76+ if ( ! $ runner_vars [ ' WPT_CERTIFICATE_VALIDATION ' ] ) {
10577 $ certificate_validation .= ' --no-check-certificate ' ;
10678}
10779
11385perform_operations ( array (
11486
11587 // Create the preparation directory if it doesn't exist. The '-p' flag creates intermediate directories as required.
116- 'mkdir -p ' . escapeshellarg ( $ WPT_PREPARE_DIR ),
88+ 'mkdir -p ' . escapeshellarg ( $ runner_vars [ ' WPT_PREPARE_DIR ' ] ),
11789
11890 // Clone the WordPress develop repository from GitHub into the preparation directory.
11991 // The '--depth=1' flag creates a shallow clone with a history truncated to the last commit.
120- 'git clone --depth=1 https://github.com/WordPress/wordpress-develop.git ' . escapeshellarg ( $ WPT_PREPARE_DIR ),
92+ 'git clone --depth=1 https://github.com/WordPress/wordpress-develop.git ' . escapeshellarg ( $ runner_vars [ ' WPT_PREPARE_DIR ' ] ),
12193
12294 // Change directory to the preparation directory, install npm dependencies, and build the project.
123- 'cd ' . escapeshellarg ( $ WPT_PREPARE_DIR ) . '; npm install && npm run build '
95+ 'cd ' . escapeshellarg ( $ runner_vars [ ' WPT_PREPARE_DIR ' ] ) . '; npm install && npm run build '
12496
12597) );
12698
132104 * This file contains template placeholders that need to be replaced with actual values
133105 * from environment variables to configure the WordPress test environment.
134106 */
135- $ contents = file_get_contents ( $ WPT_PREPARE_DIR . '/wp-tests-config-sample.php ' );
107+ $ contents = file_get_contents ( $ runner_vars [ ' WPT_PREPARE_DIR ' ] . '/wp-tests-config-sample.php ' );
136108
137109/**
138110 * Prepares a script to log system information relevant to the testing environment.
@@ -240,7 +212,7 @@ function curl_selected_bits(\$k) { return in_array(\$k, array('version', 'ssl_ve
240212$ system_logger = $ logger_replace_string . $ system_logger ;
241213
242214// Define a string that will set the 'WP_PHP_BINARY' constant to the path of the PHP executable.
243- $ php_binary_string = 'define( \'WP_PHP_BINARY \', \'' . $ WPT_PHP_EXECUTABLE . '\' ); ' ;
215+ $ php_binary_string = 'define( \'WP_PHP_BINARY \', \'' . $ runner_vars [ ' WPT_PHP_EXECUTABLE ' ] . '\' ); ' ;
244216
245217/**
246218 * An associative array mapping configuration file placeholders to environment-specific values.
@@ -261,22 +233,22 @@ function curl_selected_bits(\$k) { return in_array(\$k, array('version', 'ssl_ve
261233$ contents = str_replace ( array_keys ( $ search_replace ), array_values ( $ search_replace ), $ contents );
262234
263235// Write the modified content to the wp-tests-config.php file, which will be used by the test suite.
264- file_put_contents ( $ WPT_PREPARE_DIR . '/wp-tests-config.php ' , $ contents );
236+ file_put_contents ( $ runner_vars [ ' WPT_PREPARE_DIR ' ] . '/wp-tests-config.php ' , $ contents );
265237
266238/**
267239 * Determines the PHP version of the test environment to ensure the correct version of PHPUnit is installed.
268240 * It constructs a command that prints out the PHP version in a format compatible with PHPUnit's version requirements.
269241 */
270- $ php_version_cmd = $ WPT_PHP_EXECUTABLE . " -r \"print PHP_MAJOR_VERSION . '.' . PHP_MINOR_VERSION . '.' . PHP_RELEASE_VERSION; \"" ;
242+ $ php_version_cmd = $ runner_vars [ ' WPT_PHP_EXECUTABLE ' ] . " -r \"print PHP_MAJOR_VERSION . '.' . PHP_MINOR_VERSION . '.' . PHP_RELEASE_VERSION; \"" ;
271243
272244/**
273245 * If an SSH connection string is provided, the command to determine the PHP version is modified
274246 * to execute remotely over SSH. This is required if the test environment is not the local machine.
275247 */
276- if ( ! empty ( $ WPT_SSH_CONNECT ) ) {
248+ if ( ! empty ( $ runner_vars [ ' WPT_SSH_CONNECT ' ] ) ) {
277249 // The PHP version check command is prefixed with the SSH command, including SSH options,
278250 // and the connection string, ensuring the command is executed on the remote machine.
279- $ php_version_cmd = 'ssh ' . $ WPT_SSH_OPTIONS . ' ' . escapeshellarg ( $ WPT_SSH_CONNECT ) . ' ' . escapeshellarg ( $ php_version_cmd );
251+ $ php_version_cmd = 'ssh ' . $ runner_vars [ ' WPT_SSH_OPTIONS ' ] . ' ' . escapeshellarg ( $ runner_vars [ ' WPT_SSH_CONNECT ' ] ) . ' ' . escapeshellarg ( $ php_version_cmd );
280252}
281253
282254// Initialize return value variable for the exec function call.
@@ -313,7 +285,7 @@ function curl_selected_bits(\$k) { return in_array(\$k, array('version', 'ssl_ve
313285 */
314286
315287// Check if Composer is installed and available in the PATH.
316- $ composer_cmd = 'cd ' . escapeshellarg ( $ WPT_PREPARE_DIR ) . ' && ' ;
288+ $ composer_cmd = 'cd ' . escapeshellarg ( $ runner_vars [ ' WPT_PREPARE_DIR ' ] ) . ' && ' ;
317289$ retval = 0 ;
318290$ composer_path = escapeshellarg ( system ( 'which composer ' , $ retval ) );
319291
@@ -328,7 +300,7 @@ function curl_selected_bits(\$k) { return in_array(\$k, array('version', 'ssl_ve
328300 log_message ( 'Local Composer not found. Downloading latest stable ... ' );
329301
330302 perform_operations ( array (
331- 'wget -O ' . escapeshellarg ( $ WPT_PREPARE_DIR . '/composer.phar ' ) . ' https://getcomposer.org/composer-stable.phar ' ,
303+ 'wget -O ' . escapeshellarg ( $ runner_vars [ ' WPT_PREPARE_DIR ' ] . '/composer.phar ' ) . ' https://getcomposer.org/composer-stable.phar ' ,
332304 ) );
333305
334306 // Update the command to use the downloaded Composer phar file.
@@ -346,20 +318,20 @@ function curl_selected_bits(\$k) { return in_array(\$k, array('version', 'ssl_ve
346318 * The -r option for rsync enables recursive copying to handle directory structures.
347319 * Additional rsync options may be included for more verbose output if debugging is enabled.
348320 */
349- if ( ! empty ( $ WPT_SSH_CONNECT ) ) {
321+ if ( ! empty ( $ runner_vars [ ' WPT_SSH_CONNECT ' ] ) ) {
350322 // Initialize rsync options with recursive copying.
351323 $ rsync_options = '-r ' ;
352324
353325 // If debug mode is set to verbose, append 'v' to rsync options for verbose output.
354- if ( ' verbose ' === $ WPT_DEBUG ) {
326+ if ( $ runner_vars [ ' WPT_DEBUG ' ] ) {
355327 $ rsync_options = $ rsync_options . 'v ' ;
356328 }
357329
358330 // Perform the rsync operation with the configured options and exclude patterns.
359331 // This operation synchronizes the test environment with the prepared files, excluding version control directories
360332 // and other non-essential files for test execution.
361333 perform_operations ( array (
362- '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 ),
334+ '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 ' ] ),
363335 ) );
364336}
365337
0 commit comments