File tree Expand file tree Collapse file tree 1 file changed +14
-7
lines changed
Expand file tree Collapse file tree 1 file changed +14
-7
lines changed Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments