Passed
Pull Request — master (#53)
by Alexander
13:52
created

ParamsConfigTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 91
Duplicated Lines 0 %

Importance

Changes 7
Bugs 0 Features 0
Metric Value
wmc 4
eloc 62
dl 0
loc 91
c 7
b 0
f 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testConstants() 0 5 2
A getDefaultConfigName() 0 3 1
B configProvider() 0 75 1
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
            ['parameters from .env', [
69
                'ENV_STRING' => 'string',
70
                'ENV_NUMBER' => '42',
71
                'ENV_TEXT' => 'Some text with several words',
72
            ]],
73
            ['parameters from .env through constants', [
74
                'ENV_STRING' => 'string',
75
                'ENV_NUMBER' => '42',
76
                'ENV_TEXT' => 'Some text with several words',
77
            ]],
78
            ['parameters from YAML', [
79
                'string value' => 'string',
80
                'boolean value' => true,
81
                'int value' => 42,
82
            ]],
83
            ['parameters from JSON', [
84
                'string value' => 'string',
85
                'boolean value' => true,
86
                'int value' => 42,
87
            ]],
88
        ];
89
    }
90
91
    protected function getDefaultConfigName(): string
92
    {
93
        return 'params';
94
    }
95
96
    public function testConstants()
97
    {
98
        $values = $this->getConfigValue('parameters from .env through constants');
99
        foreach ($values as $k => $v) {
100
            $this->assertSame($v, constant($k));
101
        }
102
    }
103
}
104