From 62d0ab5da47d936134e9f540ca35fee6b3323526 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 6 Nov 2025 09:45:19 +0000 Subject: [PATCH 1/8] Initial plan From e7d467f8476a93801d8bd90f5f65d34f182df73c Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 6 Nov 2025 09:52:47 +0000 Subject: [PATCH 2/8] Add WP installation with version step Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> --- features/testing.feature | 18 +++++++++++ src/Context/FeatureContext.php | 19 +++++------ src/Context/GivenStepDefinitions.php | 47 ++++++++++++++++++++++++++++ 3 files changed, 75 insertions(+), 9 deletions(-) diff --git a/features/testing.feature b/features/testing.feature index 4bee962c4..51e0b3841 100644 --- a/features/testing.feature +++ b/features/testing.feature @@ -62,3 +62,21 @@ Feature: Test that WP-CLI loads. """ sqlite """ + + Scenario: WP installation with specific version + Given a WP installation with version "6.4.2" + + When I run `wp core version` + Then STDOUT should be: + """ + 6.4.2 + """ + + Scenario: WP installation in subdirectory with specific version + Given a WP installation in 'wordpress' with version "6.3.1" + + When I run `wp core version --path=wordpress` + Then STDOUT should be: + """ + 6.3.1 + """ diff --git a/src/Context/FeatureContext.php b/src/Context/FeatureContext.php index 4ec3c15a3..6386e544d 100644 --- a/src/Context/FeatureContext.php +++ b/src/Context/FeatureContext.php @@ -622,9 +622,9 @@ private static function configure_sqlite( $dir ): void { * We cache the results of `wp core download` to improve test performance. * Ideally, we'd cache at the HTTP layer for more reliable tests. */ - private static function cache_wp_files(): void { - $wp_version = getenv( 'WP_VERSION' ); - $wp_version_suffix = ( false !== $wp_version ) ? "-$wp_version" : ''; + private static function cache_wp_files( $version = '' ): void { + $wp_version = $version ?: getenv( 'WP_VERSION' ); + $wp_version_suffix = ( false !== $wp_version && '' !== $wp_version ) ? "-$wp_version" : ''; self::$cache_dir = sys_get_temp_dir() . '/wp-cli-test-core-download-cache' . $wp_version_suffix; self::$sqlite_cache_dir = sys_get_temp_dir() . '/wp-cli-test-sqlite-integration-cache'; @@ -1289,9 +1289,9 @@ public function add_line_to_wp_config( &$wp_config_code, $line ): void { /** * @param string $subdir */ - public function download_wp( $subdir = '' ): void { + public function download_wp( $subdir = '', $version = '' ): void { if ( ! self::$cache_dir ) { - self::cache_wp_files(); + self::cache_wp_files( $version ); $result = Process::create( Utils\esc_cmd( 'wp core version --debug --path=%s', self::$cache_dir ), null, self::get_process_env_variables() )->run_check(); echo "[Debug messages]\n"; @@ -1365,10 +1365,11 @@ public function create_config( $subdir = '', $extra_php = false ): void { /** * @param string $subdir + * @param string $version */ - public function install_wp( $subdir = '' ): void { - $wp_version = getenv( 'WP_VERSION' ); - $wp_version_suffix = ( false !== $wp_version ) ? "-$wp_version" : ''; + public function install_wp( $subdir = '', $version = '' ): void { + $wp_version = $version ?: getenv( 'WP_VERSION' ); + $wp_version_suffix = ( false !== $wp_version && '' !== $wp_version ) ? "-$wp_version" : ''; self::$install_cache_dir = sys_get_temp_dir() . '/wp-cli-test-core-install-cache' . $wp_version_suffix; if ( ! file_exists( self::$install_cache_dir ) ) { mkdir( self::$install_cache_dir ); @@ -1383,7 +1384,7 @@ public function install_wp( $subdir = '' ): void { $this->create_db(); } $this->create_run_dir(); - $this->download_wp( $subdir ); + $this->download_wp( $subdir, $version ); $this->create_config( $subdir, $config_extra_php ); $install_args = [ diff --git a/src/Context/GivenStepDefinitions.php b/src/Context/GivenStepDefinitions.php index 248766a0e..de520a98b 100644 --- a/src/Context/GivenStepDefinitions.php +++ b/src/Context/GivenStepDefinitions.php @@ -401,6 +401,29 @@ public function given_a_wp_installation(): void { $this->install_wp(); } + /** + * Installs WordPress with a specific version. + * + * ``` + * Scenario: My example scenario + * Given a WP installation with version "6.4.2" + * ... + * + * Scenario: My other scenario + * Given a WP install with version "6.3.1" + * ... + * ``` + * + * @access public + * + * @Given a WP install(ation) with version :version + * + * @param string $version + */ + public function given_a_wp_installation_with_version( $version ): void { + $this->install_wp( '', $version ); + } + /** * Installs WordPress in a given directory. * @@ -424,6 +447,30 @@ public function given_a_wp_installation_in_a_specific_folder( $subdir ): void { $this->install_wp( $subdir ); } + /** + * Installs WordPress in a given directory with a specific version. + * + * ``` + * Scenario: My example scenario + * Given a WP installation in 'foo' with version "6.4.2" + * ... + * + * Scenario: My other scenario + * Given a WP install in 'bar' with version "6.3.1" + * ... + * ``` + * + * @access public + * + * @Given a WP install(ation) in :subdir with version :version + * + * @param string $subdir + * @param string $version + */ + public function given_a_wp_installation_in_a_specific_folder_with_version( $subdir, $version ): void { + $this->install_wp( $subdir, $version ); + } + /** * Installs WordPress with Composer. * From fcb49441ed5234be599e37deb5a1654fb880ec95 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 6 Nov 2025 09:54:40 +0000 Subject: [PATCH 3/8] Fix cache directory check for version-specific downloads Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> --- src/Context/FeatureContext.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Context/FeatureContext.php b/src/Context/FeatureContext.php index 6386e544d..0667d49c1 100644 --- a/src/Context/FeatureContext.php +++ b/src/Context/FeatureContext.php @@ -1288,9 +1288,14 @@ public function add_line_to_wp_config( &$wp_config_code, $line ): void { /** * @param string $subdir + * @param string $version */ public function download_wp( $subdir = '', $version = '' ): void { - if ( ! self::$cache_dir ) { + $wp_version = $version ?: getenv( 'WP_VERSION' ); + $wp_version_suffix = ( false !== $wp_version && '' !== $wp_version ) ? "-$wp_version" : ''; + $expected_cache_dir = sys_get_temp_dir() . '/wp-cli-test-core-download-cache' . $wp_version_suffix; + + if ( ! self::$cache_dir || self::$cache_dir !== $expected_cache_dir ) { self::cache_wp_files( $version ); $result = Process::create( Utils\esc_cmd( 'wp core version --debug --path=%s', self::$cache_dir ), null, self::get_process_env_variables() )->run_check(); From 6dc669ad9f6e8ed7253e60ab4a30c8c76cdde721 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 6 Nov 2025 09:56:40 +0000 Subject: [PATCH 4/8] Simplify version suffix logic Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> --- src/Context/FeatureContext.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Context/FeatureContext.php b/src/Context/FeatureContext.php index 0667d49c1..259b405d0 100644 --- a/src/Context/FeatureContext.php +++ b/src/Context/FeatureContext.php @@ -624,7 +624,7 @@ private static function configure_sqlite( $dir ): void { */ private static function cache_wp_files( $version = '' ): void { $wp_version = $version ?: getenv( 'WP_VERSION' ); - $wp_version_suffix = ( false !== $wp_version && '' !== $wp_version ) ? "-$wp_version" : ''; + $wp_version_suffix = $wp_version ? "-$wp_version" : ''; self::$cache_dir = sys_get_temp_dir() . '/wp-cli-test-core-download-cache' . $wp_version_suffix; self::$sqlite_cache_dir = sys_get_temp_dir() . '/wp-cli-test-sqlite-integration-cache'; @@ -1292,7 +1292,7 @@ public function add_line_to_wp_config( &$wp_config_code, $line ): void { */ public function download_wp( $subdir = '', $version = '' ): void { $wp_version = $version ?: getenv( 'WP_VERSION' ); - $wp_version_suffix = ( false !== $wp_version && '' !== $wp_version ) ? "-$wp_version" : ''; + $wp_version_suffix = $wp_version ? "-$wp_version" : ''; $expected_cache_dir = sys_get_temp_dir() . '/wp-cli-test-core-download-cache' . $wp_version_suffix; if ( ! self::$cache_dir || self::$cache_dir !== $expected_cache_dir ) { @@ -1374,7 +1374,7 @@ public function create_config( $subdir = '', $extra_php = false ): void { */ public function install_wp( $subdir = '', $version = '' ): void { $wp_version = $version ?: getenv( 'WP_VERSION' ); - $wp_version_suffix = ( false !== $wp_version && '' !== $wp_version ) ? "-$wp_version" : ''; + $wp_version_suffix = $wp_version ? "-$wp_version" : ''; self::$install_cache_dir = sys_get_temp_dir() . '/wp-cli-test-core-install-cache' . $wp_version_suffix; if ( ! file_exists( self::$install_cache_dir ) ) { mkdir( self::$install_cache_dir ); From 327e63b1a1e378fc97357f8c7256289838e2ebbd Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 6 Nov 2025 11:13:24 +0000 Subject: [PATCH 5/8] Use natural syntax for version-specific WP installation steps Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> --- features/testing.feature | 4 +- src/Context/GivenStepDefinitions.php | 58 ++++++---------------------- 2 files changed, 14 insertions(+), 48 deletions(-) diff --git a/features/testing.feature b/features/testing.feature index 51e0b3841..47b0377dd 100644 --- a/features/testing.feature +++ b/features/testing.feature @@ -64,7 +64,7 @@ Feature: Test that WP-CLI loads. """ Scenario: WP installation with specific version - Given a WP installation with version "6.4.2" + Given a WP 6.4.2 installation When I run `wp core version` Then STDOUT should be: @@ -73,7 +73,7 @@ Feature: Test that WP-CLI loads. """ Scenario: WP installation in subdirectory with specific version - Given a WP installation in 'wordpress' with version "6.3.1" + Given a WP 6.3.1 installation in 'wordpress' When I run `wp core version --path=wordpress` Then STDOUT should be: diff --git a/src/Context/GivenStepDefinitions.php b/src/Context/GivenStepDefinitions.php index de520a98b..ec80426c6 100644 --- a/src/Context/GivenStepDefinitions.php +++ b/src/Context/GivenStepDefinitions.php @@ -391,36 +391,20 @@ public function given_a_database(): void { * Scenario: My other scenario * Given a WP install * ... - * ``` - * - * @access public - * - * @Given a WP install(ation) - */ - public function given_a_wp_installation(): void { - $this->install_wp(); - } - - /** - * Installs WordPress with a specific version. - * - * ``` - * Scenario: My example scenario - * Given a WP installation with version "6.4.2" - * ... * - * Scenario: My other scenario - * Given a WP install with version "6.3.1" + * Scenario: My version-specific scenario + * Given a WP 6.4.2 installation * ... * ``` * * @access public * - * @Given a WP install(ation) with version :version + * @Given /^a WP( ([^\s]+))? install(?:ation)?$/ * - * @param string $version + * @param string $version_with_space Optional version with leading space + * @param string $version Optional version number */ - public function given_a_wp_installation_with_version( $version ): void { + public function given_a_wp_installation( $version_with_space = '', $version = '' ): void { $this->install_wp( '', $version ); } @@ -435,39 +419,21 @@ public function given_a_wp_installation_with_version( $version ): void { * Scenario: My other scenario * Given a WP install in 'bar' * ... - * ``` * - * @access public - * - * @Given a WP install(ation) in :subdir - * - * @param string $subdir - */ - public function given_a_wp_installation_in_a_specific_folder( $subdir ): void { - $this->install_wp( $subdir ); - } - - /** - * Installs WordPress in a given directory with a specific version. - * - * ``` - * Scenario: My example scenario - * Given a WP installation in 'foo' with version "6.4.2" - * ... - * - * Scenario: My other scenario - * Given a WP install in 'bar' with version "6.3.1" + * Scenario: My version-specific scenario + * Given a WP 6.4.2 installation in 'wordpress' * ... * ``` * * @access public * - * @Given a WP install(ation) in :subdir with version :version + * @Given /^a WP( ([^\s]+))? install(?:ation)? in ['"]?([^'"]+)['"]?$/ * + * @param string $version_with_space Optional version with leading space + * @param string $version Optional version number * @param string $subdir - * @param string $version */ - public function given_a_wp_installation_in_a_specific_folder_with_version( $subdir, $version ): void { + public function given_a_wp_installation_in_a_specific_folder( $version_with_space = '', $version = '', $subdir = '' ): void { $this->install_wp( $subdir, $version ); } From b5838b8848709b7efd881aaa0b01b972ed728269 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 6 Nov 2025 13:25:19 +0000 Subject: [PATCH 6/8] Simplify regex to use single capture group with trim() Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> --- src/Context/GivenStepDefinitions.php | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/Context/GivenStepDefinitions.php b/src/Context/GivenStepDefinitions.php index ec80426c6..371fe39ca 100644 --- a/src/Context/GivenStepDefinitions.php +++ b/src/Context/GivenStepDefinitions.php @@ -399,13 +399,12 @@ public function given_a_database(): void { * * @access public * - * @Given /^a WP( ([^\s]+))? install(?:ation)?$/ + * @Given /^a WP( [^\s]+)? install(?:ation)?$/ * - * @param string $version_with_space Optional version with leading space - * @param string $version Optional version number + * @param string $version Optional version number (may include leading space) */ - public function given_a_wp_installation( $version_with_space = '', $version = '' ): void { - $this->install_wp( '', $version ); + public function given_a_wp_installation( $version = '' ): void { + $this->install_wp( '', trim( $version ) ); } /** @@ -427,14 +426,13 @@ public function given_a_wp_installation( $version_with_space = '', $version = '' * * @access public * - * @Given /^a WP( ([^\s]+))? install(?:ation)? in ['"]?([^'"]+)['"]?$/ + * @Given /^a WP( [^\s]+)? install(?:ation)? in ['"]?([^'"]+)['"]?$/ * - * @param string $version_with_space Optional version with leading space - * @param string $version Optional version number + * @param string $version Optional version number (may include leading space) * @param string $subdir */ - public function given_a_wp_installation_in_a_specific_folder( $version_with_space = '', $version = '', $subdir = '' ): void { - $this->install_wp( $subdir, $version ); + public function given_a_wp_installation_in_a_specific_folder( $version = '', $subdir = '' ): void { + $this->install_wp( $subdir, trim( $version ) ); } /** From 3c6103523f6d77f8713e679b8ae5c9925168fe42 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Thu, 6 Nov 2025 21:42:09 +0100 Subject: [PATCH 7/8] Lint fixes --- src/Context/FeatureContext.php | 4 ++-- src/Context/GivenStepDefinitions.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Context/FeatureContext.php b/src/Context/FeatureContext.php index 259b405d0..cdb9df1c1 100644 --- a/src/Context/FeatureContext.php +++ b/src/Context/FeatureContext.php @@ -1291,8 +1291,8 @@ public function add_line_to_wp_config( &$wp_config_code, $line ): void { * @param string $version */ public function download_wp( $subdir = '', $version = '' ): void { - $wp_version = $version ?: getenv( 'WP_VERSION' ); - $wp_version_suffix = $wp_version ? "-$wp_version" : ''; + $wp_version = $version ?: getenv( 'WP_VERSION' ); + $wp_version_suffix = $wp_version ? "-$wp_version" : ''; $expected_cache_dir = sys_get_temp_dir() . '/wp-cli-test-core-download-cache' . $wp_version_suffix; if ( ! self::$cache_dir || self::$cache_dir !== $expected_cache_dir ) { diff --git a/src/Context/GivenStepDefinitions.php b/src/Context/GivenStepDefinitions.php index 371fe39ca..6321bf235 100644 --- a/src/Context/GivenStepDefinitions.php +++ b/src/Context/GivenStepDefinitions.php @@ -420,7 +420,7 @@ public function given_a_wp_installation( $version = '' ): void { * ... * * Scenario: My version-specific scenario - * Given a WP 6.4.2 installation in 'wordpress' + * Given a WP 6.4.2 installation in 'subdir' * ... * ``` * From 29b8d54d7c1cd30f45872e709a3433b117cf7161 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Thu, 6 Nov 2025 21:45:50 +0100 Subject: [PATCH 8/8] PHPStan fix --- src/Context/FeatureContext.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Context/FeatureContext.php b/src/Context/FeatureContext.php index cdb9df1c1..7cff16319 100644 --- a/src/Context/FeatureContext.php +++ b/src/Context/FeatureContext.php @@ -621,6 +621,8 @@ private static function configure_sqlite( $dir ): void { /** * We cache the results of `wp core download` to improve test performance. * Ideally, we'd cache at the HTTP layer for more reliable tests. + * + * @param string $version */ private static function cache_wp_files( $version = '' ): void { $wp_version = $version ?: getenv( 'WP_VERSION' );