1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2026-02-05 13:14:05 +00:00

Revert "Update TenantDatabaseManagerTest.php"

This reverts commit b8e0a1c982.
This commit is contained in:
Abrar Ahmad 2022-10-10 17:17:58 +05:00
parent 69e4a1ef2a
commit 9418402c17

View file

@ -24,13 +24,11 @@ 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;
beforeEach(function () { test('databases can be created and deleted', function ($driver, $databaseManager) {
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,
]); ]);
@ -55,6 +53,10 @@ 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);
@ -89,6 +91,10 @@ 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);
@ -135,6 +141,10 @@ 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']);
@ -151,6 +161,10 @@ 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,
@ -188,6 +202,10 @@ 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,
@ -231,6 +249,10 @@ 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,
@ -268,6 +290,10 @@ 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,