Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions features/testing.feature
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,21 @@ Feature: Test that WP-CLI loads.
"""
sqlite
"""

Scenario: WP installation with specific version
Given a WP 6.4.2 installation

When I run `wp core version`
Then STDOUT should be:
"""
6.4.2
"""

Scenario: WP installation in subdirectory with specific version
Given a WP 6.3.1 installation in 'wordpress'

When I run `wp core version --path=wordpress`
Then STDOUT should be:
"""
6.3.1
"""
28 changes: 18 additions & 10 deletions src/Context/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -621,10 +621,12 @@ 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(): 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 = $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';

Expand Down Expand Up @@ -1288,10 +1290,15 @@ public function add_line_to_wp_config( &$wp_config_code, $line ): void {

/**
* @param string $subdir
* @param string $version
*/
public function download_wp( $subdir = '' ): void {
if ( ! self::$cache_dir ) {
self::cache_wp_files();
public function download_wp( $subdir = '', $version = '' ): void {
$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 ) {
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";
Expand Down Expand Up @@ -1365,10 +1372,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 = $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 );
Expand All @@ -1383,7 +1391,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 = [
Expand Down
23 changes: 17 additions & 6 deletions src/Context/GivenStepDefinitions.php
Original file line number Diff line number Diff line change
Expand Up @@ -391,14 +391,20 @@ public function given_a_database(): void {
* Scenario: My other scenario
* Given a WP install
* ...
*
* Scenario: My version-specific scenario
* Given a WP 6.4.2 installation
* ...
* ```
*
* @access public
*
* @Given a WP install(ation)
* @Given /^a WP( [^\s]+)? install(?:ation)?$/
*
* @param string $version Optional version number (may include leading space)
*/
public function given_a_wp_installation(): void {
$this->install_wp();
public function given_a_wp_installation( $version = '' ): void {
$this->install_wp( '', trim( $version ) );
}

/**
Expand All @@ -412,16 +418,21 @@ public function given_a_wp_installation(): void {
* Scenario: My other scenario
* Given a WP install in 'bar'
* ...
*
* Scenario: My version-specific scenario
* Given a WP 6.4.2 installation in 'subdir'
* ...
* ```
*
* @access public
*
* @Given a WP install(ation) in :subdir
* @Given /^a WP( [^\s]+)? install(?:ation)? in ['"]?([^'"]+)['"]?$/
*
* @param string $version Optional version number (may include leading space)
* @param string $subdir
*/
public function given_a_wp_installation_in_a_specific_folder( $subdir ): void {
$this->install_wp( $subdir );
public function given_a_wp_installation_in_a_specific_folder( $version = '', $subdir = '' ): void {
$this->install_wp( $subdir, trim( $version ) );
}

/**
Expand Down
Loading