|
368 | 368 |
|
369 | 369 | test('migrate fresh command only shows migration output when run with the verbose option', function () { |
370 | 370 | $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 | + } |
371 | 388 |
|
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); |
382 | 392 | }); |
383 | 393 |
|
384 | 394 | test('migrate fresh command respects force option in production', function () { |
|
0 commit comments