ConfigurationTestTaskB   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 7
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 1
lcom 0
cbo 1
dl 0
loc 7
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A run() 0 4 1
1
<?php
2
3
namespace unit;
4
5
use Robo\Robo;
6
use Robo\Task\BaseTask;
7
use Consolidation\Config\Loader\ConfigProcessor;
8
use Consolidation\Config\Loader\YamlConfigLoader;
9
10
class ConfigurationTest extends \Codeception\TestCase\Test
11
{
12
    public function testDifferentTasksCanHaveSameConfigKeys()
13
    {
14
        ConfigurationTestTaskA::configure('key', 'value-a');
15
        ConfigurationTestTaskB::configure('key', 'value-b');
16
17
        $taskA = new ConfigurationTestTaskA();
18
        $taskA->setConfig(Robo::config());
19
        $this->assertEquals(
20
            'value-a',
21
            $taskA->run());
22
23
        $taskB = new ConfigurationTestTaskB();
24
        $taskB->setConfig(Robo::config());
25
        $this->assertEquals(
26
            'value-b',
27
            $taskB->run());
28
    }
29
30
    public function testConfigurationWithCrossFileReferences()
31
    {
32
        $processor = new ConfigProcessor();
33
        $loader = new YamlConfigLoader();
34
        $processor->extend($loader->load(dirname(__DIR__) . '/_data/config-1.yml'));
35
        $processor->extend($loader->load(dirname(__DIR__) . '/_data/config-2.yml'));
36
        $processor->extend($loader->load(dirname(__DIR__) . '/_data/config-3.yml'));
37
38
        $sources = $processor->sources();
39
        $this->assertEquals(
40
            dirname(__DIR__) . '/_data/config-3.yml',
41
            $sources['a']);
42
        $this->assertEquals(
43
            dirname(__DIR__) . '/_data/config-2.yml',
44
            $sources['b']);
45
        $this->assertEquals(
46
            dirname(__DIR__) . '/_data/config-1.yml',
47
            $sources['c']);
48
49
        \Robo\Robo::config()->import($processor->export());
0 ignored issues
show
Deprecated Code introduced by
The method Consolidation\Config\ConfigInterface::import() has been deprecated with message: Use 'replace'. Dflydev\DotAccessData\Data::import() merges, which is confusing, since this method replaces.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
50
51
        $this->assertEquals(
52
            '3',
53
            implode(',', \Robo\Robo::config()->get('m')));
54
        $this->assertEquals(
55
            'foobarbaz',
56
            \Robo\Robo::config()->get('a'));
57
    }
58
59
    public function testConfigurationWithReverseOrderCrossFileReferences()
60
    {
61
        $processor = new ConfigProcessor();
62
        $loader = new YamlConfigLoader();
63
        $processor->extend($loader->load(dirname(__DIR__) . '/_data/config-3.yml'));
64
        $processor->extend($loader->load(dirname(__DIR__) . '/_data/config-2.yml'));
65
        $processor->extend($loader->load(dirname(__DIR__) . '/_data/config-1.yml'));
66
67
        $sources = $processor->sources();
68
        $this->assertEquals(
69
            dirname(__DIR__) . '/_data/config-3.yml',
70
            $sources['a']);
71
        $this->assertEquals(
72
            dirname(__DIR__) . '/_data/config-2.yml',
73
            $sources['b']);
74
        $this->assertEquals(
75
            dirname(__DIR__) . '/_data/config-1.yml',
76
            $sources['c']);
77
78
        \Robo\Robo::config()->import($processor->export());
0 ignored issues
show
Deprecated Code introduced by
The method Consolidation\Config\ConfigInterface::import() has been deprecated with message: Use 'replace'. Dflydev\DotAccessData\Data::import() merges, which is confusing, since this method replaces.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
79
80
        $this->assertEquals(
81
            '1',
82
            implode(',', \Robo\Robo::config()->get('m')));
83
84
        if (strpos(\Robo\Robo::config()->get('a'), '$') !== false) {
85
            throw new \PHPUnit_Framework_SkippedTestError(
86
                'Evaluation of cross-file references in reverse order not supported.'
87
            );
88
        }
89
        $this->assertEquals(
90
            'foobarbaz',
91
            \Robo\Robo::config()->get('a'));
92
    }
93
}
94
95
class ConfigurationTestTaskA extends BaseTask
96
{
97
    public function run()
98
    {
99
        return $this->getConfigValue('key');
100
    }
101
}
102
103
class ConfigurationTestTaskB extends BaseTask
104
{
105
    public function run()
106
    {
107
        return $this->getConfigValue('key');
108
    }
109
}
110