Skip to content

Commit 90ff8d7

Browse files
committed
Try making the verbosity test pass in CI
Since CI runs tests with -v, it sets SHELL_VERBOSITY to 1, making the tenants:migrate-fresh output always verbose
1 parent 1f2a017 commit 90ff8d7

1 file changed

Lines changed: 20 additions & 10 deletions

File tree

tests/CommandsTest.php

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -368,17 +368,27 @@
368368

369369
test('migrate fresh command only shows migration output when run with the verbose option', function () {
370370
$tenant = Tenant::create();
371+
$migratingOutput = 'Migrating tenant ' . $tenant->getTenantKey();
372+
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+
378+
try {
379+
Artisan::call('tenants:migrate-fresh');
380+
$defaultOutput = Artisan::output();
381+
382+
Artisan::call('tenants:migrate-fresh -v');
383+
$verboseOutput = Artisan::output();
384+
} finally {
385+
unset($_ENV['SHELL_VERBOSITY'], $_SERVER['SHELL_VERBOSITY']);
386+
$shellVerbosity === false ? putenv('SHELL_VERBOSITY') : putenv("SHELL_VERBOSITY=$shellVerbosity");
387+
}
371388

372-
// pest()->artisan()->expectsOutput() cannot observe the output suppression,
373-
// so use Artisan::call() + Artisan::output() instead.
374-
375-
// By default the underlying tenants:migrate output is suppressed
376-
Artisan::call('tenants:migrate-fresh');
377-
expect(Artisan::output())->not()->toContain('Migrating tenant ' . $tenant->getTenantKey());
378-
379-
// Underlying tenants:migrate output is shown when the verbose option is passed
380-
Artisan::call('tenants:migrate-fresh -v');
381-
expect(Artisan::output())->toContain('Migrating tenant ' . $tenant->getTenantKey());
389+
// The output is silent by default and only shown with the verbose option
390+
expect($defaultOutput)->not()->toContain($migratingOutput);
391+
expect($verboseOutput)->toContain($migratingOutput);
382392
});
383393

384394
test('migrate fresh command respects force option in production', function () {

0 commit comments

Comments
 (0)