1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace ChangelogGenerator\Tests; |
6
|
|
|
|
7
|
|
|
use ChangelogGenerator\Issue; |
8
|
|
|
use PHPUnit\Framework\TestCase; |
9
|
|
|
|
10
|
|
|
final class IssueTest extends TestCase |
11
|
|
|
{ |
12
|
|
|
private Issue $issue; |
13
|
|
|
|
14
|
|
|
public function testNumber(): void |
15
|
|
|
{ |
16
|
|
|
self::assertSame(1, $this->issue->getNumber()); |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
public function testGetTitle(): void |
20
|
|
|
{ |
21
|
|
|
self::assertSame('Test Title', $this->issue->getTitle()); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
public function testGetBody(): void |
25
|
|
|
{ |
26
|
|
|
self::assertSame('Test Body', $this->issue->getBody()); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
public function testGetUrl(): void |
30
|
|
|
{ |
31
|
|
|
self::assertSame('https://www.google.com', $this->issue->getUrl()); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function testGetUser(): void |
35
|
|
|
{ |
36
|
|
|
self::assertSame('jwage', $this->issue->getUser()); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function testGetLabels(): void |
40
|
|
|
{ |
41
|
|
|
self::assertSame(['Enhancement'], $this->issue->getLabels()); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function testIsPullRequest(): void |
45
|
|
|
{ |
46
|
|
|
$issue = new Issue( |
47
|
|
|
1, |
48
|
|
|
'Test Title', |
49
|
|
|
'Test Body', |
50
|
|
|
'https://www.google.com', |
51
|
|
|
'jwage', |
52
|
|
|
['Enhancement'], |
53
|
|
|
false |
54
|
|
|
); |
55
|
|
|
|
56
|
|
|
self::assertFalse($issue->isPullRequest()); |
57
|
|
|
|
58
|
|
|
$issue = new Issue( |
59
|
|
|
1, |
60
|
|
|
'Test Title', |
61
|
|
|
'Test Body', |
62
|
|
|
'https://www.google.com', |
63
|
|
|
'jwage', |
64
|
|
|
['Enhancement'], |
65
|
|
|
true |
66
|
|
|
); |
67
|
|
|
|
68
|
|
|
self::assertTrue($issue->isPullRequest()); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
public function testLinkedPullRequest(): void |
72
|
|
|
{ |
73
|
|
|
self::assertNull($this->issue->getLinkedPullRequest()); |
74
|
|
|
|
75
|
|
|
$linkedPullRequest = $this->createMock(Issue::class); |
76
|
|
|
|
77
|
|
|
$this->issue->setLinkedPullRequest($linkedPullRequest); |
78
|
|
|
|
79
|
|
|
self::assertInstanceOf(Issue::class, $this->issue->getLinkedPullRequest()); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
public function testLinkedIssue(): void |
83
|
|
|
{ |
84
|
|
|
self::assertNull($this->issue->getLinkedIssue()); |
85
|
|
|
|
86
|
|
|
$linkedIssue = $this->createMock(Issue::class); |
87
|
|
|
|
88
|
|
|
$this->issue->setLinkedIssue($linkedIssue); |
89
|
|
|
|
90
|
|
|
self::assertInstanceOf(Issue::class, $this->issue->getLinkedIssue()); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
public function testRender(): void |
94
|
|
|
{ |
95
|
|
|
self::assertSame(' - [1: Test Title](https://www.google.com) thanks to @jwage', $this->issue->render()); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
public function testRenderMultiContributor(): void |
99
|
|
|
{ |
100
|
|
|
$pullRequest = new Issue( |
101
|
|
|
2, |
102
|
|
|
'Test Title', |
103
|
|
|
'Test Body Fixes #1', |
104
|
|
|
'https://www.google.com', |
105
|
|
|
'Ocramius', |
106
|
|
|
['Enhancement'], |
107
|
|
|
true |
108
|
|
|
); |
109
|
|
|
|
110
|
|
|
$pullRequest->setLinkedIssue($this->issue); |
111
|
|
|
|
112
|
|
|
self::assertSame(' - [2: Test Title](https://www.google.com) thanks to @Ocramius and @jwage', $pullRequest->render()); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
public function testEmptyBodyIssuesGetsRendered(): void |
116
|
|
|
{ |
117
|
|
|
$pullRequest = new Issue( |
118
|
|
|
3, |
119
|
|
|
'PR without body', |
120
|
|
|
null, |
121
|
|
|
'https://www.google.com', |
122
|
|
|
'jwage', |
123
|
|
|
['Bugfix'], |
124
|
|
|
true |
125
|
|
|
); |
126
|
|
|
|
127
|
|
|
$pullRequest->setLinkedIssue($this->issue); |
128
|
|
|
|
129
|
|
|
self::assertSame(' - [3: PR without body](https://www.google.com) thanks to @jwage', $pullRequest->render()); |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
protected function setUp(): void |
133
|
|
|
{ |
134
|
|
|
$this->issue = new Issue( |
135
|
|
|
1, |
136
|
|
|
'Test Title', |
137
|
|
|
'Test Body', |
138
|
|
|
'https://www.google.com', |
139
|
|
|
'jwage', |
140
|
|
|
['Enhancement'], |
141
|
|
|
false |
142
|
|
|
); |
143
|
|
|
} |
144
|
|
|
} |
145
|
|
|
|