Skip to content

Commit 425513c

Browse files
authored
Merge pull request #109 from wp-cli/fix/adapt-bin-path-on-framework
2 parents 0264f85 + 147dc27 commit 425513c

File tree

1 file changed

+37
-3
lines changed

1 file changed

+37
-3
lines changed

src/Context/FeatureContext.php

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,20 +160,54 @@ public static function get_framework_dir() {
160160
return $framework_folder;
161161
}
162162

163+
164+
/**
165+
* Get the path to the WP-CLI binary.
166+
*
167+
* @return string Absolute path to the WP-CLI binary.
168+
*/
169+
public static function get_bin_path() {
170+
static $bin_path = null;
171+
172+
if ( null !== $bin_path ) {
173+
return $bin_path;
174+
}
175+
176+
$bin_path = getenv( 'WP_CLI_BIN_DIR' );
177+
178+
if ( ! empty( $bin_path ) ) {
179+
return $bin_path;
180+
}
181+
182+
$bin_paths = [
183+
self::get_vendor_dir() . '/bin',
184+
self::get_framework_dir() . '/bin',
185+
];
186+
187+
foreach ( $bin_paths as $path ) {
188+
if ( is_file( "{$path}/wp" ) && is_executable( "{$path}/wp" ) ) {
189+
$bin_path = $path;
190+
break;
191+
}
192+
}
193+
194+
return $bin_path;
195+
}
196+
163197
/**
164198
* Get the environment variables required for launched `wp` processes
165199
*/
166200
private static function get_process_env_variables() {
167201
// Ensure we're using the expected `wp` binary.
168-
$bin_path = getenv( 'WP_CLI_BIN_DIR' ) ?: realpath( self::get_vendor_dir() . '/bin' );
202+
$bin_path = self::get_bin_path();
169203
wp_cli_behat_env_debug( "WP-CLI binary path: {$bin_path}" );
170204

171205
if ( ! file_exists( "{$bin_path}/wp" ) ) {
172-
wp_cli_behat_env_debug( "WARNING: No file named 'wp' found in the provided/detected path." );
206+
wp_cli_behat_env_debug( "WARNING: No file named 'wp' found in the provided/detected binary path." );
173207
}
174208

175209
if ( ! is_executable( "{$bin_path}/wp" ) ) {
176-
wp_cli_behat_env_debug( "WARNING: File named 'wp' found in the provided/detected path is not executable." );
210+
wp_cli_behat_env_debug( "WARNING: File named 'wp' found in the provided/detected binary path is not executable." );
177211
}
178212

179213
$path_separator = Utils\is_windows() ? ';' : ':';

0 commit comments

Comments
 (0)