assertSafeTestDatabase(); } private function assertSafeTestDatabase(): void { $driver = config('database.default'); $database = config("database.connections.{$driver}.database"); $allowed = $database === ':memory:' || $database === null || str_contains((string) $database, '/testing') || str_contains((string) $database, '/tmp/') || str_ends_with((string) $database, '.testing.sqlite'); if (! $allowed) { // Fatal, not an assertion failure — a wrong DB target has to stop // execution before Laravel can run even one query against it. fwrite(STDERR, "\n\n*** ABORTING TESTS: unsafe DB target '{$database}' on connection '{$driver}'. ***\n"); fwrite(STDERR, "Set DB_CONNECTION=sqlite and DB_DATABASE=:memory: in .env.testing (or in your test's setUp before parent::setUp).\n\n"); exit(2); } } }