streamline tests

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

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 {{{