From 94af2adcc729f9a0c347cba0eb5fc3be643a4603 Mon Sep 17 00:00:00 2001 From: madmatt Date: Wed, 11 Sep 2019 23:30:10 +1200 Subject: [PATCH 1/2] FIX: Ensure TempDatabase->build() doesn't tear down the database after the testsession start request --- src/TestSessionEnvironment.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/TestSessionEnvironment.php b/src/TestSessionEnvironment.php index e8e8bf0..ae7af83 100644 --- a/src/TestSessionEnvironment.php +++ b/src/TestSessionEnvironment.php @@ -277,6 +277,9 @@ class TestSessionEnvironment $databaseConfig = DB::getConfig(); if (!$dbExists && $dbCreate) { $this->oldDatabaseName = $databaseConfig['database']; + // Ensure we don't allow TempDatabase to immediately kill the newly created DB when the request finishes + Config::modify()->set(TempDatabase::class, 'teardown_on_exit', false); + // Create a new one with a randomized name $tempDB = TempDatabase::create(); $dbName = $tempDB->build(); From c095661c9702e2c8b70127b649c2309777787802 Mon Sep 17 00:00:00 2001 From: madmatt Date: Wed, 18 Sep 2019 14:54:34 +1200 Subject: [PATCH 2/2] Fix missing config ns inclusion --- src/TestSessionEnvironment.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/TestSessionEnvironment.php b/src/TestSessionEnvironment.php index ae7af83..69ddc8a 100644 --- a/src/TestSessionEnvironment.php +++ b/src/TestSessionEnvironment.php @@ -11,6 +11,7 @@ use SilverStripe\Control\Director; use SilverStripe\Control\Email\Email; use SilverStripe\Control\Email\Mailer; use SilverStripe\Control\HTTPRequest; +use SilverStripe\Core\Config\Config; use SilverStripe\Core\Config\Configurable; use SilverStripe\Core\Environment; use SilverStripe\Core\Extensible;