Passed
Pull Request — master (#54)
by Alexander
12:39
created

ParamsConfigTest::getDefaultConfigName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
c 0
b 0
f 0
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Composer\Config\Tests\Integration\Tests\Config;
6
7
use stdClass;
8
use Yiisoft\Composer\Config\Tests\Integration\Tests\Helper\LiterallyCallback;
9
10
final class ParamsConfigTest extends ConfigTest
11
{
12
    public function configProvider(): array
13
    {
14
        return [
15
            ['boolean parameter', true],
16
            ['string parameter', 'value of param 1'],
17
            ['NAN parameter', 'NAN'],
18
            ['float parameter', 1.0000001],
19
            ['int parameter', 123],
20
            ['long int parameter', 123_000],
0 ignored issues
show
Bug introduced by
The constant Yiisoft\Composer\Config\...on\Tests\Config\123_000 was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
21
            ['array parameter', [
22
                'changed value' => 'from root config',
23
                'first-vendor/first-package' => true,
24
                'first-vendor/second-package' => true,
25
                'second-vendor/first-package' => true,
26
                'second-vendor/second-package' => true,
27
                [[[[[]]]]],
28
            ]],
29
            ['array parameter with UnsetArrayValue', [
30
                'first-vendor/second-package' => true,
31
                'second-vendor/first-package' => true,
32
                'second-vendor/second-package' => true,
33
            ]],
34
            ['array parameter with ReplaceArrayValue', ['replace']],
35
            ['array parameter with RemoveArrayKeys', [
36
                'first-vendor/first-package',
37
                'first-vendor/second-package',
38
                'second-vendor/first-package',
39
                'second-vendor/second-package',
40
                'root value',
41
            ]],
42
            [
43
                'callable parameter',
44
                new LiterallyCallback(function () {
45
                    return 'I am callable';
46
                }),
47
            ],
48
            [
49
                'static callable parameter',
50
                new LiterallyCallback(static function () {
51
                    return 'I am callable';
52
                }),
53
            ],
54
            ['object parameter', new stdClass()],
55
            /**
56
             * Test for subpackages parameters
57
             */
58
            ['first-vendor/first-package', true],
59
            ['first-vendor/second-package', true],
60
            ['first-dev-vendor/first-package', true],
61
            ['first-dev-vendor/second-package', true],
62
            ['second-vendor/first-package', true],
63
            ['second-vendor/second-package', true],
64
            ['second-dev-vendor/first-package', true],
65
            ['second-dev-vendor/second-package', true],
66
            ['constant_based_parameter', 'a constant value defined in config/constants.php'],
67
            ['constant_from_vendor', 'a constant value defined in first-dev-vendor/second-package'],
68
            ['env.string', 'string'],
69
            ['env.number', '42'],
70
            ['env.text', 'Some text with several words'],
71
            ['env.params', [
72
                'first' => 'first substition',
73
                'deeper' => [
74
                    'second' => 'second substition',
75
                    'and' => [
76
                        'deepest' => 'deepest substition',
77
                    ],
78
                ],
79
            ]],
80
            ['parameters from .env', [
81
                'ENV_STRING' => 'string',
82
                'ENV_NUMBER' => '42',
83
                'ENV_TEXT' => 'Some text with several words',
84
            ]],
85
            ['parameters from .env through constants', [
86
                'ENV_STRING' => 'string',
87
                'ENV_NUMBER' => '42',
88
                'ENV_TEXT' => 'Some text with several words',
89
            ]],
90
            ['parameters from YAML', [
91
                'string value' => 'string',
92
                'boolean value' => true,
93
                'int value' => 42,
94
            ]],
95
            ['parameters from JSON', [
96
                'string value' => 'string',
97
                'boolean value' => true,
98
                'int value' => 42,
99
            ]],
100
        ];
101
    }
102
103
    protected function getDefaultConfigName(): string
104
    {
105
        return 'params';
106
    }
107
108
    public function testConstants()
109
    {
110
        $values = $this->getConfigValue('parameters from .env through constants');
111
        foreach ($values as $k => $v) {
112
            $this->assertSame($v, constant($k));
113
        }
114
    }
115
}
116