Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
### Unreleased

### v1.2.1 (2019-11-15)

* Allow DeploymentConfig->map() to return values in standalone environment
This brings the `standalone` closer to the behaviour of other environments, except that it will
continue to return null if there is nothing mapped (where other environments will throw). `->read`
continues to return null in standalone in every case. Note that standalone will now return a value
if there's one mapped for `any` (`*`) - which is a minor breaking change to the behaviour of the
standalone environment.

### v1.2.0 (2019-11-12)

* Add Base64Url StringEncoding helper class - like base64, but with entirely websafe characters for URLs etc
Expand Down
6 changes: 2 additions & 4 deletions src/DeploymentConfig/DeploymentConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,15 +148,13 @@ public function readJSON($string)

public function map(array ...$declarations)
{
if ($this->environment === static::STANDALONE) {
return NULL;
}

$map = $this->map_parser->parse($declarations);
if (array_key_exists($this->environment, $map)) {
$value = $map[$this->environment];
} elseif (array_key_exists(static::ANY, $map)) {
$value = $map[static::ANY];
} elseif ($this->environment === static::STANDALONE) {
return NULL;
} else {
throw MissingConfigException::missingMapValue($this->environment);
}
Expand Down
32 changes: 27 additions & 5 deletions test/unit/DeploymentConfig/DeploymentConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,9 @@ public function test_its_not_environment_returns_whether_current_environment_non
* ["qa", "i-am-prod-ish"]
* ["ci", null]
* ["imagined", "who-knows-what-i-am"]
* ["standalone", "i-am-standalone"]
*/
public function test_its_map_environment_returns_value_or_default_for_the_current_env($env, $expect)
public function test_its_map_returns_value_or_default_for_the_current_env($env, $expect)
{
$subject = $this->newSubjectWithEnv($env);
$this->assertSame(
Expand All @@ -142,16 +143,25 @@ public function test_its_map_environment_returns_value_or_default_for_the_curren
['dev', 'i-am-dev'],
[['prod', 'qa'], 'i-am-prod-ish'],
['ci', NULL],
['standalone', 'i-am-standalone'],
[DeploymentConfig::ANY, 'who-knows-what-i-am']
)
);
}

public function test_its_map_returns_null_in_standalone_env()
/**
* @testWith ["dev"]
* ["standalone"]
* ["ci"]
*/
public function test_its_map_returns_any_for_env_that_is_not_defined($env)
{
$subject = $this->newSubjectWithEnv(DeploymentConfig::STANDALONE);
$this->assertNull(
$subject->map([DeploymentConfig::ANY, 'even `any` isn\'t taken'])
$subject = $this->newSubjectWithEnv($env);
$this->assertSame(
'I am anything',
$subject->map(
[DeploymentConfig::ANY, 'I am anything']
)
);
}

Expand All @@ -162,6 +172,18 @@ public function test_its_map_throws_if_no_value_defined_for_environment()
$subject->map([DeploymentConfig::PRODUCTION, 'prod']);
}

public function test_its_map_returns_null_for_standalone_if_nothing_defined()
{
$subject = $this->newSubjectWithEnv(DeploymentConfig::STANDALONE);
$this->assertSame(
NULL,
$subject->map(
[DeploymentConfig::DEV, 'I am dev'],
[DeploymentConfig::PRODUCTION, 'I am production']
)
);
}

public function test_its_map_decrypts_values()
{
$this->decrypter = new PaddedConfigDecryptStub;
Expand Down