IssueRepositoryTest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 80
Duplicated Lines 0 %

Importance

Changes 4
Bugs 0 Features 0
Metric Value
eloc 48
c 4
b 0
f 0
dl 0
loc 80
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testGetMilestoneIssues() 0 60 1
A setUp() 0 8 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ChangelogGenerator\Tests;
6
7
use ChangelogGenerator\ChangelogConfig;
8
use ChangelogGenerator\Issue;
9
use ChangelogGenerator\IssueFactory;
10
use ChangelogGenerator\IssueFetcher;
11
use ChangelogGenerator\IssueRepository;
12
use PHPUnit\Framework\MockObject\MockObject;
13
use PHPUnit\Framework\TestCase;
14
15
final class IssueRepositoryTest extends TestCase
16
{
17
    /** @var MockObject&IssueFetcher */
18
    private $issueFetcher;
19
20
    /** @var MockObject&IssueFactory */
21
    private $issueFactory;
22
23
    private IssueRepository $issueRepository;
24
25
    public function testGetMilestoneIssues(): void
26
    {
27
        $changelogConfig = new ChangelogConfig('jwage', 'changelog-generator', '1.0', []);
28
29
        $this->issueFetcher->expects(self::once())
30
            ->method('fetchMilestoneIssues')
31
            ->with($changelogConfig)
32
            ->willReturn([
33
                [
34
                    'number' => 1,
35
                    'title' => 'Issue #1',
36
                    'body' => 'Issue #1 Body',
37
                    'html_url' => 'https://github.com/jwage/changelog-generator/issue/1',
38
                    'user' => ['login' => 'jwage'],
39
                    'labels' => [['name' => 'Enhancement']],
40
                ],
41
                [
42
                    'number' => 2,
43
                    'title' => '[Bug] Issue #2',
44
                    'body' => 'Issue #2 Body',
45
                    'html_url' => 'https://github.com/jwage/changelog-generator/issue/2',
46
                    'user' => ['login' => 'jwage'],
47
                    'labels' => [['name' => 'Bug']],
48
                ],
49
            ]);
50
51
        $issue1 = $this->createMock(Issue::class);
52
        $issue2 = $this->createMock(Issue::class);
53
54
        $this->issueFactory->method('create')
0 ignored issues
show
Bug introduced by
The method method() does not exist on ChangelogGenerator\IssueFactory. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

54
        $this->issueFactory->/** @scrutinizer ignore-call */ 
55
                             method('create')

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
55
            ->willReturnMap([
56
                [
57
                    [
58
                        'number' => 1,
59
                        'title' => 'Issue #1',
60
                        'body' => 'Issue #1 Body',
61
                        'html_url' => 'https://github.com/jwage/changelog-generator/issue/1',
62
                        'user' => ['login' => 'jwage'],
63
                        'labels' => [['name' => 'Enhancement']],
64
                    ],
65
                    $issue1,
66
                ],
67
                [
68
                    [
69
                        'number' => 2,
70
                        'title' => '[Bug] Issue #2',
71
                        'body' => 'Issue #2 Body',
72
                        'html_url' => 'https://github.com/jwage/changelog-generator/issue/2',
73
                        'user' => ['login' => 'jwage'],
74
                        'labels' => [['name' => 'Bug']],
75
                    ],
76
                    $issue2,
77
                ],
78
            ]);
79
80
        $issues = $this->issueRepository->getMilestoneIssues($changelogConfig);
81
82
        self::assertCount(2, $issues);
83
        self::assertSame($issue1, $issues[1]);
84
        self::assertSame($issue2, $issues[2]);
85
    }
86
87
    protected function setUp(): void
88
    {
89
        $this->issueFetcher = $this->createMock(IssueFetcher::class);
90
        $this->issueFactory = $this->createMock(IssueFactory::class);
91
92
        $this->issueRepository = new IssueRepository(
93
            $this->issueFetcher,
94
            $this->issueFactory
95
        );
96
    }
97
}
98