Skip to content

Commit 70f8de0

Browse files
authored
Normalize temp dir in Given a directory step (#329)
1 parent 2cde4e3 commit 70f8de0

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

src/Context/FeatureContext.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1211,6 +1211,7 @@ public function create_run_dir(): void {
12111211
if ( ! isset( $this->variables['RUN_DIR'] ) ) {
12121212
$temp_run_dir = sys_get_temp_dir() . DIRECTORY_SEPARATOR . uniqid( 'wp-cli-test-run-' . self::$temp_dir_infix . '-', true );
12131213
mkdir( $temp_run_dir );
1214+
$temp_run_dir = realpath( $temp_run_dir ) ?: $temp_run_dir;
12141215
self::$run_dir = $temp_run_dir;
12151216
$this->variables['RUN_DIR'] = self::$run_dir;
12161217
}

src/Context/GivenStepDefinitions.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,13 @@ public function given_a_specific_directory( $empty_or_nonexistent, $dir ): void
5353
// Mac OS X can prefix the `/var` folder to turn it into `/private/var`.
5454
$dir = preg_replace( '|^/private/var/|', '/var/', $dir );
5555

56-
$temp_dir = Path::normalize( sys_get_temp_dir() );
56+
$temp_dir = realpath( sys_get_temp_dir() );
57+
$temp_dir = $temp_dir ? Path::normalize( $temp_dir ) : Path::normalize( sys_get_temp_dir() );
5758
$dir = Path::normalize( $dir );
5859

60+
// Also normalize temp dir for Mac OS X.
61+
$temp_dir = preg_replace( '|^/private/var/|', '/var/', $temp_dir );
62+
5963
// Also check for temp dir prefixed with `/private` for Mac OS X.
6064
if ( 0 !== strpos( $dir, $temp_dir ) && 0 !== strpos( $dir, "/private{$temp_dir}" ) ) {
6165
throw new RuntimeException(

0 commit comments

Comments
 (0)