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 string[] */ |
25
|
|
|
private $options = []; |
26
|
|
|
|
27
|
|
|
/** @var ChangelogConfig */ |
28
|
|
|
private $changelogConfig; |
29
|
|
|
|
30
|
|
|
public function testGetSetUser() : void |
31
|
|
|
{ |
32
|
|
|
self::assertEquals($this->user, $this->changelogConfig->getUser()); |
33
|
|
|
|
34
|
|
|
$this->changelogConfig->setUser('romanb'); |
35
|
|
|
|
36
|
|
|
self::assertEquals('romanb', $this->changelogConfig->getUser()); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function testGetSetRepository() : void |
40
|
|
|
{ |
41
|
|
|
self::assertEquals($this->repository, $this->changelogConfig->getRepository()); |
42
|
|
|
|
43
|
|
|
$this->changelogConfig->setRepository('purl'); |
44
|
|
|
|
45
|
|
|
self::assertEquals('purl', $this->changelogConfig->getRepository()); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function testGetSetMilestone() : void |
49
|
|
|
{ |
50
|
|
|
self::assertEquals($this->milestone, $this->changelogConfig->getMilestone()); |
51
|
|
|
|
52
|
|
|
$this->changelogConfig->setMilestone('1.0'); |
53
|
|
|
|
54
|
|
|
self::assertEquals('1.0', $this->changelogConfig->getMilestone()); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function testGetSetLabels() : void |
58
|
|
|
{ |
59
|
|
|
self::assertEquals($this->labels, $this->changelogConfig->getLabels()); |
60
|
|
|
|
61
|
|
|
$this->changelogConfig->setLabels(['Improvement']); |
62
|
|
|
|
63
|
|
|
self::assertEquals(['Improvement'], $this->changelogConfig->getLabels()); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function testGetSetOptions() : void |
67
|
|
|
{ |
68
|
|
|
self::assertEquals(['rootGitHubUrl' => 'https://api.github.com'], $this->changelogConfig->getOptions()); |
69
|
|
|
|
70
|
|
|
$this->changelogConfig->setOptions(['rootGitHubUrl' => 'https://git.mycompany.com/api/v3']); |
71
|
|
|
|
72
|
|
|
self::assertEquals(['rootGitHubUrl' => 'https://git.mycompany.com/api/v3'], $this->changelogConfig->getOptions()); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
public function testGetSetOption() : void |
76
|
|
|
{ |
77
|
|
|
self::assertNull($this->changelogConfig->getOption('test')); |
78
|
|
|
|
79
|
|
|
$this->changelogConfig->setOption('test', true); |
80
|
|
|
|
81
|
|
|
self::assertTrue($this->changelogConfig->getOption('test')); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
public function testGetMilestoneIssuesUrl() : void |
85
|
|
|
{ |
86
|
|
|
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')); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
public function testGetMilestoneIssuesUrlNoLabel() : void |
90
|
|
|
{ |
91
|
|
|
self::assertEquals('https://api.github.com/search/issues?q=milestone%3A%221.0%22+repo%3Ajwage%2Fchangelog-generator+state%3Aclosed', $this->changelogConfig->getMilestoneIssuesUrl('')); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
public function testGetMilestoneIssuesUrlWithCustomRootGitHubUrl() : void |
95
|
|
|
{ |
96
|
|
|
$this->changelogConfig->setOptions(['rootGitHubUrl' => 'https://git.mycompany.com/api/v3']); |
97
|
|
|
|
98
|
|
|
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')); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
public function testGetMilestoneIssuesUrlWithMissingRootGitHubUrl() : void |
102
|
|
|
{ |
103
|
|
|
$this->changelogConfig->setOptions([]); |
104
|
|
|
|
105
|
|
|
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')); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
public function testIsValid() : void |
109
|
|
|
{ |
110
|
|
|
self::assertTrue($this->changelogConfig->isValid()); |
111
|
|
|
|
112
|
|
|
$changelogConfig = new ChangelogConfig( |
113
|
|
|
'', |
114
|
|
|
$this->repository, |
115
|
|
|
$this->milestone, |
116
|
|
|
$this->labels, |
117
|
|
|
$this->options |
118
|
|
|
); |
119
|
|
|
|
120
|
|
|
self::assertFalse($changelogConfig->isValid()); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
protected function setUp() : void |
124
|
|
|
{ |
125
|
|
|
$this->user = 'jwage'; |
126
|
|
|
$this->repository = 'changelog-generator'; |
127
|
|
|
$this->milestone = '1.0'; |
128
|
|
|
$this->labels = ['Enhancement', 'Bug']; |
129
|
|
|
$this->options = []; |
130
|
|
|
|
131
|
|
|
$this->changelogConfig = new ChangelogConfig( |
132
|
|
|
$this->user, |
133
|
|
|
$this->repository, |
134
|
|
|
$this->milestone, |
135
|
|
|
$this->labels, |
136
|
|
|
$this->options |
137
|
|
|
); |
138
|
|
|
} |
139
|
|
|
} |
140
|
|
|
|