Skip to content

Commit

Permalink
Allow lithium\Environment::reset() to remove a specific env only fo…
Browse files Browse the repository at this point in the history
…r testing purpose.
  • Loading branch information
jails committed Oct 2, 2013
1 parent ea0d43b commit 8b2050b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
8 changes: 6 additions & 2 deletions core/Environment.php
Expand Up @@ -117,9 +117,13 @@ class Environment {
* environment, removing any environment-specific configurations, and removing the custom
* environment detector, if any has been specified.
*
* @return void
* @param $env If set, delete the defined environment only.
*/
public static function reset() {
public static function reset($env = null) {
if ($env) {
unset(static::$_configurations[$env]);
return;
}
static::$_current = '';
static::$_detector = null;
static::$_configurations = array(
Expand Down
18 changes: 17 additions & 1 deletion tests/cases/core/EnvironmentTest.php
Expand Up @@ -166,7 +166,7 @@ public function testDetectionWithArrayMap() {
/**
* Tests resetting the `Environment` class to its default state.
*/
public function testReset() {
public function testResetAll() {
Environment::set('test', array('foo' => 'bar'));
Environment::set('test');
$this->assertEqual('test', Environment::get());
Expand All @@ -177,6 +177,22 @@ public function testReset() {
$this->assertNull(Environment::get('foo'));
}

public function testResetASpecificEnv() {
Environment::set('test', array('foo' => 'bar'));
Environment::set('development', array('hello' => 'world'));

Environment::set('test');
$this->assertEqual('test', Environment::get());
$this->assertEqual('bar', Environment::get('foo'));

Environment::reset('test');
$this->assertEqual('test', Environment::get());
$this->assertNull(Environment::get('foo'));

Environment::set('development');
$this->assertEqual('world', Environment::get('hello'));
}

/**
* Tests using a custom detector to get the current environment.
*/
Expand Down

0 comments on commit 8b2050b

Please sign in to comment.