From 4f2c4528a4a50e412e54ce8fad2ffd1e51b0f7bd Mon Sep 17 00:00:00 2001 From: Samuel Stancl Date: Sun, 28 Jun 2026 18:42:45 -0700 Subject: [PATCH] simplify ENV manipulation code in test --- tests/CommandsTest.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/tests/CommandsTest.php b/tests/CommandsTest.php index f1bea31a..8d050b96 100644 --- a/tests/CommandsTest.php +++ b/tests/CommandsTest.php @@ -370,22 +370,22 @@ test('migrate fresh command only shows migration output when run with the verbos $tenant = Tenant::create(); $migratingOutput = 'Migrating tenant ' . $tenant->getTenantKey(); - // CI runs pest with -v, setting SHELL_VERBOSITY to 1, so in CI, the output is verbose by default - $shellVerbosity = getenv('SHELL_VERBOSITY'); - $_ENV['SHELL_VERBOSITY'] = $_SERVER['SHELL_VERBOSITY'] = 0; - putenv('SHELL_VERBOSITY=0'); - + // CI runs pest with --verbose which makes Artisan::call() inherit the verbosity + // so we cannot easily test commands without -v. To work around that, we temporarily + // override $_ENV['SHELL_VERBOSITY'] immediately before executing the command. If this + // ever stops working, try also overriding the value in $_SERVER and putenv(). + $originalVerbosity = $_ENV['SHELL_VERBOSITY'] ?? 0; try { + $_ENV['SHELL_VERBOSITY'] = 0; Artisan::call('tenants:migrate-fresh'); $defaultOutput = Artisan::output(); - - Artisan::call('tenants:migrate-fresh -v'); - $verboseOutput = Artisan::output(); } finally { - unset($_ENV['SHELL_VERBOSITY'], $_SERVER['SHELL_VERBOSITY']); - $shellVerbosity === false ? putenv('SHELL_VERBOSITY') : putenv("SHELL_VERBOSITY=$shellVerbosity"); + $_ENV['SHELL_VERBOSITY'] = $originalVerbosity; } + Artisan::call('tenants:migrate-fresh -v'); + $verboseOutput = Artisan::output(); + // The output is silent by default and only shown with the verbose option expect($defaultOutput)->not()->toContain($migratingOutput); expect($verboseOutput)->toContain($migratingOutput);