diff --git a/tests/Bootstrappers/DatabaseTenancyBootstrapperTest.php b/tests/Bootstrappers/DatabaseTenancyBootstrapperTest.php index 63762672..ca292933 100644 --- a/tests/Bootstrappers/DatabaseTenancyBootstrapperTest.php +++ b/tests/Bootstrappers/DatabaseTenancyBootstrapperTest.php @@ -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]);