summaryrefslogtreecommitdiffstats
path: root/common/tests/PlanetConfigTest.php
blob: 4db6e90f4146c2cf554e517546a897a9ff406984 (plain)
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
62
63
64
65
66
67
68
69
70
71
72
73
<?php

use PHPUnit\Framework\TestCase;

class PlanetConfigTest extends TestCase
{
    public function test_default_configuration_values()
    {
        $conf = new PlanetConfig();
        $this->assertEquals('http://www.example.com/', $conf->getUrl());
    }

    public function test_merge_user_configuration_with_default_one()
    {
        $conf = new PlanetConfig(['url' => 'http://foobar.tld']);
        $this->assertEquals('http://foobar.tld', $conf->getUrl());
    }

    public function test_generic_getter()
    {
        $conf = new PlanetConfig(['foo' => 'bar']);
        $this->assertEquals('bar', $conf->foo);
    }

    public function test_generic_setter()
    {
        $conf = new PlanetConfig();
        $conf->foo = 'bar';
        $this->assertEquals('bar', $conf->foo);
    }

    public function test_normalize_key_name_on_merge()
    {
        $conf = new PlanetConfig(['FOO' => 'bar']);
        $this->assertEquals('bar', $conf->foo);
    }

    public function test_normalize_key_name_on_generic_getter()
    {
        $conf = new PlanetConfig(['foo' => 'bar']);
        $this->assertEquals('bar', $conf->FOO);
    }

    public function test_normalize_key_name_on_generic_setter()
    {
        $conf = new PlanetConfig();
        $conf->FOO = 'bar';
        $this->assertEquals('bar', $conf->foo);
    }

    public function test_to_array()
    {
        $conf = new PlanetConfig(['foo' => 'bar']);
        $this->assertEquals('bar', $conf->toArray()['foo']);
        $this->assertEquals('http://www.example.com/', $conf->toArray()['url']);
    }

    public function test_constructor_without_default_config()
    {
        $conf = new PlanetConfig(['foo' => 'bar'], false);
        $this->assertEquals('bar', $conf->foo);
        $this->assertEquals(1, sizeof($conf->toArray()));
    }

    public function test_to_yaml()
    {
        $conf = new PlanetConfig([], false);
        $this->assertEquals("---\n", $conf->toYaml());

        $conf = new PlanetConfig(['foo' => 'bar'], false);
        $this->assertEquals("---\nfoo: bar\n", $conf->toYaml());
    }
}