Completed
Push — master ( aaccd5...c6e65b )
by Jonathan
10s
created

ChangelogGeneratorTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 78
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 78
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testGenerate() 0 57 1
A setUp() 0 8 1
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
        $issue      = $this->createMock(Issue::class);
35
        $issueGroup = $this->createMock(IssueGroup::class);
36
37
        $milestoneIssues = [$issue];
38
        $issueGroups     = [$issueGroup];
39
40
        $this->issueRepository->expects($this->once())
41
            ->method('getMilestoneIssues')
42
            ->with($user, $repository, $milestone)
43
            ->willReturn($milestoneIssues);
44
45
        $this->issueGrouper->expects($this->once())
46
            ->method('groupIssues')
47
            ->with($milestoneIssues)
48
            ->willReturn($issueGroups);
49
50
        $issueGroup->expects($this->once())
51
            ->method('getName')
52
            ->willReturn('Enhancement');
53
54
        $issueGroup->expects($this->once())
55
            ->method('getIssues')
56
            ->willReturn([$issue]);
57
58
        $issue->expects($this->once())
59
            ->method('render')
60
            ->willReturn('Issue #1');
61
62
        $output->expects($this->at(0))
63
            ->method('writeln')
64
            ->with([
65
                '## 1.0',
66
                '',
67
                'Total issues resolved: **1**',
68
            ]);
69
70
        $output->expects($this->at(1))
71
            ->method('writeln')
72
            ->with([
73
                '',
74
                '### Enhancement',
75
                '',
76
            ]);
77
78
        $output->expects($this->at(2))
79
            ->method('writeln')
80
            ->with('Issue #1');
81
82
        $this->changelogGenerator->generate($user, $repository, $milestone, $output);
83
    }
84
85
    protected function setUp() : void
86
    {
87
        $this->issueRepository = $this->createMock(IssueRepository::class);
88
        $this->issueGrouper    = $this->createMock(IssueGrouper::class);
89
90
        $this->changelogGenerator = new ChangelogGenerator(
91
            $this->issueRepository,
92
            $this->issueGrouper
93
        );
94
    }
95
}
96