aboutsummaryrefslogtreecommitdiff
path: root/tests/ConfigurationTest.php
blob: c2eca95cea3fe48ad0bc9f2178d4631ec1bec324 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php

declare(strict_types=1);

namespace RssBridge\Tests;

use Configuration;
use PHPUnit\Framework\TestCase;

final class ConfigurationTest extends TestCase
{
    public function testValueFromDefaultConfig()
    {
        Configuration::loadConfiguration();
        $this->assertSame(null, Configuration::getConfig('foobar', ''));
        $this->assertSame(null, Configuration::getConfig('foo', 'bar'));
        $this->assertSame('baz', Configuration::getConfig('foo', 'bar', 'baz'));
        $this->assertSame(null, Configuration::getConfig('cache', ''));
        $this->assertSame('UTC', Configuration::getConfig('system', 'timezone'));
    }

    public function testValueFromCustomConfig()
    {
        Configuration::loadConfiguration(['system' => ['timezone' => 'Europe/Berlin']]);
        $this->assertSame('Europe/Berlin', Configuration::getConfig('system', 'timezone'));
    }

    public function testValueFromEnv()
    {
        $env = [
            'RSSBRIDGE_system_timezone' => 'Europe/Berlin',
            'RSSBRIDGE_SYSTEM_MESSAGE' => 'hello',
            'RSSBRIDGE_system_enabled_bridges' => 'TwitterBridge,GettrBridge',
            'RSSBRIDGE_system_enable_debug_mode' => 'true',
            'RSSBRIDGE_fileCache_path' => '/tmp/kek',
        ];
        Configuration::loadConfiguration([], $env);
        $this->assertSame('Europe/Berlin', Configuration::getConfig('system', 'timezone'));
        $this->assertSame('hello', Configuration::getConfig('system', 'message'));
        $this->assertSame(true, Configuration::getConfig('system', 'enable_debug_mode'));
        $this->assertSame('/tmp/kek', Configuration::getConfig('FileCache', 'path'));
        $this->assertSame(['TwitterBridge', 'GettrBridge'], Configuration::getConfig('system', 'enabled_bridges'));
    }
}