mirror of
https://github.com/archtechx/tenancy.git
synced 2026-02-05 15:54:03 +00:00
Change migrate:fresh test to test if the tenant DBs are dropped by default
This commit is contained in:
parent
3728eea6de
commit
6269dc95e4
1 changed files with 16 additions and 45 deletions
|
|
@ -2,24 +2,23 @@
|
||||||
|
|
||||||
declare(strict_types=1);
|
declare(strict_types=1);
|
||||||
|
|
||||||
use Illuminate\Database\DatabaseManager;
|
|
||||||
use Illuminate\Support\Carbon;
|
|
||||||
use Illuminate\Support\Facades\Artisan;
|
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Stancl\Tenancy\Tests\Etc\User;
|
||||||
|
use Stancl\JobPipeline\JobPipeline;
|
||||||
|
use Stancl\Tenancy\Tests\Etc\Tenant;
|
||||||
use Illuminate\Support\Facades\Event;
|
use Illuminate\Support\Facades\Event;
|
||||||
use Illuminate\Support\Facades\Schema;
|
use Illuminate\Support\Facades\Schema;
|
||||||
use Stancl\JobPipeline\JobPipeline;
|
use Illuminate\Support\Facades\Artisan;
|
||||||
use Stancl\Tenancy\Bootstrappers\DatabaseTenancyBootstrapper;
|
|
||||||
use Stancl\Tenancy\Events\TenancyEnded;
|
use Stancl\Tenancy\Events\TenancyEnded;
|
||||||
use Stancl\Tenancy\Events\TenancyInitialized;
|
|
||||||
use Stancl\Tenancy\Events\TenantCreated;
|
|
||||||
use Stancl\Tenancy\Jobs\CreateDatabase;
|
use Stancl\Tenancy\Jobs\CreateDatabase;
|
||||||
|
use Illuminate\Database\DatabaseManager;
|
||||||
|
use Stancl\Tenancy\Events\TenantCreated;
|
||||||
|
use Stancl\Tenancy\Tests\Etc\TestSeeder;
|
||||||
|
use Stancl\Tenancy\Tests\Etc\ExampleSeeder;
|
||||||
|
use Stancl\Tenancy\Events\TenancyInitialized;
|
||||||
use Stancl\Tenancy\Listeners\BootstrapTenancy;
|
use Stancl\Tenancy\Listeners\BootstrapTenancy;
|
||||||
use Stancl\Tenancy\Listeners\RevertToCentralContext;
|
use Stancl\Tenancy\Listeners\RevertToCentralContext;
|
||||||
use Stancl\Tenancy\Tests\Etc\ExampleSeeder;
|
use Stancl\Tenancy\Bootstrappers\DatabaseTenancyBootstrapper;
|
||||||
use Stancl\Tenancy\Tests\Etc\Tenant;
|
|
||||||
use Stancl\Tenancy\Tests\Etc\TestSeeder;
|
|
||||||
use Stancl\Tenancy\Tests\Etc\User;
|
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
Event::listen(TenantCreated::class, JobPipeline::make([CreateDatabase::class])->send(function (TenantCreated $event) {
|
Event::listen(TenantCreated::class, JobPipeline::make([CreateDatabase::class])->send(function (TenantCreated $event) {
|
||||||
|
|
@ -267,9 +266,7 @@ test('run command works when sub command asks questions and accepts arguments',
|
||||||
expect($user->email)->toBe('email@localhost');
|
expect($user->email)->toBe('email@localhost');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('migrate fresh command deletes tenant databases based on the tenancy.database.drop_tenant_databases_on_migrate_fresh config value', function() {
|
test('migrate fresh command deletes tenant databases by default', function() {
|
||||||
config(['tenancy.database.drop_tenant_databases_on_migrate_fresh' => false]);
|
|
||||||
|
|
||||||
/** @var Tenant[] $tenants */
|
/** @var Tenant[] $tenants */
|
||||||
$tenants = [
|
$tenants = [
|
||||||
Tenant::create(),
|
Tenant::create(),
|
||||||
|
|
@ -277,16 +274,11 @@ test('migrate fresh command deletes tenant databases based on the tenancy.databa
|
||||||
Tenant::create(),
|
Tenant::create(),
|
||||||
];
|
];
|
||||||
|
|
||||||
Artisan::call('migrate:fresh', [
|
$tenantHasDatabase = fn (Tenant $tenant) => $tenant->database()->manager()->databaseExists($tenant->database()->getName());
|
||||||
'--force' => true,
|
|
||||||
'--path' => __DIR__ . '/../assets/migrations',
|
|
||||||
'--realpath' => true,
|
|
||||||
]);
|
|
||||||
|
|
||||||
$tenantDatabaseExists = fn(Tenant $tenant) => $tenant->database()->manager()->databaseExists($tenant->database()->getName());
|
|
||||||
|
|
||||||
foreach ($tenants as $tenant) {
|
foreach ($tenants as $tenant) {
|
||||||
expect($tenantDatabaseExists($tenant))->toBeTrue();
|
expect()->toBeTrue();
|
||||||
|
expect($tenantHasDatabase($tenant))->toBeTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
pest()->artisan('migrate:fresh', [
|
pest()->artisan('migrate:fresh', [
|
||||||
|
|
@ -296,29 +288,8 @@ test('migrate fresh command deletes tenant databases based on the tenancy.databa
|
||||||
]);
|
]);
|
||||||
|
|
||||||
foreach ($tenants as $tenant) {
|
foreach ($tenants as $tenant) {
|
||||||
expect($tenantDatabaseExists($tenant))->toBeTrue();
|
expect($tenant->exists())->toBeFalse();
|
||||||
}
|
expect($tenantHasDatabase($tenant))->toBeFalse();
|
||||||
|
|
||||||
config(['tenancy.database.drop_tenant_databases_on_migrate_fresh' => true]);
|
|
||||||
|
|
||||||
$tenants = [
|
|
||||||
Tenant::create(),
|
|
||||||
Tenant::create(),
|
|
||||||
Tenant::create(),
|
|
||||||
];
|
|
||||||
|
|
||||||
foreach ($tenants as $tenant) {
|
|
||||||
expect($tenantDatabaseExists($tenant))->toBeTrue();
|
|
||||||
}
|
|
||||||
|
|
||||||
pest()->artisan('migrate:fresh', [
|
|
||||||
'--force' => true,
|
|
||||||
'--path' => __DIR__ . '/../assets/migrations',
|
|
||||||
'--realpath' => true,
|
|
||||||
]);
|
|
||||||
|
|
||||||
foreach ($tenants as $tenant) {
|
|
||||||
expect($tenantDatabaseExists($tenant))->toBeFalse();
|
|
||||||
}
|
}
|
||||||
})->group('fresh');
|
})->group('fresh');
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue