@@ -633,10 +633,12 @@ private static function configure_sqlite( $dir ): void {
633633 /**
634634 * We cache the results of `wp core download` to improve test performance.
635635 * Ideally, we'd cache at the HTTP layer for more reliable tests.
636+ *
637+ * @param string $version
636638 */
637- private static function cache_wp_files (): void {
638- $ wp_version = getenv ( 'WP_VERSION ' );
639- $ wp_version_suffix = ( false !== $ wp_version ) ? "- $ wp_version " : '' ;
639+ private static function cache_wp_files ( $ version = '' ): void {
640+ $ wp_version = $ version ?: getenv ( 'WP_VERSION ' );
641+ $ wp_version_suffix = $ wp_version ? "- $ wp_version " : '' ;
640642 self ::$ cache_dir = sys_get_temp_dir () . '/wp-cli-test-core-download-cache ' . $ wp_version_suffix ;
641643 self ::$ sqlite_cache_dir = sys_get_temp_dir () . '/wp-cli-test-sqlite-integration-cache ' ;
642644
@@ -1365,10 +1367,15 @@ public function add_line_to_wp_config( &$wp_config_code, $line ): void {
13651367
13661368 /**
13671369 * @param string $subdir
1370+ * @param string $version
13681371 */
1369- public function download_wp ( $ subdir = '' ): void {
1370- if ( ! self ::$ cache_dir ) {
1371- self ::cache_wp_files ();
1372+ public function download_wp ( $ subdir = '' , $ version = '' ): void {
1373+ $ wp_version = $ version ?: getenv ( 'WP_VERSION ' );
1374+ $ wp_version_suffix = $ wp_version ? "- $ wp_version " : '' ;
1375+ $ expected_cache_dir = sys_get_temp_dir () . '/wp-cli-test-core-download-cache ' . $ wp_version_suffix ;
1376+
1377+ if ( ! self ::$ cache_dir || self ::$ cache_dir !== $ expected_cache_dir ) {
1378+ self ::cache_wp_files ( $ version );
13721379
13731380 $ result = Process::create ( Utils \esc_cmd ( 'wp core version --debug --path=%s ' , self ::$ cache_dir ), null , self ::get_process_env_variables () )->run_check ();
13741381 echo "[Debug messages] \n" ;
@@ -1442,10 +1449,11 @@ public function create_config( $subdir = '', $extra_php = false ): void {
14421449
14431450 /**
14441451 * @param string $subdir
1452+ * @param string $version
14451453 */
1446- public function install_wp ( $ subdir = '' ): void {
1447- $ wp_version = getenv ( 'WP_VERSION ' );
1448- $ wp_version_suffix = ( false !== $ wp_version ) ? "- $ wp_version " : '' ;
1454+ public function install_wp ( $ subdir = '' , $ version = '' ): void {
1455+ $ wp_version = $ version ?: getenv ( 'WP_VERSION ' );
1456+ $ wp_version_suffix = $ wp_version ? "- $ wp_version " : '' ;
14491457 self ::$ install_cache_dir = sys_get_temp_dir () . '/wp-cli-test-core-install-cache ' . $ wp_version_suffix ;
14501458 if ( ! file_exists ( self ::$ install_cache_dir ) ) {
14511459 mkdir ( self ::$ install_cache_dir );
@@ -1460,7 +1468,7 @@ public function install_wp( $subdir = '' ): void {
14601468 $ this ->create_db ();
14611469 }
14621470 $ this ->create_run_dir ();
1463- $ this ->download_wp ( $ subdir );
1471+ $ this ->download_wp ( $ subdir, $ version );
14641472 $ this ->create_config ( $ subdir , $ config_extra_php );
14651473
14661474 $ install_args = [
0 commit comments