|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace ChangelogGenerator\Tests; |
|
6
|
|
|
|
|
7
|
|
|
use ChangelogGenerator\Issue; |
|
8
|
|
|
use ChangelogGenerator\IssueFactory; |
|
9
|
|
|
use ChangelogGenerator\IssueFetcher; |
|
10
|
|
|
use ChangelogGenerator\IssueRepository; |
|
11
|
|
|
use PHPUnit\Framework\TestCase; |
|
12
|
|
|
|
|
13
|
|
|
final class IssueRepositoryTest extends TestCase |
|
14
|
|
|
{ |
|
15
|
|
|
/** @var \PHPUnit_Framework_MockObject_MockObject|IssueFetcher */ |
|
16
|
|
|
private $issueFetcher; |
|
17
|
|
|
|
|
18
|
|
|
/** @var \PHPUnit_Framework_MockObject_MockObject|IssueFactory */ |
|
19
|
|
|
private $issueFactory; |
|
20
|
|
|
|
|
21
|
|
|
/** @var IssueRepository */ |
|
22
|
|
|
private $issueRepository; |
|
23
|
|
|
|
|
24
|
|
|
public function testGetMilestoneIssues() : void |
|
25
|
|
|
{ |
|
26
|
|
|
$this->issueFetcher->expects($this->once()) |
|
27
|
|
|
->method('fetchMilestoneIssues') |
|
28
|
|
|
->with('jwage', 'changelog-generator', '1.0') |
|
29
|
|
|
->willReturn([ |
|
30
|
|
|
[ |
|
31
|
|
|
'number' => 1, |
|
32
|
|
|
'title' => 'Issue #1', |
|
33
|
|
|
'body' => 'Issue #1 Body', |
|
34
|
|
|
'html_url' => 'https://github.com/jwage/changelog-generator/issue/1', |
|
35
|
|
|
'user' => ['login' => 'jwage'], |
|
36
|
|
|
'labels' => [['name' => 'Enhancement']], |
|
37
|
|
|
], |
|
38
|
|
|
[ |
|
39
|
|
|
'number' => 2, |
|
40
|
|
|
'title' => '[Bug] Issue #2', |
|
41
|
|
|
'body' => 'Issue #2 Body', |
|
42
|
|
|
'html_url' => 'https://github.com/jwage/changelog-generator/issue/2', |
|
43
|
|
|
'user' => ['login' => 'jwage'], |
|
44
|
|
|
'labels' => [['name' => 'Bug']], |
|
45
|
|
|
], |
|
46
|
|
|
]); |
|
47
|
|
|
|
|
48
|
|
|
$issue1 = $this->createMock(Issue::class); |
|
49
|
|
|
$issue2 = $this->createMock(Issue::class); |
|
50
|
|
|
|
|
51
|
|
|
$this->issueFactory->expects($this->at(0)) |
|
52
|
|
|
->method('create') |
|
53
|
|
|
->with([ |
|
54
|
|
|
'number' => 1, |
|
55
|
|
|
'title' => 'Issue #1', |
|
56
|
|
|
'body' => 'Issue #1 Body', |
|
57
|
|
|
'html_url' => 'https://github.com/jwage/changelog-generator/issue/1', |
|
58
|
|
|
'user' => ['login' => 'jwage'], |
|
59
|
|
|
'labels' => [['name' => 'Enhancement']], |
|
60
|
|
|
]) |
|
61
|
|
|
->willReturn($issue1); |
|
62
|
|
|
|
|
63
|
|
|
$this->issueFactory->expects($this->at(1)) |
|
64
|
|
|
->method('create') |
|
65
|
|
|
->with([ |
|
66
|
|
|
'number' => 2, |
|
67
|
|
|
'title' => '[Bug] Issue #2', |
|
68
|
|
|
'body' => 'Issue #2 Body', |
|
69
|
|
|
'html_url' => 'https://github.com/jwage/changelog-generator/issue/2', |
|
70
|
|
|
'user' => ['login' => 'jwage'], |
|
71
|
|
|
'labels' => [['name' => 'Bug']], |
|
72
|
|
|
]) |
|
73
|
|
|
->willReturn($issue2); |
|
74
|
|
|
|
|
75
|
|
|
$issues = $this->issueRepository->getMilestoneIssues('jwage', 'changelog-generator', '1.0'); |
|
76
|
|
|
|
|
77
|
|
|
self::assertCount(2, $issues); |
|
78
|
|
|
self::assertSame($issue1, $issues[1]); |
|
79
|
|
|
self::assertSame($issue2, $issues[2]); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
protected function setUp() : void |
|
83
|
|
|
{ |
|
84
|
|
|
$this->issueFetcher = $this->createMock(IssueFetcher::class); |
|
85
|
|
|
$this->issueFactory = $this->createMock(IssueFactory::class); |
|
86
|
|
|
|
|
87
|
|
|
$this->issueRepository = new IssueRepository( |
|
88
|
|
|
$this->issueFetcher, |
|
89
|
|
|
$this->issueFactory |
|
90
|
|
|
); |
|
91
|
|
|
} |
|
92
|
|
|
} |
|
93
|
|
|
|