Merge pull request #15 from tractorcow/pulls/3.2-api

Update for framework 3.2 compatibility
This commit is contained in:
Damian Mooyman 2014-07-21 10:38:49 +12:00
commit 69d20eade1
5 changed files with 37 additions and 37 deletions

View File

@ -7,16 +7,16 @@ php:
env:
matrix:
- DB=MYSQL CORE_RELEASE=3.1
- DB=MYSQL CORE_RELEASE=master
matrix:
include:
- php: 5.3
env: DB=PGSQL CORE_RELEASE=3.1
env: DB=PGSQL CORE_RELEASE=master
- php: 5.4
env: DB=MYSQL CORE_RELEASE=3.1
env: DB=MYSQL CORE_RELEASE=master
- php: 5.5
env: DB=MYSQL CORE_RELEASE=3.1
env: DB=MYSQL CORE_RELEASE=master
before_script:
- phpenv rehash

View File

@ -37,7 +37,7 @@ class TestSessionController extends Controller {
parent::init();
$this->extend('init');
$canAccess = (
!Director::isLive()
&& (Director::isDev() || Director::isTest() || Director::is_cli() || Permission::check("ADMIN"))
@ -59,7 +59,7 @@ class TestSessionController extends Controller {
return $this->renderWith('TestSession_start');
}
}
/**
* Start a test session. If you wish to extend how the test session is started (and add additional test state),
* then take a look at {@link TestSessionEnvironment::startTestSession()} and
@ -92,7 +92,7 @@ class TestSessionController extends Controller {
);
$this->environment->startTestSession($params, $id);
// Optionally import database
if(!empty($params['importDatabasePath'])) {
$this->environment->importDatabase(
@ -108,7 +108,7 @@ class TestSessionController extends Controller {
if($fixtureFile) {
$this->environment->loadFixtureIntoDb($fixtureFile);
}
return $this->renderWith('TestSession_inprogress');
}
@ -126,7 +126,7 @@ class TestSessionController extends Controller {
}
$sessionStates = (array)Session::get('_TestSessionController.BrowserSessionState');
foreach($newSessionStates as $k => $v) {
Session::set($k, $v);
}
@ -157,14 +157,14 @@ class TestSessionController extends Controller {
}
$fields->merge($this->getBaseFields());
$form = new Form(
$this,
$this,
'StartForm',
$fields,
new FieldList(
new FormAction('start', 'Start Session')
)
);
$this->extend('updateStartForm', $form);
return $form;
@ -176,15 +176,15 @@ class TestSessionController extends Controller {
public function ProgressForm() {
$fields = $this->getBaseFields();
$form = new Form(
$this,
$this,
'ProgressForm',
$fields,
new FieldList(
new FormAction('set', 'Set testing state')
)
);
$form->setFormAction($this->Link('set'));
$this->extend('updateProgressForm', $form);
@ -216,8 +216,8 @@ class TestSessionController extends Controller {
}
public function DatabaseName() {
$db = DB::getConn();
if(method_exists($db, 'currentDatabase')) return $db->currentDatabase();
$db = DB::get_conn();
return $db->getSelectedDatabase();
}
/**
@ -264,7 +264,7 @@ class TestSessionController extends Controller {
if(SapphireTest::using_temp_db()) {
SapphireTest::empty_temp_db();
}
if(isset($_SESSION['_testsession_codeblocks'])) {
unset($_SESSION['_testsession_codeblocks']);
}
@ -292,7 +292,7 @@ class TestSessionController extends Controller {
foreach($sessionStates as $k => $v) {
Session::clear($k);
}
Session::clear('_TestSessionController');
Session::clear('_TestSessionController');
}
@ -332,17 +332,17 @@ class TestSessionController extends Controller {
/**
* Get all *.sql database files located in a specific path,
* keyed by their file name.
*
*
* @param String $path Absolute folder path
* @return array
*/
protected function getDatabaseTemplates($path = null) {
$templates = array();
if(!$path) {
$path = $this->config()->database_templates_path;
}
// TODO Remove once we can set BASE_PATH through the config layer
if($path && !Director::is_absolute($path)) {
$path = BASE_PATH . '/' . $path;

View File

@ -12,7 +12,7 @@
*
* An environment can have an optional identifier ({@link id}), which allows
* multiple environments to exist at the same time in the same webroot.
* This enables parallel testing with (mostly) isolated state.
* This enables parallel testing with (mostly) isolated state.
*
* For a valid test session to exist, this needs to contain at least:
* - database: The alternate database name that is being used for this test session (e.g. ss_tmpdb_1234567)
@ -25,7 +25,7 @@
* See {@link $state} for default information stored in the test session.
*/
class TestSessionEnvironment extends Object {
/**
* @var int Optional identifier for the session.
*/
@ -69,9 +69,9 @@ class TestSessionEnvironment extends Object {
*/
public function getFilePath() {
if($this->id) {
$path = Director::getAbsFile(sprintf($this->config()->test_state_id_file, $this->id));
$path = Director::getAbsFile(sprintf($this->config()->test_state_id_file, $this->id));
} else {
$path = Director::getAbsFile($this->config()->test_state_file);
$path = Director::getAbsFile($this->config()->test_state_file);
}
return $path;
@ -174,7 +174,7 @@ class TestSessionEnvironment extends Object {
// ensure we have a connection to the database
if(isset($state->database) && $state->database) {
if(!DB::getConn()) {
if(!DB::get_conn()) {
// No connection, so try and connect to tmpdb if it exists
if(isset($state->database)) {
$this->oldDatabaseName = $databaseConfig['database'];
@ -185,7 +185,7 @@ class TestSessionEnvironment extends Object {
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::getConn()->currentDatabase();
$db = DB::get_conn()->getSelectedDatabase();
if(isset($state->database) && $db != $state->database) {
$this->oldDatabaseName = $databaseConfig['database'];
$databaseConfig['database'] = $state->database;
@ -199,7 +199,7 @@ class TestSessionEnvironment extends Object {
$dbName = (isset($state->database)) ? $state->database : null;
if($dbName) {
$dbExists = DB::getConn()->databaseExists($dbName);
$dbExists = DB::get_conn()->databaseExists($dbName);
} else {
$dbExists = false;
}
@ -290,7 +290,7 @@ class TestSessionEnvironment extends Object {
}
/**
* Sliented as if the file already exists by another process, we don't want
* Sliented as if the file already exists by another process, we don't want
* to modify.
*/
public function saveState($state) {
@ -393,10 +393,10 @@ class TestSessionEnvironment extends Object {
$databaseConfig['database'] = $this->oldDatabaseName;
$conn = DB::getConn();
$conn = DB::get_conn();
if($conn) {
$conn->selectDatabase($this->oldDatabaseName);
$conn->selectDatabase($this->oldDatabaseName, false, false);
}
}
}

View File

@ -2,7 +2,7 @@
/**
* Sets state previously initialized through {@link TestSessionController}.
*/
class TestSessionRequestFilter {
class TestSessionRequestFilter implements RequestFilter {
/**
* @var TestSessionEnvironment
@ -12,8 +12,8 @@ class TestSessionRequestFilter {
public function __construct() {
$this->testSessionEnvironment = Injector::inst()->get('TestSessionEnvironment');
}
public function preRequest($req, $session, $model) {
public function preRequest(SS_HTTPRequest $request, Session $session, DataModel $model) {
if(!$this->testSessionEnvironment->isRunningTests()) return;
$testState = $this->testSessionEnvironment->getState();
@ -46,9 +46,9 @@ class TestSessionRequestFilter {
}
}
public function postRequest() {
public function postRequest(SS_HTTPRequest $request, SS_HTTPResponse $response, DataModel $model) {
if(!$this->testSessionEnvironment->isRunningTests()) return;
// Store PHP session
$state = $this->testSessionEnvironment->getState();
$state->session = Session::get_all();

View File

@ -14,7 +14,7 @@
"require": {
"php": ">=5.3.2",
"composer/installers": "*",
"silverstripe/framework": ">=3.1,<3.2"
"silverstripe/framework": "~3.2"
},
"minimum-stability": "dev"
}