11<?php
22/**
3- * Validates the presence of essential environment variables necessary for the application to run correctly.
4- * Specifically checks for variables related to directories and database configuration. It also ensures that
5- * the test and preparation directories are the same when running locally without SSH connection requirements.
3+ * Confirms the presence of required environment variables.
64 *
7- * This function will issue error messages through `error_message()` for any missing environment variables
8- * and logs a message upon successful validation of all required variables.
5+ * For the test runner to function correctly, a few requirements must be met:
6+ * - A database configuration must be provided using the documented environment
7+ * variables.
8+ * - The preparation and test directories must be the same when running
9+ * locally (not making use of an SSH connection).
910 *
10- * @param bool $check_db Optional. Whether to include database-related environment variables in the check. Defaults to true.
11- * If set to false, database variables (prefixed with 'WPT_DB_') are not checked .
11+ * @param bool $check_db Optional. Whether to confirm `WPT_DB_*` environment
12+ * variables are present. Default true .
1213 *
13- * @return void This function does not return a value but will halt execution if any required environment variable is missing.
14+ * @return void This function does not return a value but will halt execution
15+ * if any required environment variable is missing.
1416 *
1517 * @uses getenv() to retrieve environment variable values.
1618 * @uses error_message() to display error messages for missing variables.
@@ -36,21 +38,21 @@ function check_required_env( $check_db = true ) {
3638 }
3739
3840 if ( empty ( getenv ( 'WPT_SSH_CONNECT ' ) )
39- && getenv ( 'WPT_TEST_DIR ' ) !== getenv ( 'WPT_PREPARE_DIR ' ) ) {
41+ && getenv ( 'WPT_TEST_DIR ' ) !== getenv ( 'WPT_PREPARE_DIR ' ) ) {
4042 error_message ( 'WPT_TEST_DIR must be the same as WPT_PREPARE_DIR when running locally. ' );
4143 }
4244
4345 log_message ( 'Environment variables pass checks. ' );
4446}
45-
4647/**
47- * Executes a series of shell commands provided in the operations array. Each
48- * operation is logged before execution. If any command fails (indicated by a
49- * non-zero return code), an error message is displayed. This function is useful
50- * for automating batch shell tasks within a PHP script, with error handling for
51- * each operation.
48+ * Executes a set of shell commands.
49+ *
50+ * Each command is logged before being executed.
51+ *
52+ * When a non-zero return code is encountered, the error message is displayed
53+ * and the runner will fail.
5254 *
53- * @param array $operations An array of shell commands (strings) to be executed .
55+ * @param array $operations A list of shell commands (strings) to execute .
5456 * Each command should be a valid shell command and properly escaped for safety.
5557 * The commands are executed in the order they appear in the array.
5658 *
@@ -83,15 +85,12 @@ function perform_operations( $operations ) {
8385}
8486
8587/**
86- * Writes a message followed by a newline to the standard output (STDOUT). This
87- * function is commonly used for logging purposes, providing feedback during
88- * script execution, or debugging. The message is appended with the PHP
89- * end-of-line constant (PHP_EOL) to ensure proper line breaks on different
90- * operating systems.
88+ * Writes a message to the standard output (STDOUT).
9189 *
92- * @param string $message The message to be logged. This should be a string, and
93- * it will be output exactly as provided, followed by a system-specific newline
94- * character.
90+ * The message is appended with PHP_EOL to ensure proper line breaks on
91+ * different operating systems.
92+ *
93+ * @param string $message The message to be logged.
9594 *
9695 * @return void This function does not return a value. It directly writes the
9796 * message to STDOUT, which is typically visible in the console or terminal
@@ -106,11 +105,13 @@ function log_message( $message ) {
106105}
107106
108107/**
109- * Writes an error message prefixed with "Error: " to the standard error output
110- * (STDERR) and terminates the script with a status code of 1. This function is
111- * typically used to report errors during script execution. The message is
112- * appended with the PHP end-of-line constant (PHP_EOL) to ensure it is properly
113- * displayed on all operating systems.
108+ * Displays an error message and terminates the test runner execution.
109+ *
110+ * The error message is prefixed with "Error: " and appended with PHP_EOL
111+ * before being written to the standard output (STDOUT).
112+ *
113+ * After outputting the error message, the script will be terminated with a
114+ * status code of 1.
114115 *
115116 * @param string $message The error message to be logged. This string will be
116117 * output as provided, but prefixed with "Error: " to indicate its nature,
@@ -130,12 +131,11 @@ function error_message( $message ) {
130131}
131132
132133/**
133- * Ensures a single trailing slash is present at the end of a given string. This
134- * function first removes any existing trailing slashes from the input string to
135- * avoid duplication and then appends a single slash. It's commonly used to
136- * normalize file paths or URLs to ensure consistency in format, especially when
137- * concatenating paths or performing file system operations that expect a
138- * trailing slash.
134+ * Ensures a single trailing slash is present at the end of a given string.
135+ *
136+ * File system operations often expect a single trailing slash when referring
137+ * to directories or paths. This ensures that only one trailing slash is
138+ * present at the end of a given string.
139139 *
140140 * @param string $string The input string to which a trailing slash will be
141141 * added. This could be a file path, URL, or any other string that requires a
@@ -155,14 +155,16 @@ function trailingslashit( $string ) {
155155}
156156
157157/**
158- * Parses JUnit XML formatted string to extract test results, focusing
159- * specifically on test failures and errors.
160- * The function converts the XML data into a structured JSON format that
161- * summarizes the overall test outcomes, including the total number of tests,
162- * failures, errors, and execution time. Only test suites and cases that contain
163- * failures or errors are included in the final JSON output. This function is
164- * useful for automated test result analysis, continuous integration reporting,
165- * or any scenario where a quick summary of test failures and errors is needed.
158+ * Extracts test results from a JUnit XML string.
159+ *
160+ * This extracts the relevant information from the test results into a format
161+ * accepted and understood by the WordPress Test Reporter plugin.
162+ *
163+ * The data specifically extracted is:
164+ * - Total number of tests.
165+ * - Number of failures.
166+ * - Number of errors.
167+ * - Overall execution time.
166168 *
167169 * @param string $xml_string The JUnit XML data as a string. This should be
168170 * well-formed XML representing the results of test executions, typically
@@ -240,13 +242,13 @@ function process_junit_xml( $xml_string )
240242}
241243
242244/**
243- * Submits test results along with associated metadata to a specified reporting
244- * API. The function constructs a POST request containing the test results, SVN
245- * revision, SVN message, environment data, and uses an API key for
246- * authentication. The reporting API's URL is retrieved from an environment
247- * variable; if not found, a default URL is used. This function is typically
248- * used to automate the reporting of test outcomes to a centralized system for
249- * analysis, tracking, and historical record-keeping .
245+ * Submits test results to a reporting API endpoint.
246+ *
247+ * This submits test results and related metadata to a site running the
248+ * WordPress Test Reporter plugin using cURL.
249+ *
250+ * Reports are always submitted to WordPress.org Unless the WPT_REPORT_URL
251+ * environment variable is set .
250252 *
251253 * @param string $results The test results in a processed format (e.g., JSON)
252254 * ready for submission to the reporting API.
@@ -314,30 +316,29 @@ function upload_results( $results, $rev, $message, $env, $api_key ) {
314316}
315317
316318/**
317- * Collects and returns an array of key environment details relevant to the
318- * application's context. This includes the PHP version, installed PHP modules
319- * with their versions, system utilities like curl and OpenSSL versions, MySQL
320- * version, and operating system details. This function is useful for diagnostic
321- * purposes, ensuring compatibility, or for reporting system configurations in
322- * debugging or error logs.
323- * The function checks for the availability of specific PHP modules and system
324- * utilities and captures their versions. It uses shell commands to retrieve
325- * system information, which requires the PHP environment to have access to
326- * these commands and appropriate permissions.
327- *
328- * @return array An associative array containing detailed environment information. The array includes:
329- * - 'php_version': The current PHP version.
330- * - 'php_modules': An associative array of selected PHP modules and their versions.
331- * - 'system_utils': Versions of certain system utilities such as 'curl', 'imagemagick', 'graphicsmagick', and 'openssl'.
332- * - 'mysql_version': The version of MySQL installed.
333- * - 'os_name': The name of the operating system.
334- * - 'os_version': The version of the operating system.
319+ Collects details about the testing environment.
320+ *
321+ * The versions of PHP, PHP modules, database software, and system utilities
322+ * can impact the results of the test suite. This gathers the relevant details
323+ * to include in test report submissions.
324+ *
325+ * @return array An associative array containing detailed environment
326+ * information. The array includes:
327+ * - 'php_version': The current PHP version.
328+ * - 'php_modules': An associative array of selected PHP modules and their versions.
329+ * - 'system_utils': Versions of certain system utilities such as 'curl', 'imagemagick',
330+ * 'graphicsmagick', and 'openssl'.
331+ * - 'mysql_version': The version of MySQL installed.
332+ * - 'os_name': The name of the operating system.
333+ * - 'os_version': The version of the operating system.
335334 *
336335 * @uses phpversion() to get the PHP version and module versions.
337336 *
338- * @uses shell_exec() to execute system commands for retrieving MySQL version, OS details, and versions of utilities like curl and OpenSSL.
337+ * @uses shell_exec() to execute system commands for retrieving MySQL version,
338+ * OS details, and versions of utilities like curl and OpenSSL.
339339 *
340- * @uses class_exists() to check for the availability of the Imagick and Gmagick classes for version detection.
340+ * @uses class_exists() to check for the availability of the Imagick and Gmagick
341+ * classes for version detection.
341342 */
342343function get_env_details () {
343344
0 commit comments