|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace ChangelogGenerator\Tests; |
|
6
|
|
|
|
|
7
|
|
|
use ChangelogGenerator\ChangelogConfig; |
|
8
|
|
|
use ChangelogGenerator\GitHubUsernamePassword; |
|
9
|
|
|
use PHPUnit\Framework\TestCase; |
|
10
|
|
|
|
|
11
|
|
|
final class ChangelogConfigTest extends TestCase |
|
12
|
|
|
{ |
|
13
|
|
|
private string $user; |
|
14
|
|
|
|
|
15
|
|
|
private string $repository; |
|
16
|
|
|
|
|
17
|
|
|
private string $milestone; |
|
18
|
|
|
|
|
19
|
|
|
/** @var string[] */ |
|
20
|
|
|
private array $labels = []; |
|
21
|
|
|
|
|
22
|
|
|
private bool $includeOpen = false; |
|
23
|
|
|
|
|
24
|
|
|
/** @var string[] */ |
|
25
|
|
|
private array $options = []; |
|
26
|
|
|
|
|
27
|
|
|
private ChangelogConfig $changelogConfig; |
|
28
|
|
|
|
|
29
|
|
|
public function testGetSetUser(): void |
|
30
|
|
|
{ |
|
31
|
|
|
self::assertSame($this->user, $this->changelogConfig->getUser()); |
|
32
|
|
|
|
|
33
|
|
|
$this->changelogConfig->setUser('romanb'); |
|
34
|
|
|
|
|
35
|
|
|
self::assertSame('romanb', $this->changelogConfig->getUser()); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
public function testGetSetRepository(): void |
|
39
|
|
|
{ |
|
40
|
|
|
self::assertSame($this->repository, $this->changelogConfig->getRepository()); |
|
41
|
|
|
|
|
42
|
|
|
$this->changelogConfig->setRepository('purl'); |
|
43
|
|
|
|
|
44
|
|
|
self::assertSame('purl', $this->changelogConfig->getRepository()); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
public function testGetSetMilestone(): void |
|
48
|
|
|
{ |
|
49
|
|
|
self::assertSame($this->milestone, $this->changelogConfig->getMilestone()); |
|
50
|
|
|
|
|
51
|
|
|
$this->changelogConfig->setMilestone('1.0'); |
|
52
|
|
|
|
|
53
|
|
|
self::assertSame('1.0', $this->changelogConfig->getMilestone()); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
public function testGetSetLabels(): void |
|
57
|
|
|
{ |
|
58
|
|
|
self::assertSame($this->labels, $this->changelogConfig->getLabels()); |
|
59
|
|
|
|
|
60
|
|
|
$this->changelogConfig->setLabels(['Improvement']); |
|
61
|
|
|
|
|
62
|
|
|
self::assertSame(['Improvement'], $this->changelogConfig->getLabels()); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
public function testGetSetIncludeOpen(): void |
|
66
|
|
|
{ |
|
67
|
|
|
self::assertSame($this->includeOpen, $this->changelogConfig->shouldIncludeOpen()); |
|
68
|
|
|
|
|
69
|
|
|
$this->changelogConfig->setIncludeOpen(true); |
|
70
|
|
|
|
|
71
|
|
|
self::assertTrue($this->changelogConfig->shouldIncludeOpen()); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
public function testGetSetOptions(): void |
|
75
|
|
|
{ |
|
76
|
|
|
self::assertSame(['rootGitHubUrl' => 'https://api.github.com'], $this->changelogConfig->getOptions()); |
|
77
|
|
|
|
|
78
|
|
|
$this->changelogConfig->setOptions(['rootGitHubUrl' => 'https://git.mycompany.com/api/v3']); |
|
79
|
|
|
|
|
80
|
|
|
self::assertSame(['rootGitHubUrl' => 'https://git.mycompany.com/api/v3'], $this->changelogConfig->getOptions()); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
public function testGetSetOption(): void |
|
84
|
|
|
{ |
|
85
|
|
|
self::assertNull($this->changelogConfig->getOption('test')); |
|
86
|
|
|
|
|
87
|
|
|
$this->changelogConfig->setOption('test', true); |
|
88
|
|
|
|
|
89
|
|
|
self::assertTrue($this->changelogConfig->getOption('test')); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
public function testGetMilestoneIssuesUrl(): void |
|
93
|
|
|
{ |
|
94
|
|
|
self::assertSame('https://api.github.com/search/issues?q=milestone%3A%221.0%22+repo%3Ajwage%2Fchangelog-generator+state%3Aclosed+label%3A%22Enhancement%22', $this->changelogConfig->getMilestoneIssuesUrl('Enhancement')); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
public function testGetMilestoneIssuesUrlNoLabel(): void |
|
98
|
|
|
{ |
|
99
|
|
|
self::assertSame('https://api.github.com/search/issues?q=milestone%3A%221.0%22+repo%3Ajwage%2Fchangelog-generator+state%3Aclosed', $this->changelogConfig->getMilestoneIssuesUrl('')); |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
public function testGetMilestoneIssuesUrlWithCustomRootGitHubUrl(): void |
|
103
|
|
|
{ |
|
104
|
|
|
$this->changelogConfig->setOptions(['rootGitHubUrl' => 'https://git.mycompany.com/api/v3']); |
|
105
|
|
|
|
|
106
|
|
|
self::assertSame('https://git.mycompany.com/api/v3/search/issues?q=milestone%3A%221.0%22+repo%3Ajwage%2Fchangelog-generator+state%3Aclosed+label%3A%22Enhancement%22', $this->changelogConfig->getMilestoneIssuesUrl('Enhancement')); |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
public function testGetMilestoneIssuesUrlWithMissingRootGitHubUrl(): void |
|
110
|
|
|
{ |
|
111
|
|
|
$this->changelogConfig->setOptions([]); |
|
112
|
|
|
|
|
113
|
|
|
self::assertSame('https://api.github.com/search/issues?q=milestone%3A%221.0%22+repo%3Ajwage%2Fchangelog-generator+state%3Aclosed+label%3A%22Enhancement%22', $this->changelogConfig->getMilestoneIssuesUrl('Enhancement')); |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
public function testGetMilestoneIssuesUrlWithOpenIncluded(): void |
|
117
|
|
|
{ |
|
118
|
|
|
$this->changelogConfig->setIncludeOpen(true); |
|
119
|
|
|
|
|
120
|
|
|
self::assertSame('https://api.github.com/search/issues?q=milestone%3A%221.0%22+repo%3Ajwage%2Fchangelog-generator+label%3A%22Enhancement%22', $this->changelogConfig->getMilestoneIssuesUrl('Enhancement')); |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
public function testGetMilestoneIssuesUrlWithEmojiInLabel(): void |
|
124
|
|
|
{ |
|
125
|
|
|
$this->changelogConfig->setIncludeOpen(true); |
|
126
|
|
|
|
|
127
|
|
|
self::assertSame('https://api.github.com/search/issues?q=milestone%3A%221.0%22+repo%3Ajwage%2Fchangelog-generator+label%3A%22Bug+%F0%9F%90%9E%22', $this->changelogConfig->getMilestoneIssuesUrl('Bug 🐞')); |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
public function testIsValid(): void |
|
131
|
|
|
{ |
|
132
|
|
|
self::assertTrue($this->changelogConfig->isValid()); |
|
133
|
|
|
|
|
134
|
|
|
$changelogConfig = new ChangelogConfig( |
|
135
|
|
|
'', |
|
136
|
|
|
$this->repository, |
|
137
|
|
|
$this->milestone, |
|
138
|
|
|
$this->labels, |
|
139
|
|
|
$this->includeOpen, |
|
140
|
|
|
$this->options |
|
141
|
|
|
); |
|
142
|
|
|
|
|
143
|
|
|
self::assertFalse($changelogConfig->isValid()); |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
public function testGetSetGitHubCredentials(): void |
|
147
|
|
|
{ |
|
148
|
|
|
self::assertNull($this->changelogConfig->getGitHubCredentials()); |
|
149
|
|
|
|
|
150
|
|
|
$expectedGitHubCredentials = new GitHubUsernamePassword('username', 'password'); |
|
151
|
|
|
|
|
152
|
|
|
$this->changelogConfig->setGitHubCredentials($expectedGitHubCredentials); |
|
153
|
|
|
|
|
154
|
|
|
self::assertSame( |
|
155
|
|
|
$expectedGitHubCredentials, |
|
156
|
|
|
$this->changelogConfig->setGitHubCredentials($expectedGitHubCredentials) |
|
157
|
|
|
->getGitHubCredentials() |
|
158
|
|
|
); |
|
159
|
|
|
} |
|
160
|
|
|
|
|
161
|
|
|
protected function setUp(): void |
|
162
|
|
|
{ |
|
163
|
|
|
$this->user = 'jwage'; |
|
164
|
|
|
$this->repository = 'changelog-generator'; |
|
165
|
|
|
$this->milestone = '1.0'; |
|
166
|
|
|
$this->labels = ['Enhancement', 'Bug']; |
|
167
|
|
|
$this->options = []; |
|
168
|
|
|
|
|
169
|
|
|
$this->changelogConfig = new ChangelogConfig( |
|
170
|
|
|
$this->user, |
|
171
|
|
|
$this->repository, |
|
172
|
|
|
$this->milestone, |
|
173
|
|
|
$this->labels, |
|
174
|
|
|
$this->includeOpen, |
|
175
|
|
|
$this->options |
|
176
|
|
|
); |
|
177
|
|
|
} |
|
178
|
|
|
} |
|
179
|
|
|
|