Use environment variables for changeing deployment and releases settings

This makes the deployment configurations more flexible and easier to
reuse.
This commit is contained in:
Georg Grossberger 2015-11-27 13:11:01 +01:00
parent ac36fb29d5
commit cbf28cc1b0
2 changed files with 60 additions and 0 deletions

View file

@ -450,6 +450,13 @@ class Config
*/
public function deployment($option, $default = false)
{
// Environment variable override
$envValue = getenv('MAGE_DEPLOYMENT_' . strtoupper($option));
if ($envValue !== false) {
return $envValue;
}
// Host Config
if (is_array($this->hostConfig) && isset($this->hostConfig['deployment'])) {
if (isset($this->hostConfig['deployment'][$option])) {
@ -484,6 +491,13 @@ class Config
*/
public function release($option, $default = false)
{
// Environment variable override
$envValue = getenv('MAGE_RELEASE_' . strtoupper($option));
if ($envValue !== false) {
return $envValue;
}
// Host Config
if (is_array($this->hostConfig) && isset($this->hostConfig['releases'])) {
if (isset($this->hostConfig['releases'][$option])) {

View file

@ -0,0 +1,46 @@
<?php
namespace MageTest\Command;
use Mage\Config;
use PHPUnit_Framework_TestCase;
/**
* @group Mage_Config
*/
class ConfigTest extends PHPUnit_Framework_TestCase
{
public function testOverrideDeploymentOptionWithEnvironemntVariable()
{
$config = new Config();
$expected = 'b';
$actual = $config->deployment('a', 'b');
$this->assertSame($expected, $actual);
putenv('MAGE_DEPLOYMENT_A=c');
$expected = 'c';
$actual = $config->deployment('a', 'b');
$this->assertSame($expected, $actual);
}
public function testOverrideReleaseOptionWithEnvironemntVariable()
{
$config = new Config();
$expected = 'b';
$actual = $config->release('a', 'b');
$this->assertSame($expected, $actual);
putenv('MAGE_RELEASE_A=c');
$expected = 'c';
$actual = $config->release('a', 'b');
$this->assertSame($expected, $actual);
}
}