implement tests for site specific config

test that site directory config files are read correctly
correct Settings.php to pass tests
This commit is contained in:
Norbert Wagner 2021-01-11 16:38:35 +01:00
parent 998ab30bd2
commit c2b13b2f86
4 changed files with 27 additions and 14 deletions

View file

@ -146,15 +146,6 @@ class Settings implements \Iterator
$localConf = false;
if (file_exists($conf)) $localConf = require($conf);
if ( isset($this->site) )
{
$siteConf = $this->buildFileName(self::SITE);
if (file_exists($siteConf))
{
$localConf = array_replace_recursive($localConf, require($siteConf));
}
}
if (! isset($this->mode))
{ // if a localConf Mode is set use it, or take the default conf mode
$this->mode = (isset($localConf['mode'])) ? $localConf['mode'] : $this->settings['mode'];
@ -164,6 +155,15 @@ class Settings implements \Iterator
$this->settings['mode'] = $this->mode;
}
if ( isset($this->site) )
{
$siteConf = $this->buildFileName(self::SITE);
if (file_exists($siteConf))
{
$localConf = array_replace_recursive($this->settings, require($siteConf));
}
}
// load and merge Prefix.mode.conf.php
if ( isset( $modes[ $this->mode ] ) )
{

View file

@ -35,7 +35,7 @@ class SettingsTest extends TestCase
public function testLoad()
{
$cfg = $this->load('cfg');
$cfg = $this->init('cfg')->load();
$this->assertNotEmpty($cfg);
return $cfg;
}
@ -48,15 +48,24 @@ class SettingsTest extends TestCase
$this->assertEquals('test', $cfg->mode);
}
/**
*/
public function testSiteOverride()
{
$cfg = $this->init('cfg')->site('site')->load();
$this->assertEquals(42, $cfg->answer);
}
public function testTestingOverride()
{
$cfg = $this->load('cfg/testingOverride');
$cfg = $this->init('cfg/testingOverride')->load();
$this->assertEquals(42, $cfg->answer);
}
public function testLocalOverride()
{
$cfg = $this->load('cfg/localOverride');
$cfg = $this->init('cfg/localOverride')->load();
$this->assertEquals(42, $cfg->answer);
}
@ -73,7 +82,7 @@ class SettingsTest extends TestCase
$this->assertEquals($defaultName, $cfg->buildFileName());
}
private function load(string $dir)
private function init(string $dir)
{
return (new Settings())->appPath(dirname(__FILE__)."/$dir/")->load();
}

View file

@ -1,3 +1,4 @@
<?php return [
'mode' => 'test'
'mode' => 'test',
'answer' => false
];

View file

@ -0,0 +1,3 @@
<?php return [
'answer' => 42
];