Skip to content

Commit dc3296a

Browse files
committed
AI fixes
1 parent 8da6b94 commit dc3296a

File tree

3 files changed

+16
-26
lines changed

3 files changed

+16
-26
lines changed

src/Context/FeatureContext.php

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -405,26 +405,12 @@ public static function get_bin_path(): ?string {
405405
self::get_framework_dir() . DIRECTORY_SEPARATOR . 'bin',
406406
];
407407

408-
if ( Utils\is_windows() ) {
409-
foreach ( $bin_paths as $path ) {
410-
$wp_script_path = $path . DIRECTORY_SEPARATOR . 'wp';
411-
if ( is_file( $wp_script_path ) ) {
412-
$wp_bat_path = $path . DIRECTORY_SEPARATOR . 'wp.bat';
413-
if ( ! is_file( $wp_bat_path ) ) {
414-
$bat_content = '@ECHO OFF' . PHP_EOL;
415-
// Use the currently running PHP executable to avoid PATH issues.
416-
$bat_content .= '"' . PHP_BINARY . '" "' . realpath( $wp_script_path ) . '" %*';
417-
file_put_contents( $wp_bat_path, $bat_content );
418-
}
419-
return $path;
420-
}
421-
}
422-
} else {
423-
foreach ( $bin_paths as $path ) {
424-
$full_bin_path = $path . DIRECTORY_SEPARATOR . 'wp';
425-
if ( is_file( $full_bin_path ) && is_executable( $full_bin_path ) ) {
426-
return $path;
427-
}
408+
$bin = Utils\is_windows() ? 'wp.bat' : 'wp';
409+
410+
foreach ( $bin_paths as $path ) {
411+
$full_bin_path = $path . DIRECTORY_SEPARATOR . $bin;
412+
if ( is_file( $full_bin_path ) && ( Utils\is_windows() || is_executable( $full_bin_path ) ) ) {
413+
return $path;
428414
}
429415
}
430416

@@ -684,6 +670,10 @@ public static function prepare( BeforeSuiteScope $scope ): void {
684670
if ( file_exists( $install_cache_dir ) ) {
685671
self::remove_dir( $install_cache_dir );
686672
}
673+
674+
if ( getenv( 'WP_CLI_TEST_DEBUG_BEHAT_ENV' ) ) {
675+
exit;
676+
}
687677
}
688678

689679
/**
@@ -1847,9 +1837,6 @@ private static function log_proc_method_run_time( $key, $start_time ): void {
18471837
* @param string $message
18481838
*/
18491839
function wp_cli_behat_env_debug( $message ): void { // phpcs:ignore Universal.Files.SeparateFunctionsFromOO.Mixed
1850-
// Always print the message to STDERR for debugging purposes.
1851-
fwrite( STDERR, "{$message}\n" );
1852-
18531840
if ( ! getenv( 'WP_CLI_TEST_DEBUG_BEHAT_ENV' ) ) {
18541841
return;
18551842
}

src/Context/Process.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public function run() {
8282
1 => [ 'file', $stdout_file, 'a' ],
8383
2 => [ 'file', $stderr_file, 'a' ],
8484
];
85-
$proc = \WP_CLI\Utils\proc_open_compat( $this->command, $descriptors, $pipes, $this->cwd, $this->env );
85+
$proc = \WP_CLI\Utils\proc_open_compat( $this->command, $descriptors, $pipes, $this->cwd, $this->env );
8686
fclose( $pipes[0] );
8787
} else {
8888
$proc = \WP_CLI\Utils\proc_open_compat( $this->command, self::$descriptors, $pipes, $this->cwd, $this->env );

tests/tests/TestBehatTags.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,10 +225,13 @@ public function test_behat_tags_extension(): void {
225225
break;
226226
}
227227

228-
if ( ! extension_loaded( 'imagick' ) ) {
228+
// Check which extensions are loaded in the clean `php -n` environment to build the correct expectation.
229+
$imagick_loaded_in_script = (bool) exec( escapeshellarg( PHP_BINARY ) . ' -n -r "echo (int)extension_loaded(\'imagick\');"' );
230+
if ( ! $imagick_loaded_in_script ) {
229231
$expecteds[] = '~@require-extension-imagick';
230232
}
231-
if ( ! extension_loaded( 'curl' ) ) {
233+
$curl_loaded_in_script = (bool) exec( escapeshellarg( PHP_BINARY ) . ' -n -r "echo (int)extension_loaded(\'curl\');"' );
234+
if ( ! $curl_loaded_in_script ) {
232235
$expecteds[] = '~@require-extension-curl';
233236
}
234237

0 commit comments

Comments
 (0)