From 90ff8d78d9c85bcf5fe4c77b25c1765305fa1660 Mon Sep 17 00:00:00 2001 From: lukinovec Date: Sat, 13 Jun 2026 09:26:34 +0200 Subject: [PATCH] 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 --- tests/CommandsTest.php | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/tests/CommandsTest.php b/tests/CommandsTest.php index c8e0bba4..f1bea31a 100644 --- a/tests/CommandsTest.php +++ b/tests/CommandsTest.php @@ -368,17 +368,27 @@ test('migrate fresh command works', function () { test('migrate fresh command only shows migration output when run with the verbose option', function () { $tenant = Tenant::create(); + $migratingOutput = 'Migrating tenant ' . $tenant->getTenantKey(); - // pest()->artisan()->expectsOutput() cannot observe the output suppression, - // so use Artisan::call() + Artisan::output() instead. + // 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'); - // By default the underlying tenants:migrate output is suppressed - Artisan::call('tenants:migrate-fresh'); - expect(Artisan::output())->not()->toContain('Migrating tenant ' . $tenant->getTenantKey()); + try { + Artisan::call('tenants:migrate-fresh'); + $defaultOutput = Artisan::output(); - // Underlying tenants:migrate output is shown when the verbose option is passed - Artisan::call('tenants:migrate-fresh -v'); - expect(Artisan::output())->toContain('Migrating tenant ' . $tenant->getTenantKey()); + 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"); + } + + // The output is silent by default and only shown with the verbose option + expect($defaultOutput)->not()->toContain($migratingOutput); + expect($verboseOutput)->toContain($migratingOutput); }); test('migrate fresh command respects force option in production', function () {