mirror of
https://github.com/silverstripe/silverstripe-testsession
synced 2024-10-22 14:06:00 +02:00
Coupling environment with PHP session info, avoids injector troubles
I'd rather have Session::get('TestSessionId') being passed in as an identifier, but the env object is passed around so much as a singleton that its easy to forget that argument, and cause hard to debug errors. We need a global "app" object which all other objects can reference somehow.
This commit is contained in:
parent
808d6aa87a
commit
2b5984a73c
@ -30,7 +30,7 @@ class TestSessionController extends Controller {
|
|||||||
public function __construct() {
|
public function __construct() {
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
|
|
||||||
$this->environment = Injector::inst()->get('TestSessionEnvironment', Session::get('TestSessionId'));
|
$this->environment = Injector::inst()->get('TestSessionEnvironment');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function init() {
|
public function init() {
|
||||||
|
@ -54,7 +54,12 @@ class TestSessionEnvironment extends Object {
|
|||||||
public function __construct($id = null) {
|
public function __construct($id = null) {
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
|
|
||||||
$this->id = $id;
|
if($id) {
|
||||||
|
$this->id = $id;
|
||||||
|
} else {
|
||||||
|
Session::start();
|
||||||
|
$this->id = Session::get('TestSessionId');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -75,6 +80,20 @@ class TestSessionEnvironment extends Object {
|
|||||||
return(file_exists($this->getFilePath()));
|
return(file_exists($this->getFilePath()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param String $id
|
||||||
|
*/
|
||||||
|
public function setId($id) {
|
||||||
|
$this->id = $id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return String
|
||||||
|
*/
|
||||||
|
public function getId() {
|
||||||
|
return $this->id;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a temp database, sets up any extra requirements, and writes the state file. The database will be
|
* Creates a temp database, sets up any extra requirements, and writes the state file. The database will be
|
||||||
* connected to as part of {@link self::applyState()}, so if you're continuing script execution after calling this
|
* connected to as part of {@link self::applyState()}, so if you're continuing script execution after calling this
|
||||||
|
@ -10,10 +10,7 @@ class TestSessionRequestFilter {
|
|||||||
protected $testSessionEnvironment;
|
protected $testSessionEnvironment;
|
||||||
|
|
||||||
public function __construct() {
|
public function __construct() {
|
||||||
$this->testSessionEnvironment = Injector::inst()->get(
|
$this->testSessionEnvironment = Injector::inst()->get('TestSessionEnvironment');
|
||||||
'TestSessionEnvironment',
|
|
||||||
Session::get('TestSessionId')
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function preRequest($req, $session, $model) {
|
public function preRequest($req, $session, $model) {
|
||||||
|
Loading…
Reference in New Issue
Block a user