|
32 | 32 | perform_operations( array( |
33 | 33 | 'mkdir -p ' . escapeshellarg( $WPT_PREPARE_DIR ), |
34 | 34 | 'git clone --depth=1 https://github.com/WordPress/wordpress-develop.git ' . escapeshellarg( $WPT_PREPARE_DIR ), |
35 | | - 'wget -O ' . escapeshellarg( $WPT_PREPARE_DIR . '/phpunit.phar' ) . ' https://phar.phpunit.de/phpunit-5.7.phar', |
36 | 35 | 'wget -O ' . escapeshellarg( $WPT_PREPARE_DIR . '/tests/phpunit/data/plugins/wordpress-importer.zip' ) . ' https://downloads.wordpress.org/plugin/wordpress-importer.zip', |
37 | 36 | 'cd ' . escapeshellarg( $WPT_PREPARE_DIR . '/tests/phpunit/data/plugins/' ) . '; unzip wordpress-importer.zip; rm wordpress-importer.zip', |
38 | 37 | 'cd ' . escapeshellarg( $WPT_PREPARE_DIR ) . '; npm install && npm run build', |
|
104 | 103 | $contents = str_replace( array_keys( $search_replace ), array_values( $search_replace ), $contents ); |
105 | 104 | file_put_contents( $WPT_PREPARE_DIR . '/wp-tests-config.php', $contents ); |
106 | 105 |
|
| 106 | +// Now, install PHPUnit based on the test environment's PHP Version |
| 107 | +$php_version_cmd = $WPT_PHP_EXECUTABLE . " -r \"print PHP_MAJOR_VERSION . '.' . PHP_MINOR_VERSION . '.' . PHP_RELEASE_VERSION;\""; |
| 108 | +if ( ! empty( $WPT_SSH_CONNECT ) ) { |
| 109 | + $php_version_cmd = 'ssh ' . $WPT_SSH_OPTIONS . ' ' . escapeshellarg( $WPT_SSH_CONNECT ) . ' ' . escapeshellarg( $php_version_cmd ); |
| 110 | +} |
| 111 | + |
| 112 | +$retval = 0; |
| 113 | +$env_php_version = exec( $php_version_cmd, $output, $retval ); |
| 114 | +if ( $retval !== 0 ) { |
| 115 | + error_message( 'Could not retrieve the environment PHP Version.' ); |
| 116 | +} |
| 117 | +log_message( "Environment PHP Version: $env_php_version" ); |
| 118 | + |
| 119 | +// If PHP Version is 8.X.X, set PHP Version to 7.4 for compatibility with core PHPUnit tests. |
| 120 | +if ( substr( $env_php_version, 0 , 2 ) === '8.' ) { |
| 121 | + log_message( 'Version 8.x.x Found. Downloading PHPUnit for PHP 7.4 instead for compatibility.' ); |
| 122 | + $env_php_version = '7.4'; |
| 123 | +} |
| 124 | + |
| 125 | +if ( version_compare( $env_php_version, '5.6', '<' ) ) { |
| 126 | + error_message( "The test runner is not compatible with PHP < 5.6." ); |
| 127 | +} |
| 128 | + |
| 129 | +// If PHP version is 5.6-7.0, download PHPUnit 5.7 phar directly. |
| 130 | +if ( version_compare( $env_php_version, '7.1', '<' ) ) { |
| 131 | + perform_operations( array( |
| 132 | + 'wget -O ' . escapeshellarg( $WPT_PREPARE_DIR . '/phpunit.phar' ) . ' https://phar.phpunit.de/phpunit-5.7.phar', |
| 133 | + ) ); |
| 134 | + |
| 135 | +// Otherwise, use Composer to download PHPUnit to get further necessary dependencies. |
| 136 | +} else { |
| 137 | + |
| 138 | + // First, check if composer is available. Download if not. |
| 139 | + $composer_cmd = 'cd ' . escapeshellarg( $WPT_PREPARE_DIR ) . ' && '; |
| 140 | + |
| 141 | + $retval = 0; |
| 142 | + $composer_path = escapeshellarg( system( 'which composer', $retval ) ); |
| 143 | + if ( $retval === 0 ) { |
| 144 | + $composer_cmd .= $composer_path . ' '; |
| 145 | + } else { |
| 146 | + log_message( 'Local Composer not found. Downloading latest stable ...' ); |
| 147 | + |
| 148 | + perform_operations( array( |
| 149 | + 'wget -O ' . escapeshellarg( $WPT_PREPARE_DIR . '/composer.phar' ) . ' https://getcomposer.org/composer-stable.phar', |
| 150 | + ) ); |
| 151 | + |
| 152 | + $composer_cmd .= 'php composer.phar '; |
| 153 | + } |
| 154 | + |
| 155 | + // Set Composer PHP environment, then run Composer. |
| 156 | + perform_operations( array( |
| 157 | + $composer_cmd . 'config platform.php ' . escapeshellarg( $env_php_version ), |
| 158 | + $composer_cmd . 'update', |
| 159 | + ) ); |
| 160 | +} |
| 161 | + |
107 | 162 | // Deliver all files to test environment. |
108 | 163 | if ( ! empty( $WPT_SSH_CONNECT ) ) { |
109 | 164 | $rsync_options = '-r'; |
|
113 | 168 | } |
114 | 169 |
|
115 | 170 | perform_operations( array( |
116 | | - 'rsync ' . $rsync_options . ' --exclude=".git/" --exclude="node_modules/" -e "ssh ' . $WPT_SSH_OPTIONS . '" ' . escapeshellarg( trailingslashit( $WPT_PREPARE_DIR ) ) . ' ' . escapeshellarg( $WPT_SSH_CONNECT . ':' . $WPT_TEST_DIR ), |
| 171 | + '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 ), |
117 | 172 | ) ); |
118 | 173 | } |
119 | 174 |
|
|
0 commit comments