mirror of
https://github.com/archtechx/tenancy.git
synced 2026-02-05 14:34:04 +00:00
Update migrate:fresh test
This commit is contained in:
parent
2c4f482506
commit
912f9a964d
1 changed files with 35 additions and 2 deletions
|
|
@ -18,11 +18,17 @@ use Stancl\Tenancy\Events\TenantCreated;
|
|||
use Stancl\Tenancy\Events\TenantDeleted;
|
||||
use Stancl\Tenancy\Tests\Etc\TestSeeder;
|
||||
use Stancl\Tenancy\Events\DeletingTenant;
|
||||
use Stancl\Tenancy\TenancyServiceProvider;
|
||||
use Stancl\Tenancy\Tests\Etc\ExampleSeeder;
|
||||
use Stancl\Tenancy\Events\TenancyInitialized;
|
||||
use Illuminate\Console\ContainerCommandLoader;
|
||||
use Stancl\Tenancy\Listeners\BootstrapTenancy;
|
||||
use Illuminate\Contracts\Foundation\Application;
|
||||
use Stancl\Tenancy\Listeners\RevertToCentralContext;
|
||||
use Illuminate\Database\Console\Migrations\FreshCommand;
|
||||
use Stancl\Tenancy\Bootstrappers\DatabaseTenancyBootstrapper;
|
||||
use Symfony\Component\Console\CommandLoader\CommandLoaderInterface;
|
||||
|
||||
|
||||
beforeEach(function () {
|
||||
Event::listen(TenantCreated::class, JobPipeline::make([CreateDatabase::class])->send(function (TenantCreated $event) {
|
||||
|
|
@ -270,7 +276,7 @@ test('run command works when sub command asks questions and accepts arguments',
|
|||
expect($user->email)->toBe('email@localhost');
|
||||
});
|
||||
|
||||
test('migrate fresh command deletes tenant databases by default', function() {
|
||||
test('migrate fresh command only deletes tenant databases if drop_tenant_databases_on_migrate_fresh is true', function() {
|
||||
Event::listen(
|
||||
DeletingTenant::class,
|
||||
JobPipeline::make([DeleteDomains::class])->send(function (DeletingTenant $event) {
|
||||
|
|
@ -285,6 +291,10 @@ test('migrate fresh command deletes tenant databases by default', function() {
|
|||
})->shouldBeQueued(false)->toListener()
|
||||
);
|
||||
|
||||
|
||||
config(['tenancy.database.drop_tenant_databases_on_migrate_fresh' => false]);
|
||||
app()->forgetInstance(FreshCommand::class);
|
||||
|
||||
/** @var Tenant[] $tenants */
|
||||
$tenants = [
|
||||
Tenant::create(),
|
||||
|
|
@ -304,10 +314,33 @@ test('migrate fresh command deletes tenant databases by default', function() {
|
|||
'--realpath' => true,
|
||||
]);
|
||||
|
||||
foreach ($tenants as $tenant) {
|
||||
expect($tenantHasDatabase($tenant))->toBeTrue();
|
||||
}
|
||||
|
||||
config(['tenancy.database.drop_tenant_databases_on_migrate_fresh' => true]);
|
||||
app()->forgetInstance(FreshCommand::class);
|
||||
|
||||
$tenants = [
|
||||
Tenant::create(),
|
||||
Tenant::create(),
|
||||
Tenant::create(),
|
||||
];
|
||||
|
||||
foreach ($tenants as $tenant) {
|
||||
expect($tenantHasDatabase($tenant))->toBeTrue();
|
||||
}
|
||||
|
||||
pest()->artisan('migrate:fresh', [
|
||||
'--force' => true,
|
||||
'--path' => __DIR__ . '/../assets/migrations',
|
||||
'--realpath' => true,
|
||||
]);
|
||||
|
||||
foreach ($tenants as $tenant) {
|
||||
expect($tenantHasDatabase($tenant))->toBeFalse();
|
||||
}
|
||||
})->group('fresh');
|
||||
});
|
||||
|
||||
// todo@tests
|
||||
function runCommandWorks(): void
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue