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

IssueRepositoryTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 0
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
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
                    'html_url' => 'https://github.com/jwage/changelog-generator/issue/1',
34
                    'user' => ['login' => 'jwage'],
35
                    'labels' => [['name' => 'Enhancement']],
36
                ],
37
                [
38
                    'number' => 2,
39
                    'title' => '[Bug] Issue #2',
40
                    'html_url' => 'https://github.com/jwage/changelog-generator/issue/2',
41
                    'user' => ['login' => 'jwage'],
42
                    'labels' => [['name' => 'Bug']],
43
                ],
44
            ]);
45
46
        $issue1 = $this->createMock(Issue::class);
47
        $issue2 = $this->createMock(Issue::class);
48
49
        $this->issueFactory->expects($this->at(0))
50
            ->method('create')
51
            ->with(1, 'Issue #1', 'https://github.com/jwage/changelog-generator/issue/1', 'jwage', ['Enhancement'])
52
            ->willReturn($issue1);
53
54
        $this->issueFactory->expects($this->at(1))
55
            ->method('create')
56
            ->with(2, '&#91;Bug&#92; Issue #2', 'https://github.com/jwage/changelog-generator/issue/2', 'jwage', ['Bug'])
57
            ->willReturn($issue2);
58
59
        $issues = $this->issueRepository->getMilestoneIssues('jwage', 'changelog-generator', '1.0');
60
61
        self::assertCount(2, $issues);
62
        self::assertSame($issue1, $issues[1]);
63
        self::assertSame($issue2, $issues[2]);
64
    }
65
66
    protected function setUp() : void
67
    {
68
        $this->issueFetcher = $this->createMock(IssueFetcher::class);
69
        $this->issueFactory = $this->createMock(IssueFactory::class);
70
71
        $this->issueRepository = new IssueRepository(
72
            $this->issueFetcher,
73
            $this->issueFactory
74
        );
75
    }
76
}
77