Using instance reference for TestSessionEnv

This commit is contained in:
Ingo Schommer 2014-02-09 18:33:43 +13:00
parent cd5ac2c752
commit 3a4cb71808
1 changed files with 20 additions and 9 deletions

View File

@ -21,6 +21,17 @@ class TestSessionController extends Controller {
*/ */
private static $database_templates_path; private static $database_templates_path;
/**
* @var TestSessionEnvironment
*/
protected $environment;
public function __construct() {
parent::__construct();
$this->environment = Injector::inst()->get('TestSessionEnvironment');
}
public function init() { public function init() {
parent::init(); parent::init();
@ -41,7 +52,7 @@ class TestSessionController extends Controller {
} }
public function index() { public function index() {
if(Injector::inst()->get('TestSessionEnvironment')->isRunningTests()) { if($this->environment->isRunningTests()) {
return $this->renderWith('TestSession_inprogress'); return $this->renderWith('TestSession_inprogress');
} else { } else {
return $this->renderWith('TestSession_start'); return $this->renderWith('TestSession_start');
@ -71,7 +82,7 @@ class TestSessionController extends Controller {
) )
); );
Injector::inst()->get('TestSessionEnvironment')->startTestSession($params); $this->environment->startTestSession($params);
return $this->renderWith('TestSession_inprogress'); return $this->renderWith('TestSession_inprogress');
} }
@ -127,7 +138,7 @@ class TestSessionController extends Controller {
} }
protected function getBaseFields() { protected function getBaseFields() {
$testState = Injector::inst()->get('TestSessionEnvironment')->getState(); $testState = $this->environment->getState();
$fields = new FieldList( $fields = new FieldList(
$textfield = new TextField('fixture', 'Fixture YAML file path'), $textfield = new TextField('fixture', 'Fixture YAML file path'),
@ -162,7 +173,7 @@ class TestSessionController extends Controller {
* @throws LogicException * @throws LogicException
*/ */
public function set() { public function set() {
if(!Injector::inst()->get('TestSessionEnvironment')->isRunningTests()) { if(!$this->environment->isRunningTests()) {
throw new LogicException("No test session in progress."); throw new LogicException("No test session in progress.");
} }
@ -183,13 +194,13 @@ class TestSessionController extends Controller {
) )
); );
Injector::inst()->get('TestSessionEnvironment')->updateTestSession($params); $this->environment->updateTestSession($params);
return $this->renderWith('TestSession_inprogress'); return $this->renderWith('TestSession_inprogress');
} }
public function clear() { public function clear() {
if(!Injector::inst()->get('TestSessionEnvironment')->isRunningTests()) { if(!$this->environment->isRunningTests()) {
throw new LogicException("No test session in progress."); throw new LogicException("No test session in progress.");
} }
@ -214,11 +225,11 @@ class TestSessionController extends Controller {
* is there. * is there.
*/ */
public function end() { public function end() {
if(!Injector::inst()->get('TestSessionEnvironment')->isRunningTests()) { if(!$this->environment->isRunningTests()) {
throw new LogicException("No test session in progress."); throw new LogicException("No test session in progress.");
} }
Injector::inst()->get('TestSessionEnvironment')->endTestSession(); $this->environment->endTestSession();
return $this->renderWith('TestSession_end'); return $this->renderWith('TestSession_end');
} }
@ -239,7 +250,7 @@ class TestSessionController extends Controller {
* @return ArrayList * @return ArrayList
*/ */
public function getState() { public function getState() {
$stateObj = Injector::inst()->get('TestSessionEnvironment')->getState(); $stateObj = $this->environment->getState();
$state = array(); $state = array();
// Convert the stdObject of state into ArrayData // Convert the stdObject of state into ArrayData