mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 19:04:02 +00:00
Update TenantDatabaseManagerTest.php
This commit is contained in:
parent
f8ec22b5ca
commit
b8e0a1c982
1 changed files with 3 additions and 29 deletions
|
|
@ -24,11 +24,13 @@ use Stancl\Tenancy\Database\TenantDatabaseManagers\PostgreSQLSchemaManager;
|
||||||
use Stancl\Tenancy\Database\TenantDatabaseManagers\SQLiteDatabaseManager;
|
use Stancl\Tenancy\Database\TenantDatabaseManagers\SQLiteDatabaseManager;
|
||||||
use Stancl\Tenancy\Tests\Etc\Tenant;
|
use Stancl\Tenancy\Tests\Etc\Tenant;
|
||||||
|
|
||||||
test('databases can be created and deleted', function ($driver, $databaseManager) {
|
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) {
|
||||||
return $event->tenant;
|
return $event->tenant;
|
||||||
})->toListener());
|
})->toListener());
|
||||||
|
});
|
||||||
|
|
||||||
|
test('databases can be created and deleted', function ($driver, $databaseManager) {
|
||||||
config()->set([
|
config()->set([
|
||||||
"tenancy.database.managers.$driver" => $databaseManager,
|
"tenancy.database.managers.$driver" => $databaseManager,
|
||||||
]);
|
]);
|
||||||
|
|
@ -53,10 +55,6 @@ test('databases can be created and deleted', function ($driver, $databaseManager
|
||||||
test('dbs can be created when another driver is used for the central db', function () {
|
test('dbs can be created when another driver is used for the central db', function () {
|
||||||
expect(config('database.default'))->toBe('central');
|
expect(config('database.default'))->toBe('central');
|
||||||
|
|
||||||
Event::listen(TenantCreated::class, JobPipeline::make([CreateDatabase::class])->send(function (TenantCreated $event) {
|
|
||||||
return $event->tenant;
|
|
||||||
})->toListener());
|
|
||||||
|
|
||||||
$database = 'db' . pest()->randomString();
|
$database = 'db' . pest()->randomString();
|
||||||
|
|
||||||
$mysqlmanager = app(MySQLDatabaseManager::class);
|
$mysqlmanager = app(MySQLDatabaseManager::class);
|
||||||
|
|
@ -91,10 +89,6 @@ test('the tenant connection is fully removed', function () {
|
||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
Event::listen(TenantCreated::class, JobPipeline::make([CreateDatabase::class])->send(function (TenantCreated $event) {
|
|
||||||
return $event->tenant;
|
|
||||||
})->toListener());
|
|
||||||
|
|
||||||
Event::listen(TenancyInitialized::class, BootstrapTenancy::class);
|
Event::listen(TenancyInitialized::class, BootstrapTenancy::class);
|
||||||
Event::listen(TenancyEnded::class, RevertToCentralContext::class);
|
Event::listen(TenancyEnded::class, RevertToCentralContext::class);
|
||||||
|
|
||||||
|
|
@ -141,10 +135,6 @@ test('schema manager uses schema to separate tenant dbs', function () {
|
||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
Event::listen(TenantCreated::class, JobPipeline::make([CreateDatabase::class])->send(function (TenantCreated $event) {
|
|
||||||
return $event->tenant;
|
|
||||||
})->toListener());
|
|
||||||
|
|
||||||
Event::listen(TenancyInitialized::class, BootstrapTenancy::class);
|
Event::listen(TenancyInitialized::class, BootstrapTenancy::class);
|
||||||
|
|
||||||
$originalDatabaseName = config(['database.connections.pgsql.database']);
|
$originalDatabaseName = config(['database.connections.pgsql.database']);
|
||||||
|
|
@ -163,10 +153,6 @@ test('schema manager uses schema to separate tenant dbs', function () {
|
||||||
});
|
});
|
||||||
|
|
||||||
test('a tenants database cannot be created when the database already exists', function () {
|
test('a tenants database cannot be created when the database already exists', function () {
|
||||||
Event::listen(TenantCreated::class, JobPipeline::make([CreateDatabase::class])->send(function (TenantCreated $event) {
|
|
||||||
return $event->tenant;
|
|
||||||
})->toListener());
|
|
||||||
|
|
||||||
$name = 'foo' . Str::random(8);
|
$name = 'foo' . Str::random(8);
|
||||||
$tenant = Tenant::create([
|
$tenant = Tenant::create([
|
||||||
'tenancy_db_name' => $name,
|
'tenancy_db_name' => $name,
|
||||||
|
|
@ -204,10 +190,6 @@ test('tenant database can be created and deleted on a foreign server', function
|
||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
Event::listen(TenantCreated::class, JobPipeline::make([CreateDatabase::class])->send(function (TenantCreated $event) {
|
|
||||||
return $event->tenant;
|
|
||||||
})->toListener());
|
|
||||||
|
|
||||||
$name = 'foo' . Str::random(8);
|
$name = 'foo' . Str::random(8);
|
||||||
$tenant = Tenant::create([
|
$tenant = Tenant::create([
|
||||||
'tenancy_db_name' => $name,
|
'tenancy_db_name' => $name,
|
||||||
|
|
@ -251,10 +233,6 @@ test('tenant database can be created on a foreign server by using the host from
|
||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
Event::listen(TenantCreated::class, JobPipeline::make([CreateDatabase::class])->send(function (TenantCreated $event) {
|
|
||||||
return $event->tenant;
|
|
||||||
})->toListener());
|
|
||||||
|
|
||||||
$name = 'foo' . Str::random(8);
|
$name = 'foo' . Str::random(8);
|
||||||
$tenant = Tenant::create([
|
$tenant = Tenant::create([
|
||||||
'tenancy_db_name' => $name,
|
'tenancy_db_name' => $name,
|
||||||
|
|
@ -292,10 +270,6 @@ test('tenant database can be created on a foreign server by using the username a
|
||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
Event::listen(TenantCreated::class, JobPipeline::make([CreateDatabase::class])->send(function (TenantCreated $event) {
|
|
||||||
return $event->tenant;
|
|
||||||
})->toListener());
|
|
||||||
|
|
||||||
$name = 'foo' . Str::random(8);
|
$name = 'foo' . Str::random(8);
|
||||||
$tenant = Tenant::create([
|
$tenant = Tenant::create([
|
||||||
'tenancy_db_name' => $name,
|
'tenancy_db_name' => $name,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue