1
|
|
|
<?php |
2
|
|
|
use Robo\Robo; |
3
|
|
|
|
4
|
|
|
use Robo\Config\ConfigProcessor; |
5
|
|
|
use Robo\Config\YamlConfigLoader; |
6
|
|
|
|
7
|
|
|
class ConfigurationInjectionTest extends \Codeception\TestCase\Test |
|
|
|
|
8
|
|
|
{ |
9
|
|
|
/** |
10
|
|
|
* @var \Robo\Runner |
11
|
|
|
*/ |
12
|
|
|
private $runner; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @var \CodeGuy |
16
|
|
|
*/ |
17
|
|
|
protected $guy; |
18
|
|
|
|
19
|
|
|
public function _before() |
20
|
|
|
{ |
21
|
|
|
$this->runner = new \Robo\Runner('\Robo\RoboFileFixture'); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
View Code Duplication |
public function testNoOptionsNoConfiguration() |
|
|
|
|
25
|
|
|
{ |
26
|
|
|
// Run without any config and without any options |
27
|
|
|
$argv = ['placeholder', 'test:simple-list']; |
28
|
|
|
$result = $this->runner->execute($argv, null, null, $this->guy->capturedOutputStream()); |
|
|
|
|
29
|
|
|
|
30
|
|
|
$this->guy->seeInOutput("a: '1'"); |
31
|
|
|
$this->guy->seeInOutput("b: '2'"); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
View Code Duplication |
public function testOptionsButNoConfiguration() |
|
|
|
|
35
|
|
|
{ |
36
|
|
|
// Set one option, but provide no config |
37
|
|
|
$argv = ['placeholder', 'test:simple-list', '--b=3']; |
38
|
|
|
$result = $this->runner->execute($argv, null, null, $this->guy->capturedOutputStream()); |
|
|
|
|
39
|
|
|
|
40
|
|
|
$this->guy->seeInOutput("a: '1'"); |
41
|
|
|
$this->guy->seeInOutput("b: '3'"); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
View Code Duplication |
public function testWithConfigurationButNoOptions() |
|
|
|
|
45
|
|
|
{ |
46
|
|
|
\Robo\Robo::config()->set('command.test.simple-list.options.a', '4'); |
47
|
|
|
\Robo\Robo::config()->set('command.test.simple-list.options.b', '5'); |
48
|
|
|
|
49
|
|
|
$argv = ['placeholder', 'test:simple-list']; |
50
|
|
|
$result = $this->runner->execute($argv, null, null, $this->guy->capturedOutputStream()); |
|
|
|
|
51
|
|
|
|
52
|
|
|
$this->guy->seeInOutput("a: '4'"); |
53
|
|
|
$this->guy->seeInOutput("b: '5'"); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
View Code Duplication |
public function testWithConfigurationAndOptionOverride() |
|
|
|
|
57
|
|
|
{ |
58
|
|
|
\Robo\Robo::config()->set('command.test.simple-list.options.a', '4'); |
59
|
|
|
\Robo\Robo::config()->set('command.test.simple-list.options.b', '5'); |
60
|
|
|
|
61
|
|
|
$argv = ['placeholder', 'test:simple-list', '--b=6']; |
62
|
|
|
$result = $this->runner->execute($argv, null, null, $this->guy->capturedOutputStream()); |
|
|
|
|
63
|
|
|
|
64
|
|
|
$this->guy->seeInOutput("a: '4'"); |
65
|
|
|
$this->guy->seeInOutput("b: '6'"); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
View Code Duplication |
public function testSettingConfigurationFromCommandOptions() |
|
|
|
|
69
|
|
|
{ |
70
|
|
|
$argv = ['placeholder', 'test:simple-list', '-D', 'config.key=value']; |
71
|
|
|
$result = $this->runner->execute($argv, null, null, $this->guy->capturedOutputStream()); |
|
|
|
|
72
|
|
|
|
73
|
|
|
$this->guy->seeInOutput("a: '1'"); |
74
|
|
|
$this->guy->seeInOutput("b: '2'"); |
75
|
|
|
|
76
|
|
|
$actual = \Robo\Robo::config()->get('config.key'); |
77
|
|
|
$this->assertEquals('value', $actual); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
View Code Duplication |
public function testWithConfigLoader() |
|
|
|
|
81
|
|
|
{ |
82
|
|
|
$loader = new YamlConfigLoader(); |
83
|
|
|
$loader->load(dirname(__DIR__) . '/_data/robo.yml'); |
84
|
|
|
|
85
|
|
|
\Robo\Robo::config()->import($loader->export()); |
86
|
|
|
|
87
|
|
|
$argv = ['placeholder', 'test:simple-list']; |
88
|
|
|
$result = $this->runner->execute($argv, null, null, $this->guy->capturedOutputStream()); |
|
|
|
|
89
|
|
|
|
90
|
|
|
$this->guy->seeInOutput("a: '12'"); |
91
|
|
|
$this->guy->seeInOutput("b: '13'"); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
View Code Duplication |
public function testWithConfigLoaderAndCliOverride() |
|
|
|
|
95
|
|
|
{ |
96
|
|
|
$loader = new YamlConfigLoader(); |
97
|
|
|
$loader->load(dirname(__DIR__) . '/_data/robo.yml'); |
98
|
|
|
|
99
|
|
|
\Robo\Robo::config()->import($loader->export()); |
100
|
|
|
|
101
|
|
|
$argv = ['placeholder', 'test:simple-list', '--b=3']; |
102
|
|
|
$result = $this->runner->execute($argv, null, null, $this->guy->capturedOutputStream()); |
|
|
|
|
103
|
|
|
|
104
|
|
|
$this->guy->seeInOutput("a: '12'"); |
105
|
|
|
$this->guy->seeInOutput("b: '3'"); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
public function testWithConfigProcessor() |
109
|
|
|
{ |
110
|
|
|
$processor = new ConfigProcessor(); |
111
|
|
|
$loader = new YamlConfigLoader(); |
112
|
|
|
$processor->extend($loader->load(dirname(__DIR__) . '/_data/robo.yml')); |
113
|
|
|
$processor->extend($loader->load(dirname(__DIR__) . '/_data/robo2.yml')); |
114
|
|
|
\Robo\Robo::config()->import($processor->export()); |
115
|
|
|
|
116
|
|
|
$argv = ['placeholder', 'test:simple-list']; |
117
|
|
|
$result = $this->runner->execute($argv, null, null, $this->guy->capturedOutputStream()); |
|
|
|
|
118
|
|
|
|
119
|
|
|
$this->guy->seeInOutput("a: '112'"); |
120
|
|
|
$this->guy->seeInOutput("b: '13'"); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
View Code Duplication |
public function testCommandWithTaskConfiguration() |
|
|
|
|
124
|
|
|
{ |
125
|
|
|
$loader = new YamlConfigLoader(); |
126
|
|
|
$loader->load(dirname(__DIR__) . '/_data/robo.yml'); |
127
|
|
|
|
128
|
|
|
\Robo\Robo::config()->import($loader->export()); |
129
|
|
|
|
130
|
|
|
$argv = ['placeholder', 'test:exec', '--simulate']; |
131
|
|
|
$result = $this->runner->execute($argv, null, null, $this->guy->capturedOutputStream()); |
|
|
|
|
132
|
|
|
|
133
|
|
|
// `task.Exec.settings.dir` is defined in loaded robo.yml configuration file. |
134
|
|
|
$this->guy->seeInOutput("->dir('/some/dir')"); |
135
|
|
|
} |
136
|
|
|
} |
137
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.