Skip to content

Commit e7d467f

Browse files
Copilotswissspidy
andcommitted
Add WP installation with version step
Co-authored-by: swissspidy <[email protected]>
1 parent 62d0ab5 commit e7d467f

File tree

3 files changed

+75
-9
lines changed

3 files changed

+75
-9
lines changed

features/testing.feature

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

src/Context/FeatureContext.php

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -622,9 +622,9 @@ private static function configure_sqlite( $dir ): void {
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.
624624
*/
625-
private static function cache_wp_files(): void {
626-
$wp_version = getenv( 'WP_VERSION' );
627-
$wp_version_suffix = ( false !== $wp_version ) ? "-$wp_version" : '';
625+
private static function cache_wp_files( $version = '' ): void {
626+
$wp_version = $version ?: getenv( 'WP_VERSION' );
627+
$wp_version_suffix = ( false !== $wp_version && '' !== $wp_version ) ? "-$wp_version" : '';
628628
self::$cache_dir = sys_get_temp_dir() . '/wp-cli-test-core-download-cache' . $wp_version_suffix;
629629
self::$sqlite_cache_dir = sys_get_temp_dir() . '/wp-cli-test-sqlite-integration-cache';
630630

@@ -1289,9 +1289,9 @@ public function add_line_to_wp_config( &$wp_config_code, $line ): void {
12891289
/**
12901290
* @param string $subdir
12911291
*/
1292-
public function download_wp( $subdir = '' ): void {
1292+
public function download_wp( $subdir = '', $version = '' ): void {
12931293
if ( ! self::$cache_dir ) {
1294-
self::cache_wp_files();
1294+
self::cache_wp_files( $version );
12951295

12961296
$result = Process::create( Utils\esc_cmd( 'wp core version --debug --path=%s', self::$cache_dir ), null, self::get_process_env_variables() )->run_check();
12971297
echo "[Debug messages]\n";
@@ -1365,10 +1365,11 @@ public function create_config( $subdir = '', $extra_php = false ): void {
13651365

13661366
/**
13671367
* @param string $subdir
1368+
* @param string $version
13681369
*/
1369-
public function install_wp( $subdir = '' ): void {
1370-
$wp_version = getenv( 'WP_VERSION' );
1371-
$wp_version_suffix = ( false !== $wp_version ) ? "-$wp_version" : '';
1370+
public function install_wp( $subdir = '', $version = '' ): void {
1371+
$wp_version = $version ?: getenv( 'WP_VERSION' );
1372+
$wp_version_suffix = ( false !== $wp_version && '' !== $wp_version ) ? "-$wp_version" : '';
13721373
self::$install_cache_dir = sys_get_temp_dir() . '/wp-cli-test-core-install-cache' . $wp_version_suffix;
13731374
if ( ! file_exists( self::$install_cache_dir ) ) {
13741375
mkdir( self::$install_cache_dir );
@@ -1383,7 +1384,7 @@ public function install_wp( $subdir = '' ): void {
13831384
$this->create_db();
13841385
}
13851386
$this->create_run_dir();
1386-
$this->download_wp( $subdir );
1387+
$this->download_wp( $subdir, $version );
13871388
$this->create_config( $subdir, $config_extra_php );
13881389

13891390
$install_args = [

src/Context/GivenStepDefinitions.php

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,29 @@ public function given_a_wp_installation(): void {
401401
$this->install_wp();
402402
}
403403

404+
/**
405+
* Installs WordPress with a specific version.
406+
*
407+
* ```
408+
* Scenario: My example scenario
409+
* Given a WP installation with version "6.4.2"
410+
* ...
411+
*
412+
* Scenario: My other scenario
413+
* Given a WP install with version "6.3.1"
414+
* ...
415+
* ```
416+
*
417+
* @access public
418+
*
419+
* @Given a WP install(ation) with version :version
420+
*
421+
* @param string $version
422+
*/
423+
public function given_a_wp_installation_with_version( $version ): void {
424+
$this->install_wp( '', $version );
425+
}
426+
404427
/**
405428
* Installs WordPress in a given directory.
406429
*
@@ -424,6 +447,30 @@ public function given_a_wp_installation_in_a_specific_folder( $subdir ): void {
424447
$this->install_wp( $subdir );
425448
}
426449

450+
/**
451+
* Installs WordPress in a given directory with a specific version.
452+
*
453+
* ```
454+
* Scenario: My example scenario
455+
* Given a WP installation in 'foo' with version "6.4.2"
456+
* ...
457+
*
458+
* Scenario: My other scenario
459+
* Given a WP install in 'bar' with version "6.3.1"
460+
* ...
461+
* ```
462+
*
463+
* @access public
464+
*
465+
* @Given a WP install(ation) in :subdir with version :version
466+
*
467+
* @param string $subdir
468+
* @param string $version
469+
*/
470+
public function given_a_wp_installation_in_a_specific_folder_with_version( $subdir, $version ): void {
471+
$this->install_wp( $subdir, $version );
472+
}
473+
427474
/**
428475
* Installs WordPress with Composer.
429476
*

0 commit comments

Comments
 (0)