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