Completed
Pull Request — master (#552)
by Greg
03:20
created

ConfigurationTest::testConfigurationWithReverseOrderCrossFileReferences()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 24
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 24
rs 8.9713
c 1
b 0
f 0
cc 2
eloc 16
nc 2
nop 0
1
<?php
2
3
namespace unit;
4
5
use Robo\Robo;
6
use Robo\Task\BaseTask;
7
use Robo\Config\ConfigProcessor;
8
use Robo\Config\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());
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());
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
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
72
{
73
    public function run()
74
    {
75
        return $this->getConfigValue('key');
76
    }
77
}
78
79
class ConfigurationTestTaskB extends BaseTask
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
80
{
81
    public function run()
82
    {
83
        return $this->getConfigValue('key');
84
    }
85
}
86