From 20f962b26d98ce78fc6c41177946bd63552f4b5b Mon Sep 17 00:00:00 2001 From: Norbert Wagner Date: Tue, 12 Jan 2021 16:16:44 +0100 Subject: [PATCH] streamline tests --- src/Settings.php | 6 ++--- tests/SettingsTest.php | 60 ++++++++++++++++++++++++++++++------------ 2 files changed, 46 insertions(+), 20 deletions(-) diff --git a/src/Settings.php b/src/Settings.php index a5b8945..7519d5c 100644 --- a/src/Settings.php +++ b/src/Settings.php @@ -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 ) { diff --git a/tests/SettingsTest.php b/tests/SettingsTest.php index 44ff92e..047e333 100644 --- a/tests/SettingsTest.php +++ b/tests/SettingsTest.php @@ -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 {{{