@@ -406,10 +406,28 @@ public static function get_bin_path(): ?string {
406406 self ::get_framework_dir () . '/bin ' ,
407407 ];
408408
409- foreach ( $ bin_paths as $ path ) {
410- if ( is_file ( "{$ path }/wp " ) && is_executable ( "{$ path }/wp " ) ) {
411- $ bin_path = $ path ;
412- break ;
409+ if ( Utils \is_windows () ) {
410+ foreach ( $ bin_paths as $ path ) {
411+ $ wp_script_path = $ path . DIRECTORY_SEPARATOR . 'wp ' ;
412+ $ wp_bat_path = $ path . DIRECTORY_SEPARATOR . 'wp.bat ' ;
413+
414+ if ( is_file ( $ wp_script_path ) ) {
415+ if ( ! is_file ( $ wp_bat_path ) ) {
416+ $ bat_content = '@ECHO OFF ' . PHP_EOL ;
417+ $ bat_content .= 'php " ' . realpath ( $ wp_script_path ) . '" %* ' ;
418+ file_put_contents ( $ wp_bat_path , $ bat_content );
419+ }
420+ $ bin_path = $ path ;
421+ break ;
422+ }
423+ }
424+ } else {
425+ foreach ( $ bin_paths as $ path ) {
426+ $ full_bin_path = $ path . DIRECTORY_SEPARATOR . 'wp ' ;
427+ if ( is_file ( $ full_bin_path ) && is_executable ( $ full_bin_path ) ) {
428+ $ bin_path = $ path ;
429+ break ;
430+ }
413431 }
414432 }
415433
@@ -430,14 +448,21 @@ private static function get_process_env_variables(): array {
430448
431449 // Ensure we're using the expected `wp` binary.
432450 $ bin_path = self ::get_bin_path ();
451+
452+ if ( ! $ bin_path ) {
453+ throw new RuntimeException ( 'Could not find WP-CLI binary path. ' );
454+ }
455+
433456 wp_cli_behat_env_debug ( "WP-CLI binary path: {$ bin_path }" );
434457
435- if ( ! file_exists ( "{$ bin_path }/wp " ) ) {
436- wp_cli_behat_env_debug ( "WARNING: No file named 'wp' found in the provided/detected binary path. " );
458+ $ executable = Utils \is_windows () ? $ bin_path . DIRECTORY_SEPARATOR . 'wp.bat ' : $ bin_path . DIRECTORY_SEPARATOR . 'wp ' ;
459+
460+ if ( ! file_exists ( $ executable ) ) {
461+ wp_cli_behat_env_debug ( "WARNING: File $ executable not found. " );
437462 }
438463
439- if ( ! is_executable ( "{ $ bin_path } /wp " ) ) {
440- wp_cli_behat_env_debug ( "WARNING: File named 'wp' found in the provided/detected binary path is not executable. " );
464+ if ( ! is_executable ( $ executable ) ) {
465+ wp_cli_behat_env_debug ( "WARNING: File $ executable is not executable. " );
441466 }
442467
443468 $ path_separator = Utils \is_windows () ? '; ' : ': ' ;
0 commit comments