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
{
public function testConstruct()
{
$cfg = new Settings();
$this->assertNotEmpty($cfg);
return $cfg;
}
/**
* @depends testConstruct
*/
public function testLoadNoFile(Settings $cfg)
public function testLoadNoFile()
{
$cfg = new Settings();
$this->expectException(\ErrorException::class);
$cfg->load();
}
/**
*/
private function appPath(Settings $cfg, ?string $dir='')
private function appPath(Settings $cfg, string $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();
$this->assertNotEmpty($cfg);
return $cfg;
@ -71,44 +69,49 @@ class SettingsTest extends TestCase
*/
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();
$this->assertEquals('default', $cfg->testFiles);
$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);
}
/**
* @depends testConstruct
*/
public function testLocalOverride(Settings $cfg)
public function testLocalOverride()
{
$cfg = new Settings();
$cfg = $this->appPath($cfg, 'localOverride')->load();
$this->assertEquals(42, $cfg->answer);
}
/**
* @depends testConstruct
* @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/';
$cfg = new Settings();
$cfg->appPath('./');
if ($prefix !== '') $cfg->prefix($prefix);
if ($site !== '')

View File

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

View File

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