Spaces:
Paused

File size: 1,543 Bytes
bf8c0ce
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
<?php

/**
 * Matomo - free/libre analytics platform
 *
 * @link    https://matomo.org
 * @license https://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
 */

namespace Piwik\Tests\Integration\Updater\Migration\Config;

use Piwik\Config;
use Piwik\Tests\Framework\TestCase\IntegrationTestCase;
use Piwik\Updater\Migration\Config\Set;

/**
 * @group Core
 * @group Updater
 * @group Migration
 */
class SetTest extends IntegrationTestCase
{
    public function testToString()
    {
        $config = $this->configSet('General', 'foo', 'bar');

        $this->assertSame('./console config:set --section="General" --key="foo" --value="bar"', '' . $config);
    }

    public function testExecKnownSectionKnownKey()
    {
        $this->configSet('General', 'time_before_today_archive_considered_outdated', 876)->exec();

        $general = Config::getInstance()->General;
        $this->assertEquals('876', $general['time_before_today_archive_considered_outdated']);
    }

    public function testExecKnownSectionUnknownKey()
    {
        $this->configSet('General', 'foobar', '192')->exec();
        $general = Config::getInstance()->General;
        $this->assertEquals('192', $general['foobar']);
    }

    public function testExecUnknownCategory()
    {
        $this->configSet('foobar', 'baz', 'hello')->exec();

        $baz = Config::getInstance()->foobar;
        $this->assertEquals('hello', $baz['baz']);
    }

    private function configSet($section, $key, $value)
    {
        return new Set($section, $key, $value);
    }
}