mirror of
https://github.com/archtechx/tenancy.git
synced 2026-06-21 01:54:03 +00:00
Merge 90ff8d78d9 into 652bc987ce
This commit is contained in:
commit
5fefb260c5
2 changed files with 30 additions and 2 deletions
|
|
@ -14,6 +14,7 @@ use Stancl\Tenancy\Concerns\ParallelCommand;
|
|||
use Stancl\Tenancy\Database\Contracts\TenantWithDatabase;
|
||||
use Stancl\Tenancy\Database\Exceptions\TenantDatabaseDoesNotExistException;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\NullOutput;
|
||||
use Symfony\Component\Console\Output\OutputInterface as OI;
|
||||
|
||||
class MigrateFresh extends BaseCommand
|
||||
|
|
@ -72,11 +73,13 @@ class MigrateFresh extends BaseCommand
|
|||
|
||||
protected function migrateTenant(TenantWithDatabase $tenant): bool
|
||||
{
|
||||
return $this->callSilently('tenants:migrate', [
|
||||
$output = $this->getOutput()->isVerbose() ? $this->output : new NullOutput;
|
||||
|
||||
return $this->runCommand('tenants:migrate', [
|
||||
'--tenants' => [$tenant->getTenantKey()],
|
||||
'--step' => $this->option('step'),
|
||||
'--force' => true,
|
||||
]) === 0;
|
||||
], $output) === 0;
|
||||
}
|
||||
|
||||
protected function childHandle(mixed ...$args): bool
|
||||
|
|
|
|||
|
|
@ -366,6 +366,31 @@ 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 -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');
|
||||
|
||||
try {
|
||||
Artisan::call('tenants:migrate-fresh');
|
||||
$defaultOutput = Artisan::output();
|
||||
|
||||
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 () {
|
||||
// Set environment to production
|
||||
app()->detectEnvironment(fn() => 'production');
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue