fix: case-insensitive config from env, fix #2935 (#2973)

* refactor

* fix: case-sensitive config from env, fix #2935

* lowercase all config section and keys

* test: add test for case-insensitivity
This commit is contained in:
Dag 2022-08-23 21:19:53 +02:00 committed by GitHub
parent edbafc6144
commit 5165ea265d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 78 additions and 161 deletions

View file

@ -9,17 +9,30 @@ use PHPUnit\Framework\TestCase;
final class ConfigurationTest extends TestCase
{
public function test()
public function testValueFromDefaultConfig()
{
putenv('RSSBRIDGE_system_timezone=Europe/Berlin');
Configuration::loadConfiguration();
// test nonsense
$this->assertSame(null, Configuration::getConfig('foobar', ''));
$this->assertSame(null, Configuration::getConfig('foo', 'bar'));
$this->assertSame(null, Configuration::getConfig('cache', ''));
$this->assertSame('UTC', Configuration::getConfig('system', 'timezone'));
}
// test value from env
public function testValueFromCustomConfig()
{
Configuration::loadConfiguration(['system' => ['timezone' => 'Europe/Berlin']]);
$this->assertSame('Europe/Berlin', Configuration::getConfig('system', 'timezone'));
}
public function testValueFromEnv()
{
putenv('RSSBRIDGE_system_timezone=Europe/Berlin');
putenv('RSSBRIDGE_TwitterV2Bridge_twitterv2apitoken=aaa');
putenv('RSSBRIDGE_SQLiteCache_file=bbb');
Configuration::loadConfiguration([], getenv());
$this->assertSame('Europe/Berlin', Configuration::getConfig('system', 'timezone'));
$this->assertSame('aaa', Configuration::getConfig('TwitterV2Bridge', 'twitterv2apitoken'));
$this->assertSame('bbb', Configuration::getConfig('SQLiteCache', 'file'));
$this->assertSame('bbb', Configuration::getConfig('sqlitecache', 'file'));
}
}