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
|
//! ref: composer/tests/Composer/Test/Command/ReinstallCommandTest.php
use crate::test_case::{
RunOptions, create_composer_lock, create_installed_json, get_application_tester, get_package,
init_temp_composer,
};
use serial_test::serial;
use shirabe_php_shim::PhpMixed;
fn input(pairs: Vec<(&str, PhpMixed)>) -> Vec<(PhpMixed, PhpMixed)> {
pairs
.into_iter()
.map(|(k, v)| (PhpMixed::from(k), v))
.collect()
}
/// ref: ReinstallCommandTest::caseProvider
fn cases() -> Vec<(&'static str, Vec<(&'static str, PhpMixed)>, &'static str)> {
vec![
(
"reinstall a package by name",
vec![(
"packages",
PhpMixed::List(vec![
PhpMixed::from("root/req"),
PhpMixed::from("root/anotherreq*"),
]),
)],
"- Removing root/req (1.0.0)
- Removing root/anotherreq2 (1.0.0)
- Removing root/anotherreq (1.0.0)
- Installing root/anotherreq (1.0.0)
- Installing root/anotherreq2 (1.0.0)
- Installing root/req (1.0.0)",
),
(
"reinstall packages by type",
vec![(
"--type",
PhpMixed::List(vec![PhpMixed::from("metapackage")]),
)],
"- Removing root/req (1.0.0)
- Removing root/lala (1.0.0)
- Removing root/anotherreq2 (1.0.0)
- Removing root/anotherreq (1.0.0)
- Installing root/anotherreq (1.0.0)
- Installing root/anotherreq2 (1.0.0)
- Installing root/lala (1.0.0)
- Installing root/req (1.0.0)",
),
(
"reinstall a package that is not installed",
vec![(
"packages",
PhpMixed::List(vec![PhpMixed::from("root/unknownreq")]),
)],
r#"<warning>Pattern "root/unknownreq" does not match any currently installed packages.</warning>
<warning>Found no packages to reinstall, aborting.</warning>"#,
),
]
}
#[test]
#[serial]
#[ignore = "ReinstallCommand::execute defers the two InstallationManager::execute(...) calls (Phase-C: needs a &mut InstalledRepositoryInterface view of local_repo, and InstallationManager::execute is itself todo!()), so no Removing/Installing lines are emitted and the output is empty. Only the \"not installed\" case, which aborts with warnings before reaching that code, would pass"]
fn test_reinstall_command() {
for (label, options, expected) in cases() {
let composer_json = serde_json::json!({
"require": { "root/req": "1.*" },
"require-dev": {
"root/anotherreq": "2.*",
"root/anotherreq2": "2.*",
"root/lala": "2.*",
},
});
let _tear_down = init_temp_composer(Some(&composer_json), None, None, true);
let root_req_package = get_package("root/req", "1.0.0");
let another_req_package = get_package("root/anotherreq", "1.0.0");
let another_req_package2 = get_package("root/anotherreq2", "1.0.0");
let another_req_package3 = get_package("root/lala", "1.0.0");
root_req_package.__set_type("metapackage".to_string());
another_req_package.__set_type("metapackage".to_string());
another_req_package2.__set_type("metapackage".to_string());
another_req_package3.__set_type("metapackage".to_string());
let dev = [
another_req_package.clone(),
another_req_package2.clone(),
another_req_package3.clone(),
];
create_composer_lock(std::slice::from_ref(&root_req_package), &dev);
create_installed_json(std::slice::from_ref(&root_req_package), &dev, true);
let mut app_tester = get_application_tester();
let mut args = vec![
("command", PhpMixed::from("reinstall")),
("--no-progress", PhpMixed::from(true)),
("--no-plugins", PhpMixed::from(true)),
];
args.extend(options);
app_tester.run(input(args), RunOptions::default()).unwrap();
assert_eq!(expected, app_tester.get_display().trim(), "case: {label}");
}
}
|