1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
|
//! ref: composer/tests/Composer/Test/ConfigTest.php
use indexmap::IndexMap;
use shirabe::config::Config;
use shirabe_php_shim::PhpMixed;
fn repo(r#type: &str, url: &str) -> PhpMixed {
let mut m: IndexMap<String, PhpMixed> = IndexMap::new();
m.insert("type".to_string(), PhpMixed::String(r#type.to_string()));
m.insert("url".to_string(), PhpMixed::String(url.to_string()));
PhpMixed::Array(m)
}
fn map(pairs: Vec<(&str, PhpMixed)>) -> IndexMap<String, PhpMixed> {
pairs.into_iter().map(|(k, v)| (k.to_string(), v)).collect()
}
fn disable(name: &str) -> PhpMixed {
PhpMixed::Array(map(vec![(name, PhpMixed::Bool(false))]))
}
fn packagist() -> PhpMixed {
repo("composer", "https://repo.packagist.org")
}
struct Case {
expected: IndexMap<String, PhpMixed>,
local: IndexMap<String, PhpMixed>,
system: Option<IndexMap<String, PhpMixed>>,
}
/// ref: ConfigTest::dataAddPackagistRepository
fn data_add_packagist_repository() -> Vec<Case> {
vec![
// local config inherits system defaults
Case {
expected: map(vec![("packagist.org", packagist())]),
local: map(vec![]),
system: None,
},
// local config can disable system config by name
Case {
expected: map(vec![]),
local: map(vec![("0", disable("packagist.org"))]),
system: None,
},
// local config can disable system config by name bc
Case {
expected: map(vec![]),
local: map(vec![("0", disable("packagist"))]),
system: None,
},
// local config adds above defaults
Case {
expected: map(vec![
("0", repo("vcs", "git://github.com/composer/composer.git")),
("1", repo("pear", "http://pear.composer.org")),
("packagist.org", packagist()),
]),
local: map(vec![
("0", repo("vcs", "git://github.com/composer/composer.git")),
("1", repo("pear", "http://pear.composer.org")),
]),
system: None,
},
// system config adds above core defaults
Case {
expected: map(vec![
("example.com", repo("composer", "http://example.com")),
("packagist.org", packagist()),
]),
local: map(vec![]),
system: Some(map(vec![(
"example.com",
repo("composer", "http://example.com"),
)])),
},
// local config can disable repos by name and re-add them anonymously to bring them above system config
Case {
expected: map(vec![
("1", repo("composer", "http://packagist.org")),
("example.com", repo("composer", "http://example.com")),
]),
local: map(vec![
("0", disable("packagist.org")),
("1", repo("composer", "http://packagist.org")),
]),
system: Some(map(vec![(
"example.com",
repo("composer", "http://example.com"),
)])),
},
// local config can override by name to bring a repo above system config
Case {
expected: map(vec![
("packagist.org", repo("composer", "http://packagistnew.org")),
("example.com", repo("composer", "http://example.com")),
]),
local: map(vec![(
"packagist.org",
repo("composer", "http://packagistnew.org"),
)]),
system: Some(map(vec![(
"example.com",
repo("composer", "http://example.com"),
)])),
},
// local config redefining packagist.org by URL override it if no named keys are used
Case {
expected: map(vec![("0", repo("composer", "https://repo.packagist.org"))]),
local: map(vec![("0", repo("composer", "https://repo.packagist.org"))]),
system: None,
},
// local config redefining packagist.org by URL override it also with named keys
Case {
expected: map(vec![(
"example",
repo("composer", "https://repo.packagist.org"),
)]),
local: map(vec![(
"example",
repo("composer", "https://repo.packagist.org"),
)]),
system: None,
},
// incorrect local config does not cause ErrorException
Case {
expected: map(vec![
("packagist.org", packagist()),
("type", PhpMixed::String("vcs".to_string())),
("url", PhpMixed::String("http://example.com".to_string())),
]),
local: map(vec![
("type", PhpMixed::String("vcs".to_string())),
("url", PhpMixed::String("http://example.com".to_string())),
]),
system: None,
},
]
}
#[test]
#[ignore = "Config::merge of an anonymous {name: false} disable entry reaches current() (todo!()) in the php-shim"]
fn test_add_packagist_repository() {
for case in data_add_packagist_repository() {
let mut config = Config::new(false, None);
if let Some(system) = case.system {
let mut cfg: IndexMap<String, PhpMixed> = IndexMap::new();
cfg.insert("repositories".to_string(), PhpMixed::Array(system));
config.merge(&cfg, "test");
}
let mut cfg: IndexMap<String, PhpMixed> = IndexMap::new();
cfg.insert("repositories".to_string(), PhpMixed::Array(case.local));
config.merge(&cfg, "test");
let actual = config.get_repositories();
// PHP assertEquals on arrays compares pairs irrespective of order.
assert_eq!(case.expected.len(), actual.len());
for (key, value) in &case.expected {
assert_eq!(Some(value), actual.get(key), "repository key {key:?}");
}
}
}
// The remaining ConfigTest cases either read process env via Platform (process-timeout,
// htaccess-protect, var/realpath replacement, oauth, audit, ...) without the env isolation
// their setUp/tearDown provides, or exercise plugin-config merge details. They are not
// ported yet.
#[test]
#[ignore = "not yet ported (env-dependent without the setUp/tearDown isolation, or plugin-config merge details)"]
fn test_preferred_install_as_string() {
todo!()
}
#[test]
#[ignore = "not yet ported (env-dependent without the setUp/tearDown isolation, or plugin-config merge details)"]
fn test_merge_preferred_install() {
todo!()
}
#[test]
#[ignore = "not yet ported (env-dependent without the setUp/tearDown isolation, or plugin-config merge details)"]
fn test_merge_github_oauth() {
todo!()
}
#[test]
#[ignore = "not yet ported (env-dependent without the setUp/tearDown isolation, or plugin-config merge details)"]
fn test_var_replacement() {
todo!()
}
#[test]
#[ignore = "not yet ported (env-dependent without the setUp/tearDown isolation, or plugin-config merge details)"]
fn test_realpath_replacement() {
todo!()
}
#[test]
#[ignore = "not yet ported (env-dependent without the setUp/tearDown isolation, or plugin-config merge details)"]
fn test_stream_wrapper_dirs() {
todo!()
}
#[test]
#[ignore = "not yet ported (env-dependent without the setUp/tearDown isolation, or plugin-config merge details)"]
fn test_fetching_relative_paths() {
todo!()
}
#[test]
#[ignore = "not yet ported (env-dependent without the setUp/tearDown isolation, or plugin-config merge details)"]
fn test_override_github_protocols() {
todo!()
}
#[test]
#[ignore = "not yet ported (env-dependent without the setUp/tearDown isolation, or plugin-config merge details)"]
fn test_git_disabled_by_default_in_github_protocols() {
todo!()
}
#[test]
#[ignore = "not yet ported (env-dependent without the setUp/tearDown isolation, or plugin-config merge details)"]
fn test_allowed_urls_pass() {
todo!()
}
#[test]
#[ignore = "not yet ported (env-dependent without the setUp/tearDown isolation, or plugin-config merge details)"]
fn test_prohibited_urls_throw_exception() {
todo!()
}
#[test]
#[ignore = "not yet ported (env-dependent without the setUp/tearDown isolation, or plugin-config merge details)"]
fn test_prohibited_urls_warning_verify_peer() {
todo!()
}
#[test]
#[ignore = "not yet ported (env-dependent without the setUp/tearDown isolation, or plugin-config merge details)"]
fn test_disable_tls_can_be_overridden() {
todo!()
}
#[test]
#[ignore = "not yet ported (env-dependent without the setUp/tearDown isolation, or plugin-config merge details)"]
fn test_process_timeout() {
todo!()
}
#[test]
#[ignore = "not yet ported (env-dependent without the setUp/tearDown isolation, or plugin-config merge details)"]
fn test_htaccess_protect() {
todo!()
}
#[test]
#[ignore = "not yet ported (env-dependent without the setUp/tearDown isolation, or plugin-config merge details)"]
fn test_get_source_of_value() {
todo!()
}
#[test]
#[ignore = "not yet ported (env-dependent without the setUp/tearDown isolation, or plugin-config merge details)"]
fn test_get_source_of_value_env_variables() {
todo!()
}
#[test]
#[ignore = "not yet ported (env-dependent without the setUp/tearDown isolation, or plugin-config merge details)"]
fn test_audit() {
todo!()
}
#[test]
#[ignore = "not yet ported (env-dependent without the setUp/tearDown isolation, or plugin-config merge details)"]
fn test_get_defaults_to_an_empty_array() {
todo!()
}
#[test]
#[ignore = "not yet ported (env-dependent without the setUp/tearDown isolation, or plugin-config merge details)"]
fn test_merges_plugin_config() {
todo!()
}
#[test]
#[ignore = "not yet ported (env-dependent without the setUp/tearDown isolation, or plugin-config merge details)"]
fn test_overrides_global_boolean_plugins_config() {
todo!()
}
#[test]
#[ignore = "not yet ported (env-dependent without the setUp/tearDown isolation, or plugin-config merge details)"]
fn test_allows_all_plugins_from_local_boolean() {
todo!()
}
|