mirror of
https://github.com/archtechx/tenancy.git
synced 2026-08-06 10:44:04 +00:00
Correct the "throw exception while DB_URL is set" test
Set the url in the template connection config only after creating a tenant. Before, the url was set before creating a tenant, and because of that, the tenant couldn't be created in the first place. During CreateDatabase, a QueryException (`SQLSTATE[HY000] [1049] Unknown database 'bc.us-east-1.rds.amazonaws.com'`) was thrown, and the test didn't get to exercise the bootstrapper's code branch that should throw an exception if the db url is set
This commit is contained in:
parent
df4be2e060
commit
f6d7ac13db
1 changed files with 9 additions and 11 deletions
|
|
@ -12,7 +12,6 @@ use Stancl\Tenancy\Listeners\RevertToCentralContext;
|
|||
use Stancl\Tenancy\Tests\Etc\Tenant;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Database\QueryException;
|
||||
use Stancl\Tenancy\Database\TenantDatabaseManagers\MySQLDatabaseManager;
|
||||
use Stancl\Tenancy\Database\TenantDatabaseManagers\SQLiteDatabaseManager;
|
||||
use Stancl\Tenancy\Database\TenantDatabaseManagers\PostgreSQLDatabaseManager;
|
||||
|
|
@ -129,24 +128,23 @@ test('harden prevents tenants from using the database of another tenant', functi
|
|||
])->with('db_managers');
|
||||
|
||||
test('database tenancy bootstrapper throws an exception if DATABASE_URL is set', function (string|null $databaseUrl) {
|
||||
config(['database.connections.central.url' => $databaseUrl]);
|
||||
|
||||
config(['tenancy.bootstrappers' => [DatabaseTenancyBootstrapper::class]]);
|
||||
|
||||
Event::listen(TenantCreated::class, JobPipeline::make([CreateDatabase::class])->send(function (TenantCreated $event) {
|
||||
return $event->tenant;
|
||||
})->toListener());
|
||||
|
||||
$tenant = Tenant::create();
|
||||
|
||||
pest()->artisan('tenants:migrate');
|
||||
|
||||
config(['database.connections.central.url' => $databaseUrl]);
|
||||
|
||||
if ($databaseUrl) {
|
||||
expect(fn() => Tenant::create())->toThrow(QueryException::class);
|
||||
expect(fn() => tenancy()->initialize($tenant))
|
||||
->toThrow(Exception::class, 'The template connection must NOT have URL defined.');
|
||||
} else {
|
||||
expect(function() {
|
||||
$tenant1 = Tenant::create();
|
||||
|
||||
pest()->artisan('tenants:migrate');
|
||||
|
||||
tenancy()->initialize($tenant1);
|
||||
})->not()->toThrow(Throwable::class);
|
||||
expect(fn() => tenancy()->initialize($tenant))->not()->toThrow(Throwable::class);
|
||||
}
|
||||
})->with(['abc.us-east-1.rds.amazonaws.com', null]);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue