Completed
Push — master ( a20e35...2a3e96 )
by Greg
03:21
created

ConfigurationTest::testConfigurationWithReverseOrderCrossFileReferences()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 24
rs 9.536
c 0
b 0
f 0
cc 2
nc 2
nop 0
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
        verify($taskA->run())->equals('value-a');
20
21
        $taskB = new ConfigurationTestTaskB();
22
        $taskB->setConfig(Robo::config());
23
        verify($taskB->run())->equals('value-b');
24
    }
25
26
    public function testConfigurationWithCrossFileReferences()
27
    {
28
        $processor = new ConfigProcessor();
29
        $loader = new YamlConfigLoader();
30
        $processor->extend($loader->load(dirname(__DIR__) . '/_data/config-1.yml'));
31
        $processor->extend($loader->load(dirname(__DIR__) . '/_data/config-2.yml'));
32
        $processor->extend($loader->load(dirname(__DIR__) . '/_data/config-3.yml'));
33
34
        $sources = $processor->sources();
35
        verify($sources['a'])->equals(dirname(__DIR__) . '/_data/config-3.yml');
36
        verify($sources['b'])->equals(dirname(__DIR__) . '/_data/config-2.yml');
37
        verify($sources['c'])->equals(dirname(__DIR__) . '/_data/config-1.yml');
38
39
        \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...
40
41
        verify(implode(',', \Robo\Robo::config()->get('m')))->equals('3');
42
        verify(\Robo\Robo::config()->get('a'))->equals('foobarbaz');
43
    }
44
45
    public function testConfigurationWithReverseOrderCrossFileReferences()
46
    {
47
        $processor = new ConfigProcessor();
48
        $loader = new YamlConfigLoader();
49
        $processor->extend($loader->load(dirname(__DIR__) . '/_data/config-3.yml'));
50
        $processor->extend($loader->load(dirname(__DIR__) . '/_data/config-2.yml'));
51
        $processor->extend($loader->load(dirname(__DIR__) . '/_data/config-1.yml'));
52
53
        $sources = $processor->sources();
54
        verify($sources['a'])->equals(dirname(__DIR__) . '/_data/config-3.yml');
55
        verify($sources['b'])->equals(dirname(__DIR__) . '/_data/config-2.yml');
56
        verify($sources['c'])->equals(dirname(__DIR__) . '/_data/config-1.yml');
57
58
        \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...
59
60
        verify(implode(',', \Robo\Robo::config()->get('m')))->equals('1');
61
62
        if (strpos(\Robo\Robo::config()->get('a'), '$') !== false) {
63
            throw new \PHPUnit_Framework_SkippedTestError(
64
                'Evaluation of cross-file references in reverse order not supported.'
65
            );
66
        }
67
        verify(\Robo\Robo::config()->get('a'))->equals('foobarbaz');
68
    }
69
}
70
71
class ConfigurationTestTaskA extends BaseTask
72
{
73
    public function run()
74
    {
75
        return $this->getConfigValue('key');
76
    }
77
}
78
79
class ConfigurationTestTaskB extends BaseTask
80
{
81
    public function run()
82
    {
83
        return $this->getConfigValue('key');
84
    }
85
}
86