Util_Settings/tests/SettingsTest.php

93 lines
2.2 KiB
PHP

<?php
/* {{{ Copyright and License Notice
*
* Copyright © 2021 RaBe Websolutions
*
* This file is part of rabe/Util-Settings.
*
* rabe/Util-Settings is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* rabe/Util-Settings is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with rabe/Util-Settings. If not, see <https://www.gnu.org/licenses/>.
*
*///}}}
declare(strict_types=1);
namespace rabe\Util\tests;
use rabe\Util\Settings;
use PHPUnit\Framework\TestCase;
class SettingsTest extends TestCase
{
public function testLoadNoFile()
{
$this->expectException(\ErrorException::class);
(new Settings())->load();
}
public function testLoad()
{
$cfg = $this->init('cfg')->load();
$this->assertNotEmpty($cfg);
return $cfg;
}
/**
* @depends testLoad
*/
public function testMode(Settings $cfg)
{
$this->assertEquals('test', $cfg->mode);
}
/**
*/
public function testSiteOverride()
{
$cfg = $this->init('cfg')->site('site')->load();
$this->assertEquals(42, $cfg->answer);
}
public function testTestingOverride()
{
$cfg = $this->init('cfg/testingOverride')->load();
$this->assertEquals(42, $cfg->answer);
}
public function testLocalOverride()
{
$cfg = $this->init('cfg/localOverride')->load();
$this->assertEquals(42, $cfg->answer);
}
public function testBuildFileName()
{
$path = './config/';
$prefix = '';
$postfix = 'conf.php';
$type = '';
$defaultName = "$path$prefix$type$postfix";
$cfg = new Settings();
$this->assertEquals($defaultName, $cfg->buildFileName());
}
private function init(string $dir)
{
return (new Settings())->appPath(dirname(__FILE__)."/$dir/")->load();
}
}
/* jEdit buffer local properties {{{
* :folding=explicit:collapseFolds=1:
}}}*/