Implemented a unit test for loading environment variables through config files.
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
Config files may now have a 'lock' key. If a config file has such a key, ConfigORM will refuse to commit changes. This allows the developer to use Core::getEnv() in config files, without risk of it being overwritten by a commit.
This commit is contained in:
parent
eec9eda22d
commit
7a899e33d7
@ -88,6 +88,10 @@ class ConfigORM extends ConfigORMAbstract
|
||||
*/
|
||||
public function commit(): bool
|
||||
{
|
||||
// If config has a lock file, don't write
|
||||
if (isset($this->cfg['lock']))
|
||||
throw new ConfigException("Could not write config file. $this->file is locked with the 'lock' key.");
|
||||
|
||||
// Write the changes
|
||||
if (is_writable($this->file)) {
|
||||
$config = var_export($this->cfg, true);
|
||||
|
@ -0,0 +1,42 @@
|
||||
<?php
|
||||
/**
|
||||
* FuzeWorks Framework Core.
|
||||
*
|
||||
* The FuzeWorks PHP FrameWork
|
||||
*
|
||||
* Copyright (C) 2013-2019 TechFuze
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
* @author TechFuze
|
||||
* @copyright Copyright (c) 2013 - 2019, TechFuze. (http://techfuze.net)
|
||||
* @license https://opensource.org/licenses/MIT MIT License
|
||||
*
|
||||
* @link http://techfuze.net/fuzeworks
|
||||
* @since Version 1.2.0
|
||||
*
|
||||
* @version Version 1.2.0
|
||||
*/
|
||||
|
||||
use FuzeWorks\Core;
|
||||
|
||||
return array(
|
||||
'testKey' => Core::getEnv('TESTKEY'),
|
||||
'otherKey' => Core::getEnv('OTHERKEY', 'somethingDefault')
|
||||
);
|
@ -190,4 +190,20 @@ class configTest extends CoreTestAbstract
|
||||
$this->assertEquals($config2->key, 'other_value');
|
||||
}
|
||||
|
||||
/**
|
||||
* @coversNothing
|
||||
*/
|
||||
public function testConfigWithEnvironmentVariables()
|
||||
{
|
||||
// First push the test variable
|
||||
putenv('TESTKEY=Superb');
|
||||
|
||||
// Load the config
|
||||
$config = $this->config->getConfig('testconfigwithenvironment', ['test'.DS.'config'.DS.'TestConfigWithEnvironment']);
|
||||
|
||||
// Check values
|
||||
$this->assertEquals('Superb', $config->get('testKey'));
|
||||
$this->assertEquals('somethingDefault', $config->get('otherKey'));
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user