Skip to content

Commit 9264f6d

Browse files
authored
Merge pull request #17 from ingenerator/feat/1.x/allow-standalone-val
Allow DeploymentConfig->map() to return values in standalone environment
2 parents 93273ff + 8cd3cd5 commit 9264f6d

File tree

3 files changed

+38
-9
lines changed

3 files changed

+38
-9
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
### Unreleased
22

3+
### v1.2.1 (2019-11-15)
4+
5+
* Allow DeploymentConfig->map() to return values in standalone environment
6+
This brings the `standalone` closer to the behaviour of other environments, except that it will
7+
continue to return null if there is nothing mapped (where other environments will throw). `->read`
8+
continues to return null in standalone in every case. Note that standalone will now return a value
9+
if there's one mapped for `any` (`*`) - which is a minor breaking change to the behaviour of the
10+
standalone environment.
11+
312
### v1.2.0 (2019-11-12)
413

514
* Add Base64Url StringEncoding helper class - like base64, but with entirely websafe characters for URLs etc

src/DeploymentConfig/DeploymentConfig.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,15 +148,13 @@ public function readJSON($string)
148148

149149
public function map(array ...$declarations)
150150
{
151-
if ($this->environment === static::STANDALONE) {
152-
return NULL;
153-
}
154-
155151
$map = $this->map_parser->parse($declarations);
156152
if (array_key_exists($this->environment, $map)) {
157153
$value = $map[$this->environment];
158154
} elseif (array_key_exists(static::ANY, $map)) {
159155
$value = $map[static::ANY];
156+
} elseif ($this->environment === static::STANDALONE) {
157+
return NULL;
160158
} else {
161159
throw MissingConfigException::missingMapValue($this->environment);
162160
}

test/unit/DeploymentConfig/DeploymentConfigTest.php

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,9 @@ public function test_its_not_environment_returns_whether_current_environment_non
132132
* ["qa", "i-am-prod-ish"]
133133
* ["ci", null]
134134
* ["imagined", "who-knows-what-i-am"]
135+
* ["standalone", "i-am-standalone"]
135136
*/
136-
public function test_its_map_environment_returns_value_or_default_for_the_current_env($env, $expect)
137+
public function test_its_map_returns_value_or_default_for_the_current_env($env, $expect)
137138
{
138139
$subject = $this->newSubjectWithEnv($env);
139140
$this->assertSame(
@@ -142,16 +143,25 @@ public function test_its_map_environment_returns_value_or_default_for_the_curren
142143
['dev', 'i-am-dev'],
143144
[['prod', 'qa'], 'i-am-prod-ish'],
144145
['ci', NULL],
146+
['standalone', 'i-am-standalone'],
145147
[DeploymentConfig::ANY, 'who-knows-what-i-am']
146148
)
147149
);
148150
}
149151

150-
public function test_its_map_returns_null_in_standalone_env()
152+
/**
153+
* @testWith ["dev"]
154+
* ["standalone"]
155+
* ["ci"]
156+
*/
157+
public function test_its_map_returns_any_for_env_that_is_not_defined($env)
151158
{
152-
$subject = $this->newSubjectWithEnv(DeploymentConfig::STANDALONE);
153-
$this->assertNull(
154-
$subject->map([DeploymentConfig::ANY, 'even `any` isn\'t taken'])
159+
$subject = $this->newSubjectWithEnv($env);
160+
$this->assertSame(
161+
'I am anything',
162+
$subject->map(
163+
[DeploymentConfig::ANY, 'I am anything']
164+
)
155165
);
156166
}
157167

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

175+
public function test_its_map_returns_null_for_standalone_if_nothing_defined()
176+
{
177+
$subject = $this->newSubjectWithEnv(DeploymentConfig::STANDALONE);
178+
$this->assertSame(
179+
NULL,
180+
$subject->map(
181+
[DeploymentConfig::DEV, 'I am dev'],
182+
[DeploymentConfig::PRODUCTION, 'I am production']
183+
)
184+
);
185+
}
186+
165187
public function test_its_map_decrypts_values()
166188
{
167189
$this->decrypter = new PaddedConfigDecryptStub;

0 commit comments

Comments
 (0)