1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace ChangelogGenerator\Tests; |
6
|
|
|
|
7
|
|
|
use ChangelogGenerator\ChangelogGenerator; |
8
|
|
|
use ChangelogGenerator\Issue; |
9
|
|
|
use ChangelogGenerator\IssueGroup; |
10
|
|
|
use ChangelogGenerator\IssueGrouper; |
11
|
|
|
use ChangelogGenerator\IssueRepository; |
12
|
|
|
use PHPUnit\Framework\TestCase; |
13
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
14
|
|
|
|
15
|
|
|
final class ChangelogGeneratorTest extends TestCase |
16
|
|
|
{ |
17
|
|
|
/** @var \PHPUnit_Framework_MockObject_MockObject|IssueRepository */ |
18
|
|
|
private $issueRepository; |
19
|
|
|
|
20
|
|
|
/** @var \PHPUnit_Framework_MockObject_MockObject|IssueGrouper */ |
21
|
|
|
private $issueGrouper; |
22
|
|
|
|
23
|
|
|
/** @var ChangelogGenerator */ |
24
|
|
|
private $changelogGenerator; |
25
|
|
|
|
26
|
|
|
public function testGenerate() : void |
27
|
|
|
{ |
28
|
|
|
$user = 'jwage'; |
29
|
|
|
$repository = 'changelog-generator'; |
30
|
|
|
$milestone = '1.0'; |
31
|
|
|
|
32
|
|
|
$output = $this->createMock(OutputInterface::class); |
33
|
|
|
|
34
|
|
|
$issue1 = $this->createMock(Issue::class); |
35
|
|
|
$issue2 = $this->createMock(Issue::class); |
36
|
|
|
$pullRequest1 = $this->createMock(Issue::class); |
37
|
|
|
$pullRequest2 = $this->createMock(Issue::class); |
38
|
|
|
|
39
|
|
|
$issueGroup = $this->createMock(IssueGroup::class); |
40
|
|
|
|
41
|
|
|
$milestoneIssues = [$issue1, $issue2, $pullRequest1, $pullRequest2]; |
42
|
|
|
$issueGroups = [$issueGroup]; |
43
|
|
|
|
44
|
|
|
$this->issueRepository->expects($this->once()) |
45
|
|
|
->method('getMilestoneIssues') |
46
|
|
|
->with($user, $repository, $milestone) |
47
|
|
|
->willReturn($milestoneIssues); |
48
|
|
|
|
49
|
|
|
$this->issueGrouper->expects($this->once()) |
50
|
|
|
->method('groupIssues') |
51
|
|
|
->with($milestoneIssues) |
52
|
|
|
->willReturn($issueGroups); |
53
|
|
|
|
54
|
|
|
$issueGroup->expects($this->once()) |
55
|
|
|
->method('getName') |
56
|
|
|
->willReturn('Enhancement'); |
57
|
|
|
|
58
|
|
|
$issueGroup->expects($this->once()) |
59
|
|
|
->method('getIssues') |
60
|
|
|
->willReturn([$issue1, $issue2]); |
61
|
|
|
|
62
|
|
|
$issue1->expects($this->once()) |
63
|
|
|
->method('render') |
64
|
|
|
->willReturn('Issue #1'); |
65
|
|
|
|
66
|
|
|
$issue1->expects($this->once()) |
67
|
|
|
->method('getUser') |
68
|
|
|
->willReturn('jwage'); |
69
|
|
|
|
70
|
|
|
$issue2->expects($this->once()) |
71
|
|
|
->method('render') |
72
|
|
|
->willReturn('Issue #2'); |
73
|
|
|
|
74
|
|
|
$issue2->expects($this->once()) |
75
|
|
|
->method('getUser') |
76
|
|
|
->willReturn('jwage'); |
77
|
|
|
|
78
|
|
|
$pullRequest1->expects($this->any()) |
79
|
|
|
->method('isPullRequest') |
80
|
|
|
->willReturn(true); |
81
|
|
|
|
82
|
|
|
$pullRequest1->expects($this->once()) |
83
|
|
|
->method('getUser') |
84
|
|
|
->willReturn('Ocramius'); |
85
|
|
|
|
86
|
|
|
$pullRequest2->expects($this->any()) |
87
|
|
|
->method('isPullRequest') |
88
|
|
|
->willReturn(true); |
89
|
|
|
|
90
|
|
|
$pullRequest2->expects($this->once()) |
91
|
|
|
->method('getUser') |
92
|
|
|
->willReturn('romanb'); |
93
|
|
|
|
94
|
|
|
$output->expects($this->at(0)) |
95
|
|
|
->method('writeln') |
96
|
|
|
->with([ |
97
|
|
|
'## 1.0', |
98
|
|
|
'', |
99
|
|
|
'Total issues resolved: **2**', |
100
|
|
|
'Total pull requests resolved: **2**', |
101
|
|
|
'Total contributors: **3**', |
102
|
|
|
]); |
103
|
|
|
|
104
|
|
|
$output->expects($this->at(1)) |
105
|
|
|
->method('writeln') |
106
|
|
|
->with([ |
107
|
|
|
'', |
108
|
|
|
'### Enhancement', |
109
|
|
|
'', |
110
|
|
|
]); |
111
|
|
|
|
112
|
|
|
$output->expects($this->at(2)) |
113
|
|
|
->method('writeln') |
114
|
|
|
->with('Issue #1'); |
115
|
|
|
|
116
|
|
|
$this->changelogGenerator->generate($user, $repository, $milestone, $output); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
protected function setUp() : void |
120
|
|
|
{ |
121
|
|
|
$this->issueRepository = $this->createMock(IssueRepository::class); |
122
|
|
|
$this->issueGrouper = $this->createMock(IssueGrouper::class); |
123
|
|
|
|
124
|
|
|
$this->changelogGenerator = new ChangelogGenerator( |
125
|
|
|
$this->issueRepository, |
126
|
|
|
$this->issueGrouper |
127
|
|
|
); |
128
|
|
|
} |
129
|
|
|
} |
130
|
|
|
|