Completed
Push — master ( e3bdde...4905fa )
by Jonathan
10s
created

ChangelogConfigTest   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 118
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 118
rs 10
c 0
b 0
f 0
wmc 11

11 Methods

Rating   Name   Duplication   Size   Complexity  
A testIsValid() 0 13 1
A testGetSetRepository() 0 7 1
A testGetSetOptions() 0 7 1
A testGetMilestoneIssuesUrlWithCustomRootGitHubUrl() 0 5 1
A testGetSetMilestone() 0 7 1
A testGetSetUser() 0 7 1
A testGetMilestoneIssuesUrl() 0 3 1
A setUp() 0 14 1
A testGetMilestoneIssuesUrlWithMissingRootGitHubUrl() 0 5 1
A testGetMilestoneIssuesUrlNoLabel() 0 3 1
A testGetSetLabels() 0 7 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ChangelogGenerator\Tests;
6
7
use ChangelogGenerator\ChangelogConfig;
8
use PHPUnit\Framework\TestCase;
9
10
final class ChangelogConfigTest extends TestCase
11
{
12
    /** @var string */
13
    private $user;
14
15
    /** @var string */
16
    private $repository;
17
18
    /** @var string */
19
    private $milestone;
20
21
    /** @var string[] */
22
    private $labels = [];
23
24
    /** @var string[] */
25
    private $options = [];
26
27
    /** @var ChangelogConfig */
28
    private $changelogConfig;
29
30
    public function testGetSetUser() : void
31
    {
32
        self::assertEquals($this->user, $this->changelogConfig->getUser());
33
34
        $this->changelogConfig->setUser('romanb');
35
36
        self::assertEquals('romanb', $this->changelogConfig->getUser());
37
    }
38
39
    public function testGetSetRepository() : void
40
    {
41
        self::assertEquals($this->repository, $this->changelogConfig->getRepository());
42
43
        $this->changelogConfig->setRepository('purl');
44
45
        self::assertEquals('purl', $this->changelogConfig->getRepository());
46
    }
47
48
    public function testGetSetMilestone() : void
49
    {
50
        self::assertEquals($this->milestone, $this->changelogConfig->getMilestone());
51
52
        $this->changelogConfig->setMilestone('1.0');
53
54
        self::assertEquals('1.0', $this->changelogConfig->getMilestone());
55
    }
56
57
    public function testGetSetLabels() : void
58
    {
59
        self::assertEquals($this->labels, $this->changelogConfig->getLabels());
60
61
        $this->changelogConfig->setLabels(['Improvement']);
62
63
        self::assertEquals(['Improvement'], $this->changelogConfig->getLabels());
64
    }
65
66
    public function testGetSetOptions() : void
67
    {
68
        self::assertEquals(['rootGitHubUrl' => 'https://api.github.com'], $this->changelogConfig->getOptions());
69
70
        $this->changelogConfig->setOptions(['rootGitHubUrl' => 'https://git.mycompany.com/api/v3']);
71
72
        self::assertEquals(['rootGitHubUrl' => 'https://git.mycompany.com/api/v3'], $this->changelogConfig->getOptions());
73
    }
74
75
    public function testGetMilestoneIssuesUrl() : void
76
    {
77
        self::assertEquals('https://api.github.com/search/issues?q=milestone%3A%221.0%22+repo%3Ajwage%2Fchangelog-generator+state%3Aclosed+label%3AEnhancement', $this->changelogConfig->getMilestoneIssuesUrl('Enhancement'));
78
    }
79
80
    public function testGetMilestoneIssuesUrlNoLabel() : void
81
    {
82
        self::assertEquals('https://api.github.com/search/issues?q=milestone%3A%221.0%22+repo%3Ajwage%2Fchangelog-generator+state%3Aclosed', $this->changelogConfig->getMilestoneIssuesUrl(''));
83
    }
84
85
    public function testGetMilestoneIssuesUrlWithCustomRootGitHubUrl() : void
86
    {
87
        $this->changelogConfig->setOptions(['rootGitHubUrl' => 'https://git.mycompany.com/api/v3']);
88
89
        self::assertEquals('https://git.mycompany.com/api/v3/search/issues?q=milestone%3A%221.0%22+repo%3Ajwage%2Fchangelog-generator+state%3Aclosed+label%3AEnhancement', $this->changelogConfig->getMilestoneIssuesUrl('Enhancement'));
90
    }
91
92
    public function testGetMilestoneIssuesUrlWithMissingRootGitHubUrl() : void
93
    {
94
        $this->changelogConfig->setOptions([]);
95
96
        self::assertEquals('https://api.github.com/search/issues?q=milestone%3A%221.0%22+repo%3Ajwage%2Fchangelog-generator+state%3Aclosed+label%3AEnhancement', $this->changelogConfig->getMilestoneIssuesUrl('Enhancement'));
97
    }
98
99
    public function testIsValid() : void
100
    {
101
        self::assertTrue($this->changelogConfig->isValid());
102
103
        $changelogConfig = new ChangelogConfig(
104
            '',
105
            $this->repository,
106
            $this->milestone,
107
            $this->labels,
108
            $this->options
109
        );
110
111
        self::assertFalse($changelogConfig->isValid());
112
    }
113
114
    protected function setUp() : void
115
    {
116
        $this->user       = 'jwage';
117
        $this->repository = 'changelog-generator';
118
        $this->milestone  = '1.0';
119
        $this->labels     = ['Enhancement', 'Bug'];
120
        $this->options    = [];
121
122
        $this->changelogConfig = new ChangelogConfig(
123
            $this->user,
124
            $this->repository,
125
            $this->milestone,
126
            $this->labels,
127
            $this->options
128
        );
129
    }
130
}
131