Implement Resettable interface on SubsiteState so it gets reset between unit tests

This commit is contained in:
Mike Cochrane 2017-10-05 04:52:53 +00:00
parent c2a81f76ae
commit a2a86c6eb1

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;
}
} }