reorganize tests once again and make sure the write conf files are loaded

This commit is contained in:
Norbert Wagner 2021-01-14 08:58:14 +01:00
parent 6d3158a5c7
commit 0b3957a2de
5 changed files with 24 additions and 19 deletions

View File

@ -27,26 +27,24 @@ use PHPUnit\Framework\TestCase;
class SettingsTest extends TestCase class SettingsTest extends TestCase
{ {
public function testConstruct() public function testConstruct()
{ {
$cfg = new Settings(); $cfg = new Settings();
$this->assertNotEmpty($cfg); $this->assertNotEmpty($cfg);
return $cfg;
} }
/** /**
* @depends testConstruct
*/ */
public function testLoadNoFile(Settings $cfg) public function testLoadNoFile()
{ {
$cfg = new Settings();
$this->expectException(\ErrorException::class); $this->expectException(\ErrorException::class);
$cfg->load(); $cfg->load();
} }
/** /**
*/ */
private function appPath(Settings $cfg, ?string $dir='') private function appPath(Settings $cfg, string $dir='')
{ {
if (isset($dir)) $dir .= '/'; if (isset($dir)) $dir .= '/';
@ -57,10 +55,10 @@ class SettingsTest extends TestCase
} }
/** /**
* @depends testConstruct
*/ */
public function testLoad(Settings $cfg) public function testLoad()
{ {
$cfg = new Settings();
$cfg = $this->appPath($cfg)->load(); $cfg = $this->appPath($cfg)->load();
$this->assertNotEmpty($cfg); $this->assertNotEmpty($cfg);
return $cfg; return $cfg;
@ -71,44 +69,49 @@ class SettingsTest extends TestCase
*/ */
public function testMode(Settings $cfg) public function testMode(Settings $cfg)
{ {
$this->assertEquals('test', $cfg->mode); $this->assertEquals('default', $cfg->testFiles);
$this->assertEquals('prod', $cfg->mode);
} }
/** /**
* @depends testConstruct
*/ */
public function testSiteOverride(Settings $cfg) public function testSiteOverride()
{ {
$cfg = new Settings();
$cfg = $this->appPath($cfg)->site('site')->load(); $cfg = $this->appPath($cfg)->site('site')->load();
$this->assertEquals('default', $cfg->testFiles);
$this->assertEquals(42, $cfg->answer); $this->assertEquals(42, $cfg->answer);
} }
/** /**
* @depends testConstruct
*/ */
public function testTestingOverride(Settings $cfg) public function testTestingOverride()
{ {
$cfg = $this->appPath($cfg, 'testingOverride')->load(); $cfg = new Settings();
$cfg = $this->appPath($cfg, 'testing')->load();
$this->assertEquals('testing', $cfg->testFiles);
$this->assertEquals(42, $cfg->answer); $this->assertEquals(42, $cfg->answer);
} }
/** /**
* @depends testConstruct
*/ */
public function testLocalOverride(Settings $cfg) public function testLocalOverride()
{ {
$cfg = new Settings();
$cfg = $this->appPath($cfg, 'localOverride')->load(); $cfg = $this->appPath($cfg, 'localOverride')->load();
$this->assertEquals(42, $cfg->answer); $this->assertEquals(42, $cfg->answer);
} }
/** /**
* @depends testConstruct
* @dataProvider fileNameData * @dataProvider fileNameData
*/ */
public function testBuildFileName(string $prefix, $type, string $site, string $expected, Settings $cfg) public function testBuildFileName(string $prefix, $type, string $site, string $expected)
{ {
$path = './config/'; $path = './config/';
$cfg = new Settings();
$cfg->appPath('./'); $cfg->appPath('./');
if ($prefix !== '') $cfg->prefix($prefix); if ($prefix !== '') $cfg->prefix($prefix);
if ($site !== '') if ($site !== '')

View File

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

View File

@ -1,4 +1,5 @@
<?php return [ <?php return [
'mode' => 'prod', 'mode' => 'prod',
'testFiles' => 'testing',
'answer' => false 'answer' => false
]; ];