streamline tests

This commit is contained in:
Norbert Wagner 2021-01-12 16:16:44 +01:00
parent c2b13b2f86
commit 20f962b26d
2 changed files with 46 additions and 20 deletions

View File

@ -62,8 +62,8 @@ class Settings implements \Iterator
// appPath() {{{
/** {{{
* Sets the application path where the config/ dirtectory is located
* If the package path is not set it is set to the appPath
*
* If the package path is not set, it is set to the appPath
* @param string $path
*///}}}
public function appPath( string $path )
{
@ -75,7 +75,7 @@ class Settings implements \Iterator
// pkgPath() {{{
/** {{{
* Sets the package path where the config/ dirtectory for the default and mode files is located
*
* @param string $path
*///}}}
public function pkgPath( string $path )
{

View File

@ -27,15 +27,40 @@ use PHPUnit\Framework\TestCase;
class SettingsTest extends TestCase
{
public function testLoadNoFile()
public function testConstruct()
{
$this->expectException(\ErrorException::class);
(new Settings())->load();
$cfg = new Settings();
$this->assertNotEmpty($cfg);
return $cfg;
}
public function testLoad()
/**
* @depends testConstruct
*/
public function testLoadNoFile(Settings $cfg)
{
$cfg = $this->init('cfg')->load();
$this->expectException(\ErrorException::class);
$cfg->load();
}
/**
*/
private function appPath(Settings $cfg, ?string $dir='')
{
if (isset($dir)) $dir .= '/';
$path = dirname(__FILE__).'/cfg/'.$dir;
$cfg->appPath($path);
return $cfg;
}
/**
* @depends testConstruct
*/
public function testLoad(Settings $cfg)
{
$cfg = $this->appPath($cfg)->load();
$this->assertNotEmpty($cfg);
return $cfg;
}
@ -49,23 +74,29 @@ class SettingsTest extends TestCase
}
/**
* @depends testConstruct
*/
public function testSiteOverride()
public function testSiteOverride(Settings $cfg)
{
$cfg = $this->init('cfg')->site('site')->load();
$cfg = $this->appPath($cfg)->site('site')->load();
$this->assertEquals(42, $cfg->answer);
}
public function testTestingOverride()
/**
* @depends testConstruct
*/
public function testTestingOverride(Settings $cfg)
{
$cfg = $this->init('cfg/testingOverride')->load();
$cfg = $this->appPath($cfg, 'testingOverride')->load();
$this->assertEquals(42, $cfg->answer);
}
public function testLocalOverride()
/**
* @depends testConstruct
*/
public function testLocalOverride(Settings $cfg)
{
$cfg = $this->init('cfg/localOverride')->load();
$cfg = $this->appPath($cfg, 'localOverride')->load();
$this->assertEquals(42, $cfg->answer);
}
@ -81,11 +112,6 @@ class SettingsTest extends TestCase
$this->assertEquals($defaultName, $cfg->buildFileName());
}
private function init(string $dir)
{
return (new Settings())->appPath(dirname(__FILE__)."/$dir/")->load();
}
}
/* jEdit buffer local properties {{{