diff --git a/_config.php b/_config.php index 7bd9a34..a372c88 100644 --- a/_config.php +++ b/_config.php @@ -10,21 +10,21 @@ TestSessionEnvironment::singleton()->loadFromFile(); * This closure will run every time a Resque_Event is forked (just before it is forked, so it applies to the parent * and child process). */ -if(class_exists('Resque_Event') && class_exists('SSResqueRun')) { - Resque_Event::listen('beforeFork', function($data) { - global $databaseConfig; +if (class_exists('Resque_Event') && class_exists('SSResqueRun')) { + Resque_Event::listen('beforeFork', function ($data) { + $databaseConfig = DB::getConfig(); - // Reconnect to the database - this may connect to the old DB first, but is required because these processes - // are long-lived, and MySQL connections often get closed in between worker runs. We need to connect before - // calling {@link TestSessionEnvironment::loadFromFile()}. - DB::connect($databaseConfig); + // Reconnect to the database - this may connect to the old DB first, but is required because these processes + // are long-lived, and MySQL connections often get closed in between worker runs. We need to connect before + // calling {@link TestSessionEnvironment::loadFromFile()}. + DB::connect($databaseConfig); - $testEnv = TestSessionEnvironment::singleton(); + $testEnv = TestSessionEnvironment::singleton(); - if($testEnv->isRunningTests()) { - $testEnv->loadFromFile(); - } else { - $testEnv->endTestSession(); - } - }); + if ($testEnv->isRunningTests()) { + $testEnv->loadFromFile(); + } else { + $testEnv->endTestSession(); + } + }); } diff --git a/src/TestSessionEnvironment.php b/src/TestSessionEnvironment.php index fb74c9e..c4e60ca 100644 --- a/src/TestSessionEnvironment.php +++ b/src/TestSessionEnvironment.php @@ -450,9 +450,9 @@ class TestSessionEnvironment public function resetDatabaseName() { if ($this->oldDatabaseName) { - global $databaseConfig; - + $databaseConfig = DB::getConfig(); $databaseConfig['database'] = $this->oldDatabaseName; + DB::setConfig($databaseConfig); $conn = DB::get_conn(); diff --git a/src/TestSessionRequestFilter.php b/src/TestSessionRequestFilter.php index 7999aaf..cda508c 100644 --- a/src/TestSessionRequestFilter.php +++ b/src/TestSessionRequestFilter.php @@ -58,7 +58,7 @@ class TestSessionRequestFilter implements RequestFilter $file = $testState->stubfile; if (!Director::isLive() && $file && file_exists($file)) { // Connect to the database so the included code can interact with it - global $databaseConfig; + $databaseConfig = DB::getConfig(); if ($databaseConfig) { DB::connect($databaseConfig); }