1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2026-08-06 12:04:04 +00:00

simplify ENV manipulation code in test

This commit is contained in:
Samuel Stancl 2026-06-28 18:42:45 -07:00
parent 90ff8d78d9
commit 4f2c4528a4
No known key found for this signature in database
GPG key ID: BA146259A1E16C57

View file

@ -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);