Make 'database' state optional

This commit is contained in:
Ingo Schommer 2014-02-27 14:46:23 +13:00
parent add47cb625
commit 2c12cde90a
1 changed files with 16 additions and 19 deletions

View File

@ -128,22 +128,24 @@ class TestSessionEnvironment extends Object {
} }
} }
if(!DB::getConn()) { if(isset($state->database) && $state->database) {
// No connection, so try and connect to tmpdb if it exists if(!DB::getConn()) {
if(isset($state->database)) { // No connection, so try and connect to tmpdb if it exists
$this->oldDatabaseName = $databaseConfig['database']; if(isset($state->database)) {
$databaseConfig['database'] = $state->database; $this->oldDatabaseName = $databaseConfig['database'];
} $databaseConfig['database'] = $state->database;
}
// Connect to database // Connect to database
DB::connect($databaseConfig);
} else {
// We've already connected to the database, do a fast check to see what database we're currently using
$db = DB::query("SELECT DATABASE()")->value();
if(isset($state->database) && $db != $state->database) {
$this->oldDatabaseName = $databaseConfig['database'];
$databaseConfig['database'] = $state->database;
DB::connect($databaseConfig); DB::connect($databaseConfig);
} else {
// We've already connected to the database, do a fast check to see what database we're currently using
$db = DB::query("SELECT DATABASE()")->value();
if(isset($state->database) && $db != $state->database) {
$this->oldDatabaseName = $databaseConfig['database'];
$databaseConfig['database'] = $state->database;
DB::connect($databaseConfig);
}
} }
} }
@ -246,11 +248,6 @@ class TestSessionEnvironment extends Object {
$contents = file_get_contents(Director::getAbsFile($this->config()->test_state_file)); $contents = file_get_contents(Director::getAbsFile($this->config()->test_state_file));
$json = json_decode($contents); $json = json_decode($contents);
if(!isset($json->database)) {
throw new \LogicException('The test session file ('
. Director::getAbsFile($this->config()->test_state_file) . ') doesn\'t contain a database name.');
}
$this->applyState($json); $this->applyState($json);
} catch(Exception $e) { } catch(Exception $e) {
throw new \Exception("A test session appears to be in progress, but we can't retrieve the details. " throw new \Exception("A test session appears to be in progress, but we can't retrieve the details. "