|
6 | 6 | * The script assumes that certain environment variables are set to configure SSH, |
7 | 7 | * directories, and executables used in the test preparation process. |
8 | 8 | * |
| 9 | + * @link https://github.com/wordpress/phpunit-test-runner/ Original source repository |
9 | 10 | * @package WordPress |
10 | 11 | */ |
11 | 12 | require __DIR__ . '/functions.php'; |
|
42 | 43 | case 'true': |
43 | 44 | $WPT_DEBUG = true; |
44 | 45 | break; |
| 46 | + case 'verbose': |
| 47 | + $WPT_DEBUG = 'verbose'; |
| 48 | + break; |
45 | 49 | default: |
46 | 50 | $WPT_DEBUG = false; |
47 | 51 | break; |
|
83 | 87 | if( empty( $WPT_SSH_CONNECT ) ) { |
84 | 88 | perform_operations( array( |
85 | 89 | 'chmod 600 ~/.ssh/id_rsa', |
86 | | - 'wp cli info', |
| 90 | + 'wp cli info' |
87 | 91 | ) ); |
88 | 92 | } else { |
89 | 93 | perform_operations( array( |
90 | 94 | 'chmod 600 ~/.ssh/id_rsa', |
91 | | - 'ssh -q ' . $WPT_SSH_OPTIONS . ' ' . escapeshellarg( $WPT_SSH_CONNECT ) . ' wp cli info', |
| 95 | + 'ssh -q ' . $WPT_SSH_OPTIONS . ' ' . escapeshellarg( $WPT_SSH_CONNECT ) . ' wp cli info' |
92 | 96 | ) ); |
93 | 97 | } |
94 | 98 |
|
|
115 | 119 | 'cd ' . escapeshellarg( $WPT_PREPARE_DIR . '/tests/phpunit/data/plugins/' ) . '; unzip wordpress-importer.zip; rm wordpress-importer.zip', |
116 | 120 |
|
117 | 121 | // Change directory to the preparation directory, install npm dependencies, and build the project. |
118 | | - 'cd ' . escapeshellarg( $WPT_PREPARE_DIR ) . '; npm install && npm run build', |
| 122 | + 'cd ' . escapeshellarg( $WPT_PREPARE_DIR ) . '; npm install && npm run build' |
119 | 123 |
|
120 | 124 | ) ); |
121 | 125 |
|
|
277 | 281 | } |
278 | 282 |
|
279 | 283 | // Log the obtained PHP version for confirmation and debugging purposes. |
280 | | -log_message( "Environment PHP Version: $env_php_version" ); |
281 | | - |
282 | | - |
283 | | -/** |
284 | | - * Ensures compatibility with PHPUnit by adjusting the PHP version if needed. |
285 | | - * If the environment's PHP version is 8.x.x, it overrides the version to 7.4. |
286 | | - * This is because the core PHPUnit tests may not be compatible with PHP 8.x.x. |
287 | | - */ |
288 | | -if ( substr( $env_php_version, 0 , 2 ) === '8.' ) { |
289 | | - // Log the occurrence of PHP version 8.x.x and the decision to use PHPUnit compatible with PHP 7.4 instead. |
290 | | - log_message( 'Version 8.x.x Found. Downloading PHPUnit for PHP 7.4 instead for compatibility.' ); |
291 | | - |
292 | | - // Override the PHP version to 7.4 for PHPUnit compatibility. |
293 | | - $env_php_version = '7.4'; |
294 | | -} |
| 284 | +log_message( 'Environment PHP Version: ' . $env_php_version ); |
295 | 285 |
|
296 | 286 | /** |
297 | 287 | * Checks if the detected PHP version is below 7.0. |
|
300 | 290 | */ |
301 | 291 | if ( version_compare( $env_php_version, '7.0', '<' ) ) { |
302 | 292 | // Logs an error message indicating the test runner's incompatibility with PHP versions below 7.0. |
303 | | - error_message( "The test runner is not compatible with PHP < 7.0." ); |
| 293 | + error_message( 'The test runner is not compatible with PHP < 7.0.' ); |
304 | 294 | } |
305 | 295 |
|
306 | 296 | /** |
307 | | - * Installs PHPUnit 5.7 directly if the PHP version is less than 7.1. |
308 | | - * PHPUnit 5.7 is the last version to support PHP 7.0. |
| 297 | + * Use Composer to manage PHPUnit and its dependencies. |
| 298 | + * This allows for better dependency management and compatibility. |
309 | 299 | */ |
310 | | -if ( version_compare( $env_php_version, '7.1', '<' ) ) { |
311 | | - |
312 | | - // Download the PHPUnit phar file directly using wget. |
313 | | - perform_operations( array( |
314 | | - 'wget -O ' . escapeshellarg( $WPT_PREPARE_DIR . '/phpunit.phar' ) . ' https://phar.phpunit.de/phpunit-5.7.phar', |
315 | | - ) ); |
316 | | - |
317 | | -} else { |
318 | | - |
319 | | - /** |
320 | | - * If the PHP version is 7.1 or greater, use Composer to manage PHPUnit and its dependencies. |
321 | | - * This allows for better dependency management and compatibility. |
322 | | - */ |
323 | 300 |
|
324 | | - // Check if Composer is installed and available in the PATH. |
325 | | - $composer_cmd = 'cd ' . escapeshellarg( $WPT_PREPARE_DIR ) . ' && '; |
326 | | - $retval = 0; |
327 | | - $composer_path = escapeshellarg( system( 'which composer', $retval ) ); |
328 | | - |
329 | | - if ( $retval === 0 ) { |
330 | | - |
331 | | - // If Composer is available, prepare the command to use the Composer binary. |
332 | | - $composer_cmd .= $composer_path . ' '; |
| 301 | +// Check if Composer is installed and available in the PATH. |
| 302 | +$composer_cmd = 'cd ' . escapeshellarg( $WPT_PREPARE_DIR ) . ' && '; |
| 303 | +$retval = 0; |
| 304 | +$composer_path = escapeshellarg( system( 'which composer', $retval ) ); |
333 | 305 |
|
334 | | - } else { |
| 306 | +if ( $retval === 0 ) { |
335 | 307 |
|
336 | | - // If Composer is not available, download the Composer phar file. |
337 | | - log_message( 'Local Composer not found. Downloading latest stable ...' ); |
| 308 | + // If Composer is available, prepare the command to use the Composer binary. |
| 309 | + $composer_cmd .= $composer_path . ' '; |
338 | 310 |
|
339 | | - perform_operations( array( |
340 | | - 'wget -O ' . escapeshellarg( $WPT_PREPARE_DIR . '/composer.phar' ) . ' https://getcomposer.org/composer-stable.phar', |
341 | | - ) ); |
| 311 | +} else { |
342 | 312 |
|
343 | | - // Update the command to use the downloaded Composer phar file. |
344 | | - $composer_cmd .= 'php composer.phar '; |
345 | | - } |
| 313 | + // If Composer is not available, download the Composer phar file. |
| 314 | + log_message( 'Local Composer not found. Downloading latest stable ...' ); |
346 | 315 |
|
347 | | - // Set the PHP version for Composer to ensure compatibility and update dependencies. |
348 | 316 | perform_operations( array( |
349 | | - $composer_cmd . 'config platform.php ' . escapeshellarg( $env_php_version ), |
350 | | - $composer_cmd . 'update', |
| 317 | + 'wget -O ' . escapeshellarg( $WPT_PREPARE_DIR . '/composer.phar' ) . ' https://getcomposer.org/composer-stable.phar', |
351 | 318 | ) ); |
| 319 | + |
| 320 | + // Update the command to use the downloaded Composer phar file. |
| 321 | + $composer_cmd .= 'php composer.phar '; |
352 | 322 | } |
353 | 323 |
|
| 324 | +// Set the PHP version for Composer to ensure compatibility and update dependencies. |
| 325 | +perform_operations( array( |
| 326 | + $composer_cmd . 'config platform.php ' . escapeshellarg( $env_php_version ), |
| 327 | + $composer_cmd . 'update', |
| 328 | +) ); |
| 329 | + |
354 | 330 | /** |
355 | 331 | * If an SSH connection is configured, use rsync to transfer the prepared files to the remote test environment. |
356 | 332 | * The -r option for rsync enables recursive copying to handle directory structures. |
|
0 commit comments