Passed
Push — master ( 3ac984...7fdc78 )
by Jonathan
03:15 queued 01:28
created

ChangelogGeneratorTest::testGenerate()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 91
Code Lines 67

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 67
nc 1
nop 0
dl 0
loc 91
rs 8.518
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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