Merge pull request #321 from mikenz/resetable-state

Implement Resettable interface on SubsiteState so it gets reset between unit tests
This commit is contained in:
Daniel Hensby 2017-10-05 17:22:56 +01:00 committed by GitHub
commit 0157bd0c05

View File

@ -4,11 +4,12 @@ namespace SilverStripe\Subsites\State;
use SilverStripe\Core\Injector\Injectable; use SilverStripe\Core\Injector\Injectable;
use SilverStripe\Core\Injector\Injector; use SilverStripe\Core\Injector\Injector;
use SilverStripe\Core\Resettable;
/** /**
* SubsiteState provides static access to the current state for subsite related data during a request * SubsiteState provides static access to the current state for subsite related data during a request
*/ */
class SubsiteState class SubsiteState implements Resettable
{ {
use Injectable; use Injectable;
@ -106,4 +107,22 @@ class SubsiteState
Injector::inst()->registerService($this); Injector::inst()->registerService($this);
} }
} }
/**
* Reset the local cache of the singleton
*/
public static function reset()
{
SubsiteState::singleton()->resetState();
}
/**
* Reset the local cache of this object
*/
public function resetState()
{
$this->originalSubsiteId = null;
$this->subsiteId = null;
$this->useSessions = null;
}
} }