From 2c12cde90aa62a22f899487d0be98772610fa898 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Thu, 27 Feb 2014 14:46:23 +1300 Subject: [PATCH] Make 'database' state optional --- code/TestSessionEnvironment.php | 35 +++++++++++++++------------------ 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/code/TestSessionEnvironment.php b/code/TestSessionEnvironment.php index afbec73..ad2c81b 100644 --- a/code/TestSessionEnvironment.php +++ b/code/TestSessionEnvironment.php @@ -128,22 +128,24 @@ class TestSessionEnvironment extends Object { } } - if(!DB::getConn()) { - // No connection, so try and connect to tmpdb if it exists - if(isset($state->database)) { - $this->oldDatabaseName = $databaseConfig['database']; - $databaseConfig['database'] = $state->database; - } + if(isset($state->database) && $state->database) { + if(!DB::getConn()) { + // No connection, so try and connect to tmpdb if it exists + if(isset($state->database)) { + $this->oldDatabaseName = $databaseConfig['database']; + $databaseConfig['database'] = $state->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; + // 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); + } } } @@ -246,11 +248,6 @@ class TestSessionEnvironment extends Object { $contents = file_get_contents(Director::getAbsFile($this->config()->test_state_file)); $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); } catch(Exception $e) { throw new \Exception("A test session appears to be in progress, but we can't retrieve the details. "