mirror of
https://github.com/archtechx/tenancy.git
synced 2026-08-06 06:54:03 +00:00
simplify ENV manipulation code in test
This commit is contained in:
parent
90ff8d78d9
commit
4f2c4528a4
1 changed files with 10 additions and 10 deletions
|
|
@ -370,21 +370,21 @@ 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();
|
||||||
|
} finally {
|
||||||
|
$_ENV['SHELL_VERBOSITY'] = $originalVerbosity;
|
||||||
|
}
|
||||||
|
|
||||||
Artisan::call('tenants:migrate-fresh -v');
|
Artisan::call('tenants:migrate-fresh -v');
|
||||||
$verboseOutput = Artisan::output();
|
$verboseOutput = Artisan::output();
|
||||||
} finally {
|
|
||||||
unset($_ENV['SHELL_VERBOSITY'], $_SERVER['SHELL_VERBOSITY']);
|
|
||||||
$shellVerbosity === false ? putenv('SHELL_VERBOSITY') : putenv("SHELL_VERBOSITY=$shellVerbosity");
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue