+19
-1
@@ -12,11 +12,29 @@ abstract class TestCase extends BaseTestCase
|
||||
public function createApplication(): Application
|
||||
{
|
||||
$app = parent::createApplication();
|
||||
$connectionName = $app->make('config')->get('database.default');
|
||||
$connection = $app->make('config')->get('database.connections.'.$connectionName, []);
|
||||
|
||||
// Never let a test runner silently fall back to the developer/application database.
|
||||
// Keep this check before RefreshDatabase or any schema cleanup can open a connection.
|
||||
if ($app->environment('testing') && ($connection['driver'] ?? null) === 'pgsql') {
|
||||
$database = strtolower((string) ($connection['database'] ?? ''));
|
||||
$host = strtolower((string) ($connection['host'] ?? ''));
|
||||
$url = $connection['url'] ?? null;
|
||||
|
||||
if ($database === 'investemoz'
|
||||
|| ! str_ends_with($database, '_test')
|
||||
|| ! in_array($host, ['127.0.0.1', 'localhost'], true)
|
||||
|| ! in_array($url, [null, ''], true)) {
|
||||
throw new \LogicException('PHPUnit PostgreSQL target rejected: configure an explicit loopback *_test database with no DB_URL.');
|
||||
}
|
||||
}
|
||||
|
||||
// migrate:fresh only clears the connection's public search path. This module owns a separate schema.
|
||||
if (! RefreshDatabaseState::$migrated && $app->environment('testing')) {
|
||||
$db = $app->make('db')->connection();
|
||||
if ($db->getDriverName() === 'pgsql'
|
||||
&& in_array($db->getDatabaseName(), ['portal_services_test', 'investmoz_test'], true)
|
||||
&& in_array($db->getDatabaseName(), ['portal_services_test', 'investmoz_test', 'investmoz_browser_e2e_test'], true)
|
||||
&& (string) $db->getConfig('port') === '55441'
|
||||
&& in_array($db->getConfig('host'), ['127.0.0.1', 'localhost'], true)) {
|
||||
$db->statement('DROP SCHEMA IF EXISTS skills_edu CASCADE');
|
||||
|
||||
Reference in New Issue
Block a user