Skip to content

Commit 4f2c452

Browse files
committed
simplify ENV manipulation code in test
1 parent 90ff8d7 commit 4f2c452

1 file changed

Lines changed: 10 additions & 10 deletions

File tree

tests/CommandsTest.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -370,22 +370,22 @@
370370
$tenant = Tenant::create();
371371
$migratingOutput = 'Migrating tenant ' . $tenant->getTenantKey();
372372

373-
// CI runs pest with -v, setting SHELL_VERBOSITY to 1, so in CI, the output is verbose by default
374-
$shellVerbosity = getenv('SHELL_VERBOSITY');
375-
$_ENV['SHELL_VERBOSITY'] = $_SERVER['SHELL_VERBOSITY'] = 0;
376-
putenv('SHELL_VERBOSITY=0');
377-
373+
// CI runs pest with --verbose which makes Artisan::call() inherit the verbosity
374+
// so we cannot easily test commands without -v. To work around that, we temporarily
375+
// override $_ENV['SHELL_VERBOSITY'] immediately before executing the command. If this
376+
// ever stops working, try also overriding the value in $_SERVER and putenv().
377+
$originalVerbosity = $_ENV['SHELL_VERBOSITY'] ?? 0;
378378
try {
379+
$_ENV['SHELL_VERBOSITY'] = 0;
379380
Artisan::call('tenants:migrate-fresh');
380381
$defaultOutput = Artisan::output();
381-
382-
Artisan::call('tenants:migrate-fresh -v');
383-
$verboseOutput = Artisan::output();
384382
} finally {
385-
unset($_ENV['SHELL_VERBOSITY'], $_SERVER['SHELL_VERBOSITY']);
386-
$shellVerbosity === false ? putenv('SHELL_VERBOSITY') : putenv("SHELL_VERBOSITY=$shellVerbosity");
383+
$_ENV['SHELL_VERBOSITY'] = $originalVerbosity;
387384
}
388385

386+
Artisan::call('tenants:migrate-fresh -v');
387+
$verboseOutput = Artisan::output();
388+
389389
// The output is silent by default and only shown with the verbose option
390390
expect($defaultOutput)->not()->toContain($migratingOutput);
391391
expect($verboseOutput)->toContain($migratingOutput);

0 commit comments

Comments
 (0)