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
|
//! ref: composer/tests/Composer/Test/Command/FundCommandTest.php
use crate::test_case::{
RunOptions, create_installed_json, get_application_tester, get_complete_package,
init_temp_composer,
};
use indexmap::IndexMap;
use serial_test::serial;
use shirabe::package::handle::{CompletePackageHandle, PackageInterfaceHandle};
use shirabe_php_shim::PhpMixed;
fn funding_entry(r#type: &str, url: &str) -> IndexMap<String, PhpMixed> {
let mut m = IndexMap::new();
m.insert("type".to_string(), PhpMixed::from(r#type));
m.insert("url".to_string(), PhpMixed::from(url));
m
}
/// Runs one `useCaseProvider` case.
fn run_fund_case(
composer_json: serde_json::Value,
command: &[(&str, PhpMixed)],
funding: &[(&str, IndexMap<String, PhpMixed>)],
expected: &str,
) {
let tear_down = init_temp_composer(Some(&composer_json), None, None, true);
let first = get_complete_package("first/pkg", "2.3.4");
let stable = get_complete_package("stable/pkg", "1.0.0");
let dev = get_complete_package("dev/pkg", "2.3.4.5");
let by_name: IndexMap<&str, &CompletePackageHandle> = [
("first/pkg", &first),
("stable/pkg", &stable),
("dev/pkg", &dev),
]
.into_iter()
.collect();
for (pkg_name, info) in funding {
if let Some(pkg) = by_name.get(pkg_name) {
pkg.set_funding(vec![info.clone()]);
}
}
let packages: Vec<PackageInterfaceHandle> = vec![first.into(), stable.into()];
let dev_packages: Vec<PackageInterfaceHandle> = vec![dev.into()];
create_installed_json(&packages, &dev_packages, true);
let mut input: Vec<(PhpMixed, PhpMixed)> =
vec![(PhpMixed::from("command"), PhpMixed::from("fund"))];
for (k, v) in command {
input.push((PhpMixed::from(*k), v.clone()));
}
let mut app_tester = get_application_tester();
let status_code = app_tester
.run(
input,
RunOptions {
capture_stderr_separately: true,
..RunOptions::default()
},
)
.unwrap();
assert_eq!(0, status_code);
assert_eq!(expected.trim(), app_tester.get_display().trim());
drop(tear_down);
}
#[test]
#[serial]
#[ignore = "FundCommand queries every repository (incl. the default packagist ComposerRepository) over \
HTTP for funding metadata before falling back to locally installed data, reaching \
shirabe-php-shim curl.rs curl_version (todo!()); this path needs real network access"]
fn test_fund_command() {
// 'no funding links present, locally or remotely'
run_fund_case(
serde_json::json!({
"repositories": [],
"require": { "first/pkg": "^2.0" },
"require-dev": { "dev/pkg": "~4.0" },
}),
&[],
&[],
"No funding links were found in your package dependencies. This doesn't mean they don't need your support!",
);
// 'funding links set locally are used as fallback if not found remotely'
run_fund_case(
serde_json::json!({
"repositories": [],
"require": { "first/pkg": "^2.0" },
"require-dev": { "dev/pkg": "~4.0" },
}),
&[],
&[
(
"first/pkg",
funding_entry("github", "https://github.com/composer-test-data"),
),
(
"dev/pkg",
funding_entry("github", "https://github.com/composer-test-data-dev"),
),
],
"The following packages were found in your dependencies which publish funding information:
dev
pkg
https://github.com/sponsors/composer-test-data-dev
first
https://github.com/sponsors/composer-test-data
Please consider following these links and sponsoring the work of package authors!
Thank you!",
);
// 'funding links set remotely are used as primary if found'
run_fund_case(
serde_json::json!({
"repositories": [
{
"type": "package",
"package": [
{ "name": "first/pkg", "version": "dev-foo", "funding": [{ "type": "github", "url": "https://github.com/test-should-not-be-used" }] },
{ "name": "first/pkg", "version": "dev-main", "default-branch": true, "funding": [{ "type": "custom", "url": "https://example.org" }] },
{ "name": "dev/pkg", "version": "dev-foo", "default-branch": true, "funding": [{ "type": "github", "url": "https://github.com/org" }] },
{ "name": "stable/pkg", "version": "1.0.0", "funding": [{ "type": "github", "url": "org2" }] },
],
},
],
"require": { "first/pkg": "^2.0", "stable/pkg": "^1.0" },
"require-dev": { "dev/pkg": "~4.0" },
}),
&[],
&[
(
"first/pkg",
funding_entry("github", "https://github.com/composer-test-data"),
),
(
"dev/pkg",
funding_entry("github", "https://github.com/composer-test-data-dev"),
),
(
"stable/pkg",
funding_entry("github", "https://github.com/composer-test-data-stable"),
),
],
"The following packages were found in your dependencies which publish funding information:
dev
pkg
https://github.com/sponsors/org
first
https://example.org
stable
https://github.com/sponsors/composer-test-data-stable
Please consider following these links and sponsoring the work of package authors!
Thank you!",
);
// 'format funding links as JSON'
run_fund_case(
serde_json::json!({
"repositories": [],
"require": { "first/pkg": "^2.0" },
"require-dev": { "dev/pkg": "~4.0" },
}),
&[("--format", PhpMixed::from("json"))],
&[
(
"first/pkg",
funding_entry("github", "https://github.com/composer-test-data"),
),
(
"dev/pkg",
funding_entry("github", "https://github.com/composer-test-data-dev"),
),
],
r#"{
"dev": {
"https://github.com/sponsors/composer-test-data-dev": [
"pkg"
]
},
"first": {
"https://github.com/sponsors/composer-test-data": [
"pkg"
]
}
}"#,
);
}
|