Skip to content

Commit

Permalink
Merge pull request #321 from mikenz/resetable-state
Browse files Browse the repository at this point in the history
Implement Resettable interface on SubsiteState so it gets reset between unit tests
  • Loading branch information
dhensby authored Oct 5, 2017
2 parents 4a1f571 + a2a86c6 commit 0157bd0
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/State/SubsiteState.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@

use SilverStripe\Core\Injector\Injectable;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\Core\Resettable;

/**
* SubsiteState provides static access to the current state for subsite related data during a request
*/
class SubsiteState
class SubsiteState implements Resettable
{
use Injectable;

Expand Down Expand Up @@ -106,4 +107,22 @@ public function withState(callable $callback)
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;
}
}

0 comments on commit 0157bd0

Please sign in to comment.