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