@@ -621,10 +621,12 @@ private static function configure_sqlite( $dir ): void {
621621 /**
622622 * We cache the results of `wp core download` to improve test performance.
623623 * Ideally, we'd cache at the HTTP layer for more reliable tests.
624+ *
625+ * @param string $version
624626 */
625- private static function cache_wp_files (): void {
626- $ wp_version = getenv ( 'WP_VERSION ' );
627- $ wp_version_suffix = ( false !== $ wp_version ) ? "- $ wp_version " : '' ;
627+ private static function cache_wp_files ( $ version = '' ): void {
628+ $ wp_version = $ version ?: getenv ( 'WP_VERSION ' );
629+ $ wp_version_suffix = $ wp_version ? "- $ wp_version " : '' ;
628630 self ::$ cache_dir = sys_get_temp_dir () . '/wp-cli-test-core-download-cache ' . $ wp_version_suffix ;
629631 self ::$ sqlite_cache_dir = sys_get_temp_dir () . '/wp-cli-test-sqlite-integration-cache ' ;
630632
@@ -1288,10 +1290,15 @@ public function add_line_to_wp_config( &$wp_config_code, $line ): void {
12881290
12891291 /**
12901292 * @param string $subdir
1293+ * @param string $version
12911294 */
1292- public function download_wp ( $ subdir = '' ): void {
1293- if ( ! self ::$ cache_dir ) {
1294- self ::cache_wp_files ();
1295+ public function download_wp ( $ subdir = '' , $ version = '' ): void {
1296+ $ wp_version = $ version ?: getenv ( 'WP_VERSION ' );
1297+ $ wp_version_suffix = $ wp_version ? "- $ wp_version " : '' ;
1298+ $ expected_cache_dir = sys_get_temp_dir () . '/wp-cli-test-core-download-cache ' . $ wp_version_suffix ;
1299+
1300+ if ( ! self ::$ cache_dir || self ::$ cache_dir !== $ expected_cache_dir ) {
1301+ self ::cache_wp_files ( $ version );
12951302
12961303 $ result = Process::create ( Utils \esc_cmd ( 'wp core version --debug --path=%s ' , self ::$ cache_dir ), null , self ::get_process_env_variables () )->run_check ();
12971304 echo "[Debug messages] \n" ;
@@ -1365,10 +1372,11 @@ public function create_config( $subdir = '', $extra_php = false ): void {
13651372
13661373 /**
13671374 * @param string $subdir
1375+ * @param string $version
13681376 */
1369- public function install_wp ( $ subdir = '' ): void {
1370- $ wp_version = getenv ( 'WP_VERSION ' );
1371- $ wp_version_suffix = ( false !== $ wp_version ) ? "- $ wp_version " : '' ;
1377+ public function install_wp ( $ subdir = '' , $ version = '' ): void {
1378+ $ wp_version = $ version ?: getenv ( 'WP_VERSION ' );
1379+ $ wp_version_suffix = $ wp_version ? "- $ wp_version " : '' ;
13721380 self ::$ install_cache_dir = sys_get_temp_dir () . '/wp-cli-test-core-install-cache ' . $ wp_version_suffix ;
13731381 if ( ! file_exists ( self ::$ install_cache_dir ) ) {
13741382 mkdir ( self ::$ install_cache_dir );
@@ -1383,7 +1391,7 @@ public function install_wp( $subdir = '' ): void {
13831391 $ this ->create_db ();
13841392 }
13851393 $ this ->create_run_dir ();
1386- $ this ->download_wp ( $ subdir );
1394+ $ this ->download_wp ( $ subdir, $ version );
13871395 $ this ->create_config ( $ subdir , $ config_extra_php );
13881396
13891397 $ install_args = [
0 commit comments