|
1
|
|
|
<?php |
|
2
|
|
|
use Robo\Robo; |
|
3
|
|
|
|
|
4
|
|
|
use Consolidation\Config\Loader\ConfigProcessor; |
|
5
|
|
|
use Consolidation\Config\Loader\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 testHelpWithoutConfiguration() |
|
|
|
|
|
|
57
|
|
|
{ |
|
58
|
|
|
$argv = ['placeholder', 'help', 'test:simple-list']; |
|
59
|
|
|
$result = $this->runner->execute($argv, null, null, $this->guy->capturedOutputStream()); |
|
|
|
|
|
|
60
|
|
|
|
|
61
|
|
|
$this->guy->seeInOutput('[default: "1"]'); |
|
62
|
|
|
$this->guy->seeInOutput('[default: "2"]'); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
View Code Duplication |
public function testHelpWithConfigurationButNoOptions() |
|
|
|
|
|
|
66
|
|
|
{ |
|
67
|
|
|
\Robo\Robo::config()->set('command.test.simple-list.options.a', '4'); |
|
68
|
|
|
\Robo\Robo::config()->set('command.test.simple-list.options.b', '5'); |
|
69
|
|
|
|
|
70
|
|
|
$argv = ['placeholder', 'help', 'test:simple-list']; |
|
71
|
|
|
$result = $this->runner->execute($argv, null, null, $this->guy->capturedOutputStream()); |
|
|
|
|
|
|
72
|
|
|
|
|
73
|
|
|
$this->guy->seeInOutput('[default: "4"]'); |
|
74
|
|
|
$this->guy->seeInOutput('[default: "5"]'); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
View Code Duplication |
public function testWithConfigurationAndOptionOverride() |
|
|
|
|
|
|
78
|
|
|
{ |
|
79
|
|
|
\Robo\Robo::config()->set('command.test.simple-list.options.a', '4'); |
|
80
|
|
|
\Robo\Robo::config()->set('command.test.simple-list.options.b', '5'); |
|
81
|
|
|
|
|
82
|
|
|
$argv = ['placeholder', 'test:simple-list', '--b=6']; |
|
83
|
|
|
$result = $this->runner->execute($argv, null, null, $this->guy->capturedOutputStream()); |
|
|
|
|
|
|
84
|
|
|
|
|
85
|
|
|
$this->guy->seeInOutput("a: '4'"); |
|
86
|
|
|
$this->guy->seeInOutput("b: '6'"); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
View Code Duplication |
public function testWithConfigurationFallbacks() |
|
|
|
|
|
|
90
|
|
|
{ |
|
91
|
|
|
\Robo\Robo::config()->set('command.test.simple-list.options.a', '4'); |
|
92
|
|
|
\Robo\Robo::config()->set('command.test.options.b', '7'); |
|
93
|
|
|
|
|
94
|
|
|
$argv = ['placeholder', 'test:simple-list']; |
|
95
|
|
|
$result = $this->runner->execute($argv, null, null, $this->guy->capturedOutputStream()); |
|
|
|
|
|
|
96
|
|
|
|
|
97
|
|
|
$this->guy->seeInOutput("a: '4'"); |
|
98
|
|
|
$this->guy->seeInOutput("b: '7'"); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
View Code Duplication |
public function testSettingConfigurationFromCommandOptions() |
|
|
|
|
|
|
102
|
|
|
{ |
|
103
|
|
|
$argv = ['placeholder', 'test:simple-list', '-D', 'config.key=value']; |
|
104
|
|
|
$result = $this->runner->execute($argv, null, null, $this->guy->capturedOutputStream()); |
|
|
|
|
|
|
105
|
|
|
|
|
106
|
|
|
$this->guy->seeInOutput("a: '1'"); |
|
107
|
|
|
$this->guy->seeInOutput("b: '2'"); |
|
108
|
|
|
|
|
109
|
|
|
$actual = \Robo\Robo::config()->get('config.key'); |
|
110
|
|
|
$this->assertEquals('value', $actual); |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
View Code Duplication |
public function testWithConfigLoader() |
|
|
|
|
|
|
114
|
|
|
{ |
|
115
|
|
|
$loader = new YamlConfigLoader(); |
|
116
|
|
|
$loader->load(dirname(__DIR__) . '/_data/robo.yml'); |
|
117
|
|
|
|
|
118
|
|
|
\Robo\Robo::config()->import($loader->export()); |
|
119
|
|
|
|
|
120
|
|
|
$argv = ['placeholder', 'test:simple-list']; |
|
121
|
|
|
$result = $this->runner->execute($argv, null, null, $this->guy->capturedOutputStream()); |
|
|
|
|
|
|
122
|
|
|
|
|
123
|
|
|
$this->guy->seeInOutput("a: '12'"); |
|
124
|
|
|
$this->guy->seeInOutput("b: '13'"); |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
View Code Duplication |
public function testWithConfigLoaderAndCliOverride() |
|
|
|
|
|
|
128
|
|
|
{ |
|
129
|
|
|
$loader = new YamlConfigLoader(); |
|
130
|
|
|
$loader->load(dirname(__DIR__) . '/_data/robo.yml'); |
|
131
|
|
|
|
|
132
|
|
|
\Robo\Robo::config()->import($loader->export()); |
|
133
|
|
|
|
|
134
|
|
|
$argv = ['placeholder', 'test:simple-list', '--b=3']; |
|
135
|
|
|
$result = $this->runner->execute($argv, null, null, $this->guy->capturedOutputStream()); |
|
|
|
|
|
|
136
|
|
|
|
|
137
|
|
|
$this->guy->seeInOutput("a: '12'"); |
|
138
|
|
|
$this->guy->seeInOutput("b: '3'"); |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
public function testWithConfigProcessor() |
|
142
|
|
|
{ |
|
143
|
|
|
$processor = new ConfigProcessor(); |
|
144
|
|
|
$loader = new YamlConfigLoader(); |
|
145
|
|
|
$processor->extend($loader->load(dirname(__DIR__) . '/_data/robo.yml')); |
|
146
|
|
|
$processor->extend($loader->load(dirname(__DIR__) . '/_data/robo2.yml')); |
|
147
|
|
|
\Robo\Robo::config()->import($processor->export()); |
|
148
|
|
|
|
|
149
|
|
|
$argv = ['placeholder', 'test:simple-list']; |
|
150
|
|
|
$result = $this->runner->execute($argv, null, null, $this->guy->capturedOutputStream()); |
|
|
|
|
|
|
151
|
|
|
|
|
152
|
|
|
$this->guy->seeInOutput("a: '112'"); |
|
153
|
|
|
$this->guy->seeInOutput("b: '13'"); |
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
|
View Code Duplication |
public function testCommandWithTaskConfiguration() |
|
|
|
|
|
|
157
|
|
|
{ |
|
158
|
|
|
$loader = new YamlConfigLoader(); |
|
159
|
|
|
$loader->load(dirname(__DIR__) . '/_data/robo.yml'); |
|
160
|
|
|
|
|
161
|
|
|
\Robo\Robo::config()->import($loader->export()); |
|
162
|
|
|
|
|
163
|
|
|
$argv = ['placeholder', 'test:exec', '--simulate']; |
|
164
|
|
|
$result = $this->runner->execute($argv, null, null, $this->guy->capturedOutputStream()); |
|
|
|
|
|
|
165
|
|
|
|
|
166
|
|
|
// `task.Base.Exec.settings.dir` is defined in loaded robo.yml configuration file. |
|
167
|
|
|
$this->guy->seeInOutput("->dir('/some/dir')"); |
|
168
|
|
|
} |
|
169
|
|
|
|
|
170
|
|
View Code Duplication |
public function testCommandWithFallbackTaskConfiguration() |
|
|
|
|
|
|
171
|
|
|
{ |
|
172
|
|
|
$loader = new YamlConfigLoader(); |
|
173
|
|
|
$loader->load(dirname(__DIR__) . '/_data/falback-task-config-robo.yml'); |
|
174
|
|
|
|
|
175
|
|
|
\Robo\Robo::config()->import($loader->export()); |
|
176
|
|
|
|
|
177
|
|
|
$argv = ['placeholder', 'test:exec', '--simulate']; |
|
178
|
|
|
$result = $this->runner->execute($argv, null, null, $this->guy->capturedOutputStream()); |
|
|
|
|
|
|
179
|
|
|
|
|
180
|
|
|
// `task.Base.settings.dir` is defined in loaded robo.yml configuration file. |
|
181
|
|
|
$this->guy->seeInOutput("->dir('/some/other/dir')"); |
|
182
|
|
|
} |
|
183
|
|
|
} |
|
184
|
|
|
|
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.