Skip to content

Commit dddbb7a

Browse files
committed
Merge branch 'main' into try/os
2 parents d155f32 + 77d4758 commit dddbb7a

File tree

3 files changed

+53
-16
lines changed

3 files changed

+53
-16
lines changed

features/testing.feature

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,21 @@ Feature: Test that WP-CLI loads.
6666
"""
6767
sqlite
6868
"""
69+
70+
Scenario: WP installation with specific version
71+
Given a WP 6.4.2 installation
72+
73+
When I run `wp core version`
74+
Then STDOUT should be:
75+
"""
76+
6.4.2
77+
"""
78+
79+
Scenario: WP installation in subdirectory with specific version
80+
Given a WP 6.3.1 installation in 'wordpress'
81+
82+
When I run `wp core version --path=wordpress`
83+
Then STDOUT should be:
84+
"""
85+
6.3.1
86+
"""

src/Context/FeatureContext.php

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -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 = [

src/Context/GivenStepDefinitions.php

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -391,14 +391,20 @@ public function given_a_database(): void {
391391
* Scenario: My other scenario
392392
* Given a WP install
393393
* ...
394+
*
395+
* Scenario: My version-specific scenario
396+
* Given a WP 6.4.2 installation
397+
* ...
394398
* ```
395399
*
396400
* @access public
397401
*
398-
* @Given a WP install(ation)
402+
* @Given /^a WP( [^\s]+)? install(?:ation)?$/
403+
*
404+
* @param string $version Optional version number (may include leading space)
399405
*/
400-
public function given_a_wp_installation(): void {
401-
$this->install_wp();
406+
public function given_a_wp_installation( $version = '' ): void {
407+
$this->install_wp( '', trim( $version ) );
402408
}
403409

404410
/**
@@ -412,16 +418,21 @@ public function given_a_wp_installation(): void {
412418
* Scenario: My other scenario
413419
* Given a WP install in 'bar'
414420
* ...
421+
*
422+
* Scenario: My version-specific scenario
423+
* Given a WP 6.4.2 installation in 'subdir'
424+
* ...
415425
* ```
416426
*
417427
* @access public
418428
*
419-
* @Given a WP install(ation) in :subdir
429+
* @Given /^a WP( [^\s]+)? install(?:ation)? in ['"]?([^'"]+)['"]?$/
420430
*
431+
* @param string $version Optional version number (may include leading space)
421432
* @param string $subdir
422433
*/
423-
public function given_a_wp_installation_in_a_specific_folder( $subdir ): void {
424-
$this->install_wp( $subdir );
434+
public function given_a_wp_installation_in_a_specific_folder( $version = '', $subdir = '' ): void {
435+
$this->install_wp( $subdir, trim( $version ) );
425436
}
426437

427438
/**

0 commit comments

Comments
 (0)