aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/utils/FakeConfigManager.php
blob: 014c2af0d8f1ae3179ad3d591cc494710bef6737 (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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php

namespace Shaarli;

use Shaarli\Config\ConfigManager;

/**
 * Fake ConfigManager
 */
class FakeConfigManager extends ConfigManager
{
    protected $values = [];

    /**
     * Initialize with test values
     *
     * @param array $values Initial values
     */
    public function __construct($values = [])
    {
        $this->values = $values;
    }

    /**
     * Set a given value
     *
     * @param string $key   Key of the value to set
     * @param mixed  $value Value to set
     */
    public function set($key, $value, $write = false, $isLoggedIn = false)
    {
        $this->values[$key] = $value;
    }

    /**
     * Get a given configuration value
     *
     * @param string $key Index of the value to retrieve
     *
     * @return mixed The value if set, else the name of the key
     */
    public function get($key, $default = '')
    {
        if (isset($this->values[$key])) {
            return $this->values[$key];
        }
        return $key;
    }

    /**
     * Check if a setting exists
     *
     * @param string $setting Asked setting, keys separated with dots
     *
     * @return bool true if the setting exists, false otherwise
     */
    public function exists($setting)
    {
        return array_key_exists($setting, $this->values);
    }
}