Skip to content

Commit 9b9610d

Browse files
committed
test: patch up tests for windows
1 parent 5d73585 commit 9b9610d

2 files changed

Lines changed: 19 additions & 3 deletions

File tree

tests/Pest.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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
5863
function 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
}

tests/context.test.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,10 @@
5555
// with UsersController or auth.required from later registrations
5656
$rootLine = collect_lines($output, 'GET /');
5757

58-
expect($rootLine)->not->toContain('UsersController')
58+
// positive assertion first, so an empty output fails loudly instead
59+
// of letting the not-contains checks pass vacuously
60+
expect($rootLine)->toContain('GET /')
61+
->and($rootLine)->not->toContain('UsersController')
5962
->and($rootLine)->not->toContain('auth.required');
6063
});
6164

0 commit comments

Comments
 (0)