diff --git a/_config.php b/_config.php index e7bd2ee..237dd1a 100644 --- a/_config.php +++ b/_config.php @@ -1,6 +1,8 @@ get('TestSessionEnvironment')->loadFromFile(); diff --git a/code/TestSessionController.php b/code/TestSessionController.php index 75fbd9d..4191482 100644 --- a/code/TestSessionController.php +++ b/code/TestSessionController.php @@ -1,8 +1,27 @@ get('RandomGenerator'); + $generator = Injector::inst()->get('SilverStripe\\Security\\RandomGenerator'); $id = substr($generator->randomToken(), 0, 10); Session::set('TestSessionId', $id); } diff --git a/code/TestSessionEnvironment.php b/code/TestSessionEnvironment.php index e49ed15..062844b 100644 --- a/code/TestSessionEnvironment.php +++ b/code/TestSessionEnvironment.php @@ -1,9 +1,16 @@ extend('onBeforeApplyState', $state); - $database = (isset($state->database)) ? $state->database : null; - // back up source global $databaseConfig; $this->oldDatabaseName = $databaseConfig['database']; @@ -244,7 +251,7 @@ class TestSessionEnvironment extends Object $mailer = (isset($state->mailer)) ? $state->mailer : null; if ($mailer) { - if (!class_exists($mailer) || !is_subclass_of($mailer, 'Mailer')) { + if (!class_exists($mailer) || !is_subclass_of($mailer, 'SilverStripe\\Control\\Email\\Mailer')) { throw new InvalidArgumentException(sprintf( 'Class "%s" is not a valid class, or subclass of Mailer', $mailer @@ -272,7 +279,7 @@ class TestSessionEnvironment extends Object * Import the database * * @param String $path Absolute path to a SQL dump (include DROP TABLE commands) - * @return void + * @param bool $requireDefaultRecords */ public function importDatabase($path, $requireDefaultRecords = false) { @@ -309,6 +316,8 @@ class TestSessionEnvironment extends Object /** * Sliented as if the file already exists by another process, we don't want * to modify. + * + * @param mixed $state */ public function saveState($state) { @@ -367,11 +376,11 @@ class TestSessionEnvironment extends Object if (SapphireTest::using_temp_db()) { $state = $this->getState(); - $dbConn = DB::getConn(); + $dbConn = DB::get_schema(); $dbExists = $dbConn->databaseExists($state->database); if($dbExists) { // Clean up temp database - $dbConn->dropDatabase(); + $dbConn->dropDatabase($state->database); file_put_contents('php://stdout', "Deleted temp database: $state->database" . PHP_EOL); } // End test session mode @@ -406,8 +415,8 @@ class TestSessionEnvironment extends Object throw new LogicException("Fixture file must be inside the tests subfolder of one of your modules."); } - $factory = Injector::inst()->create('FixtureFactory'); - $fixture = Injector::inst()->create('YamlFixture', $fixtureFile); + $factory = Injector::inst()->create('SilverStripe\\Dev\\FixtureFactory'); + $fixture = Injector::inst()->create('SilverStripe\\Dev\\YamlFixture', $fixtureFile); $fixture->writeInto($factory); $state = $this->getState(); diff --git a/code/TestSessionRequestFilter.php b/code/TestSessionRequestFilter.php index 8e78feb..88fd748 100644 --- a/code/TestSessionRequestFilter.php +++ b/code/TestSessionRequestFilter.php @@ -3,6 +3,14 @@ use SilverStripe\ORM\DataModel; use SilverStripe\ORM\FieldType\DBDatetime; use SilverStripe\ORM\DB; +use SilverStripe\Core\Injector\Injector; +use SilverStripe\Control\SS_HTTPRequest; +use SilverStripe\Control\Session; +use SilverStripe\Core\Config\Config; +use SilverStripe\Control\Director; +use SilverStripe\Control\SS_HTTPResponse; +use SilverStripe\Control\RequestFilter; + /** * Sets state previously initialized through {@link TestSessionController}. @@ -36,8 +44,8 @@ class TestSessionRequestFilter implements RequestFilter // Register mailer if (isset($testState->mailer)) { $mailer = $testState->mailer; - Injector::inst()->registerService(new $mailer(), 'Mailer'); - Config::inst()->update("Email", "send_all_emails_to", null); + Injector::inst()->registerService(new $mailer(), 'SilverStripe\\Control\\Email\\Mailer'); + Config::inst()->update("SilverStripe\\Control\\Email\\Email", "send_all_emails_to", null); } // Allows inclusion of a PHP file, usually with procedural commands diff --git a/tests/unit/TestSessionStubCodeWriterTest.php b/tests/unit/TestSessionStubCodeWriterTest.php index 727ff0a..4f2a982 100644 --- a/tests/unit/TestSessionStubCodeWriterTest.php +++ b/tests/unit/TestSessionStubCodeWriterTest.php @@ -1,4 +1,7 @@