@@ -19,8 +19,13 @@ function sandboxSetup(): void
1919 $ sandbox = $ base . '/leaf-cli-test- ' . substr (str_shuffle ('abcdefghijklmnopqrstuvwxyz ' ), 0 , 10 );
2020
2121 mkdir ("$ sandbox/bin " , 0777 , true );
22+
23+ // shim composer on every platform: bash script for unix shells,
24+ // batch file for cmd.exe (resolved via PATHEXT)
2225 file_put_contents ("$ sandbox/bin/composer " , "#!/bin/bash \necho \"COMPOSER CALLED WITH: \$@ \"\n" );
2326 chmod ("$ sandbox/bin/composer " , 0755 );
27+ file_put_contents ("$ sandbox/bin/composer.bat " , "@echo COMPOSER CALLED WITH: %* \r\n" );
28+
2429 chdir ($ sandbox );
2530
2631 $ GLOBALS ['__cliSandbox ' ] = $ sandbox ;
@@ -58,9 +63,17 @@ function removeDirRecursive(string $dir): void
5863function leaf (string $ args ): array
5964{
6065 $ bin = dirname (__DIR__ ) . '/bin/leaf ' ;
61- $ path = $ GLOBALS ['__cliSandbox ' ] . '/bin: ' . getenv ('PATH ' );
6266
63- exec ('PATH= ' . escapeshellarg ($ path ) . ' ' . escapeshellarg (PHP_BINARY ) . ' ' . escapeshellarg ($ bin ) . " $ args 2>&1 " , $ output , $ exit );
67+ // `PATH=x cmd` prefixes are bash-only; mutate the inherited environment
68+ // instead so the shim wins on every platform, and restore it after
69+ $ originalPath = getenv ('PATH ' );
70+ putenv ('PATH= ' . $ GLOBALS ['__cliSandbox ' ] . DIRECTORY_SEPARATOR . 'bin ' . PATH_SEPARATOR . $ originalPath );
71+
72+ try {
73+ exec (escapeshellarg (PHP_BINARY ) . ' ' . escapeshellarg ($ bin ) . " $ args 2>&1 " , $ output , $ exit );
74+ } finally {
75+ putenv ("PATH= $ originalPath " );
76+ }
6477
6578 return [$ exit , implode ("\n" , $ output )];
6679}
0 commit comments