1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2026-08-06 05:54:03 +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(); $tenant = Tenant::create();
$migratingOutput = 'Migrating tenant ' . $tenant->getTenantKey(); $migratingOutput = 'Migrating tenant ' . $tenant->getTenantKey();
// CI runs pest with -v, setting SHELL_VERBOSITY to 1, so in CI, the output is verbose by default // CI runs pest with --verbose which makes Artisan::call() inherit the verbosity
$shellVerbosity = getenv('SHELL_VERBOSITY'); // so we cannot easily test commands without -v. To work around that, we temporarily
$_ENV['SHELL_VERBOSITY'] = $_SERVER['SHELL_VERBOSITY'] = 0; // override $_ENV['SHELL_VERBOSITY'] immediately before executing the command. If this
putenv('SHELL_VERBOSITY=0'); // ever stops working, try also overriding the value in $_SERVER and putenv().
$originalVerbosity = $_ENV['SHELL_VERBOSITY'] ?? 0;
try { try {
$_ENV['SHELL_VERBOSITY'] = 0;
Artisan::call('tenants:migrate-fresh'); Artisan::call('tenants:migrate-fresh');
$defaultOutput = Artisan::output(); $defaultOutput = Artisan::output();
Artisan::call('tenants:migrate-fresh -v');
$verboseOutput = Artisan::output();
} finally { } finally {
unset($_ENV['SHELL_VERBOSITY'], $_SERVER['SHELL_VERBOSITY']); $_ENV['SHELL_VERBOSITY'] = $originalVerbosity;
$shellVerbosity === false ? putenv('SHELL_VERBOSITY') : putenv("SHELL_VERBOSITY=$shellVerbosity");
} }
Artisan::call('tenants:migrate-fresh -v');
$verboseOutput = Artisan::output();
// The output is silent by default and only shown with the verbose option // The output is silent by default and only shown with the verbose option
expect($defaultOutput)->not()->toContain($migratingOutput); expect($defaultOutput)->not()->toContain($migratingOutput);
expect($verboseOutput)->toContain($migratingOutput); expect($verboseOutput)->toContain($migratingOutput);