1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2026-08-06 05:54:03 +00:00

migrate-fresh: show migration output when verbose (#1464)

Resubmission of #1369 (by @lordofthebrain), changes adapted to v4. Also
added a test (passes with the MigrateFresh changes, fails without them).

---------

Co-authored-by: lordofthebrain <f.mangelsdorf@gmail.com>
Co-authored-by: Samuel Stancl <samuel@archte.ch>
This commit is contained in:
lukinovec 2026-06-29 04:04:02 +02:00 committed by GitHub
parent aa9d1d7fcf
commit df4be2e060
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 35 additions and 2 deletions

View file

@ -366,6 +366,36 @@ test('migrate fresh command works', function () {
expect(DB::table('users')->exists())->toBeFalse();
});
test('migrate fresh command only shows migration output when run with the verbose option', function () {
$tenant = Tenant::create();
$migratingOutput = 'Migrating tenant ' . $tenant->getTenantKey();
// CI runs pest with --verbose which makes Artisan::call() inherit the verbosity
// so we cannot easily test commands without -v. To work around that, we temporarily
// override $_ENV['SHELL_VERBOSITY'] immediately before executing the command. If this
// ever stops working, try also overriding the value in $_SERVER and putenv().
$emptySentinel = new \stdClass();
$originalVerbosity = $_ENV['SHELL_VERBOSITY'] ?? $emptySentinel;
try {
$_ENV['SHELL_VERBOSITY'] = 0;
Artisan::call('tenants:migrate-fresh');
$defaultOutput = Artisan::output();
} finally {
if ($originalVerbosity === $emptySentinel) {
unset($_ENV['SHELL_VERBOSITY']);
} else {
$_ENV['SHELL_VERBOSITY'] = $originalVerbosity;
}
}
Artisan::call('tenants:migrate-fresh -v');
$verboseOutput = Artisan::output();
// 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 () {
// Set environment to production
app()->detectEnvironment(fn() => 'production');