Skip to content

Commit 8182330

Browse files
committed
More AI fixes
1 parent c1be927 commit 8182330

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

tests/tests/TestBehatTags.php

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,18 +44,25 @@ protected function tear_down(): void {
4444
private function run_behat_tags_script( $env = '' ) {
4545
$behat_tags = dirname( dirname( __DIR__ ) ) . '/utils/behat-tags.php';
4646

47+
// Use the same PHP binary that is running the tests to ensure extension consistency.
48+
$php_run = escapeshellarg( PHP_BINARY ) . ' ' . escapeshellarg( $behat_tags );
49+
50+
$command = '';
4751
if ( ! empty( $env ) ) {
48-
putenv( $env );
52+
// putenv() can be unreliable, especially on Windows.
53+
// Prepending the variable to the command is a more robust cross-platform solution.
54+
if ( Utils\is_windows() ) {
55+
// Note: `set` is internal to `cmd.exe` and works on the subsequent command after `&&`.
56+
$command = 'set ' . $env . ' && ';
57+
} else {
58+
// On Unix-like systems, this sets the variable for the duration of the command.
59+
$command = $env . ' ';
60+
}
4961
}
5062

51-
$command = 'cd ' . escapeshellarg( $this->temp_dir ) . ' && php ' . escapeshellarg( $behat_tags );
63+
$command = 'cd ' . escapeshellarg( $this->temp_dir ) . ' && ' . $command . $php_run;
5264
$output = exec( $command );
5365

54-
if ( ! empty( $env ) ) {
55-
list( $key ) = explode( '=', $env, 2 );
56-
putenv( $key ); // Unsets the variable.
57-
}
58-
5966
return $output;
6067
}
6168

0 commit comments

Comments
 (0)