Skip to content
Merged
Show file tree
Hide file tree
Changes from 16 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
8 changes: 8 additions & 0 deletions features/testing.feature
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,11 @@ Feature: Test that WP-CLI loads.
This should only run on MySQL or MariaDB
"""

Scenario: Verify sys_get_temp_dir() in sub-process
Given a WP install
When I run `wp eval 'echo sys_get_temp_dir();'`
Then STDOUT should not contain:
"""
C:\Windows
Comment thread
swissspidy marked this conversation as resolved.
Outdated
"""
Comment thread
swissspidy marked this conversation as resolved.
Outdated

43 changes: 35 additions & 8 deletions src/Context/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,13 @@ private static function get_process_env_variables(): array {

$env = array_merge( $_ENV, $env );

foreach ( [ 'TEMP', 'TMP', 'SystemRoot', 'windir' ] as $key ) {
$value = getenv( $key );
if ( false !== $value ) {
$env[ $key ] = $value;
}
}

if ( self::running_with_code_coverage() ) {
$has_coverage_driver = ( new Runtime() )->hasXdebug() || ( new Runtime() )->hasPCOV();

Expand Down Expand Up @@ -683,7 +690,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 = $wp_version ? "-$wp_version" : '';
self::$cache_dir = sys_get_temp_dir() . '/wp-cli-test-core-download-cache' . $wp_version_suffix;
$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';

if ( 'sqlite' === getenv( 'WP_CLI_TEST_DBTYPE' ) ) {
Expand All @@ -699,15 +706,34 @@ private static function cache_wp_files( $version = '' ): void {
}
}

if ( is_readable( self::$cache_dir . '/wp-config-sample.php' ) ) {
if ( is_readable( $cache_dir . '/wp-includes/version.php' ) ) {
self::$cache_dir = $cache_dir;
return;
}

$cmd = Utils\esc_cmd( 'wp core download --force --path=%s', self::$cache_dir );
$cmd = Utils\esc_cmd( 'wp core download --force --path=%s', $cache_dir );
if ( $wp_version ) {
$cmd .= Utils\esc_cmd( ' --version=%s', $wp_version );
}
Process::create( $cmd, null, self::get_process_env_variables() )->run_check();

$max_retries = 3;
$retry_count = 0;
$completed = false;

// This is in addition to the retry logic inside Utils\http_request().
while ( $retry_count < $max_retries && ! $completed ) {
try {
Process::create( $cmd, null, self::get_process_env_variables() )->run_check();
$completed = true;
} catch ( \Exception $e ) {
++$retry_count;
if ( $retry_count >= $max_retries ) {
throw $e;
}
}
}

self::$cache_dir = $cache_dir;
}

/**
Expand Down Expand Up @@ -1183,9 +1209,10 @@ private static function get_event_file( $scope, &$line ): ?string {
*/
public function create_run_dir(): void {
if ( ! isset( $this->variables['RUN_DIR'] ) ) {
self::$run_dir = sys_get_temp_dir() . DIRECTORY_SEPARATOR . uniqid( 'wp-cli-test-run-' . self::$temp_dir_infix . '-', true );
$temp_run_dir = sys_get_temp_dir() . DIRECTORY_SEPARATOR . uniqid( 'wp-cli-test-run-' . self::$temp_dir_infix . '-', true );
mkdir( $temp_run_dir );
self::$run_dir = $temp_run_dir;
$this->variables['RUN_DIR'] = self::$run_dir;
mkdir( $this->variables['RUN_DIR'] );
}
}

Expand Down Expand Up @@ -1525,7 +1552,7 @@ public static function copy_dir( $src_dir, $dest_dir ): void {
* @var \SplFileInfo $item
*/
foreach ( $iterator as $item ) {
$dest_path = $dest_dir . '/' . $iterator->getSubPathname();
$dest_path = rtrim( $dest_dir, '/\\' ) . DIRECTORY_SEPARATOR . $iterator->getSubPathname();
if ( $item->isDir() ) {
if ( ! is_dir( $dest_path ) ) {
mkdir( $dest_path, 0777, true );
Expand Down Expand Up @@ -1565,7 +1592,7 @@ public function download_wp( $subdir = '', $version = '' ): void {
echo "WordPress {$result->stdout}\n";
}

$dest_dir = $this->variables['RUN_DIR'] . "/$subdir";
$dest_dir = rtrim( $this->variables['RUN_DIR'], '/\\' ) . ( $subdir ? DIRECTORY_SEPARATOR . $subdir : '' );

if ( $subdir ) {
mkdir( $dest_dir, 0777, true /*recursive*/ );
Expand Down