diff --git a/.harness.json b/.harness.json index 261b5b7..40874b2 100644 --- a/.harness.json +++ b/.harness.json @@ -5,22 +5,13 @@ "laravel/prompts" ], "allow_commands": [ - { - "command": "new", - "reason": "the installer is named for the tool, like laravel new; renaming it would change the public API of the CLI" - }, - { - "command": "self-update", - "reason": "the command is named for the tool, like composer self-update; renaming it would change the public API of the CLI" - }, - { - "command": "version", - "reason": "the command is named for the tool; renaming it would change the public API of the CLI" - } + { "command": "new", "reason": "the installer is named for the tool, like laravel new; renaming it would change the public API of the CLI" }, + { "command": "self-update", "reason": "the command is named for the tool, like composer self-update; renaming it would change the public API of the CLI" }, + { "command": "version", "reason": "the command is named for the tool; renaming it would change the public API of the CLI" } ], "ratchet": { "phpstan_level": 8, "phpstan_baseline": 0, - "coverage": 36.86 + "coverage": 92 } } diff --git a/tests/Support/Sandbox.php b/tests/Support/Sandbox.php index 27f779a..9541f38 100644 --- a/tests/Support/Sandbox.php +++ b/tests/Support/Sandbox.php @@ -29,6 +29,9 @@ final class Sandbox /** @var array */ private array $originalServer = []; + /** @var array */ + private array $originalSuperEnv = []; + public function __construct() { $this->root = realpath(sys_get_temp_dir()).'/pollora-cli-'.bin2hex(random_bytes(6)); @@ -61,9 +64,16 @@ public function env(string $name, string $value): void $this->originalServer[$name] = $_SERVER[$name] ?? null; } - // Symfony Process only passes on the variables that $_SERVER also knows. + if (! array_key_exists($name, $this->originalSuperEnv)) { + $this->originalSuperEnv[$name] = $_ENV[$name] ?? null; + } + + // Symfony Process builds the environment of a child from the variables that $_SERVER also knows, + // then lets $_ENV override them: $_ENV is empty with the php.ini of macOS (variables_order GPCS) + // and filled on Linux, where it would bring back the original PATH. Both are set. putenv($name.'='.$value); $_SERVER[$name] = $value; + $_ENV[$name] = $value; } /** @@ -129,6 +139,14 @@ public function restore(): void } } + foreach ($this->originalSuperEnv as $name => $value) { + if ($value === null) { + unset($_ENV[$name]); + } else { + $_ENV[$name] = $value; + } + } + self::removeTree($this->root); }