Passed
Push — master ( 941e97...ba9899 )
by Ross
02:32
created

SubDomainInfoTest::getClass()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 0
1
<?php
2
/**
3
 *
4
 * Copyright (C) 2018  Ross Mitchell
5
 *
6
 * This file is part of RossMitchell/UpdateCloudFlare.
7
 *
8
 * RossMitchell/UpdateCloudFlare is free software: you can redistribute
9
 * it and/or modify it under the terms of the GNU General Public License
10
 * as published by the Free Software Foundation, either version 3 of the
11
 * License, or (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20
 */
21
22
namespace RossMitchell\UpdateCloudFlare\Tests\Data;
23
24
use RossMitchell\UpdateCloudFlare\Data\IpType;
25
use RossMitchell\UpdateCloudFlare\Data\SubDomainInfo;
26
use RossMitchell\UpdateCloudFlare\Tests\AbstractTestClass;
27
use Symfony\Component\Console\Exception\LogicException;
28
29
/**
30
 * Class SubDomainInfoTest
31
 * @testdox RossMitchell\UpdateCloudFlare\Data\SubDomainInfo
32
 * @package RossMitchell\UpdateCloudFlare\Tests\Data
33
 */
34
class SubDomainInfoTest extends AbstractTestClass
35
{
36
    /**
37
     * @test
38
     */
39
    public function canGetTheIpAddress()
40
    {
41
        $ipAddress = '1.2.3.4';
42
        $class = $this->getClass();
43
        $class->setIpAddress($ipAddress);
44
45
        $this->assertEquals($ipAddress, $class->getIpAddress());
46
    }
47
48
    /**
49
     * @test
50
     */
51
    public function canGetTheSubDomain()
52
    {
53
        $subDomain = 'www';
54
        $class = $this->getClass();
55
        $class->setSubDomain($subDomain);
56
57
        $this->assertEquals($subDomain, $class->getSubDomain());
58
    }
59
60
    /**
61
     * @test
62
     */
63
    public function canGetTheIpType()
64
    {
65
        $ipType = $this->getIpType();
66
        $class = $this->getClass();
67
        $class->setIpType($ipType);
68
69
        $this->assertEquals(IpType::IP_V4, $class->getIpType());
70
    }
71
72
    /**
73
     * @test
74
     */
75
    public function canGetTheSubDomainId()
76
    {
77
        $subDomainId = '1234';
78
        $class = $this->getClass();
79
        $class->setSubDomainId($subDomainId);
80
81
        $this->assertEquals($subDomainId, $class->getSubDomainId());
82
    }
83
84
    /**
85
     * @test
86
     */
87
    public function canGetTheZoneId()
88
    {
89
        $zoneId = '4567';
90
        $class = $this->getClass();
91
        $class->setZoneId($zoneId);
92
93
        $this->assertEquals($zoneId, $class->getZoneId());
94
    }
95
96
    /**
97
     * @test
98
     */
99
    public function willThrowAnExceptionIfIpAddressIsNotSet()
100
    {
101
        $class = $this->getClass();
102
        $this->expectException(LogicException::class);
103
        $class->getIpAddress();
104
    }
105
106
    /**
107
     * @test
108
     */
109
    public function willThrowAnExceptionIfIpTypeIsNotSet()
110
    {
111
        $class = $this->getClass();
112
        $this->expectException(LogicException::class);
113
        $class->getIpType();
114
    }
115
116
    /**
117
     * @test
118
     */
119
    public function willThrowAnExceptionIfSubDomainIsNotSet()
120
    {
121
        $class = $this->getClass();
122
        $this->expectException(LogicException::class);
123
        $class->getSubDomain();
124
    }
125
126
    /**
127
     * @test
128
     */
129
    public function willThrowAnExceptionIfSubDomainIdIsNotSet()
130
    {
131
        $class = $this->getClass();
132
        $this->expectException(LogicException::class);
133
        $class->getSubDomainId();
134
    }
135
136
    /**
137
     * @test
138
     */
139
    public function willThrowAnExceptionIfZoneIdIsNotSet()
140
    {
141
        $class = $this->getClass();
142
        $this->expectException(LogicException::class);
143
        $class->getZoneId();
144
    }
145
146
    /**
147
     * @return SubDomainInfo
148
     */
149
    private function getClass(): SubDomainInfo
150
    {
151
        return new SubDomainInfo();
152
    }
153
154
    /**
155
     * @param string $ipType
156
     *
157
     * @return IpType
158
     */
159
    private function getIpType(string $ipType = IpType::IP_V4): IpType
160
    {
161
        $type = new IpType();
162
        $type->setType($ipType);
163
164
        return $type;
165
    }
166
}
167