|
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\Model\Requests; |
|
23
|
|
|
|
|
24
|
|
|
use RossMitchell\UpdateCloudFlare\Data\IpType; |
|
25
|
|
|
use RossMitchell\UpdateCloudFlare\Exceptions\CloudFlareException; |
|
26
|
|
|
use RossMitchell\UpdateCloudFlare\Factories\Data\SubDomainInfoFactory; |
|
27
|
|
|
use RossMitchell\UpdateCloudFlare\Factories\Requests\UpdateDnsRecordFactory; |
|
28
|
|
|
use RossMitchell\UpdateCloudFlare\Model\Requests\UpdateDnsRecord; |
|
29
|
|
|
use RossMitchell\UpdateCloudFlare\Requests\UpdateDnsRecords; |
|
30
|
|
|
use RossMitchell\UpdateCloudFlare\Tests\AbstractTestClass; |
|
31
|
|
|
use RossMitchell\UpdateCloudFlare\Tests\Fakes\Curl; |
|
32
|
|
|
use RossMitchell\UpdateCloudFlare\Tests\Fakes\Helpers\UpdateDnsRecordsResponse; |
|
33
|
|
|
use Symfony\Component\Console\Exception\LogicException; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Class UpdateDnsRecordTest |
|
37
|
|
|
* @testdox RossMitchell\UpdateCloudFlare\Requests\UpdateDnsRecords |
|
38
|
|
|
* @package RossMitchell\UpdateCloudFlare\Tests\Model\Requests |
|
39
|
|
|
*/ |
|
40
|
|
|
class UpdateDnsRecordTest extends AbstractTestClass |
|
41
|
|
|
{ |
|
42
|
|
|
/** |
|
43
|
|
|
* @Inject |
|
44
|
|
|
* @var UpdateDnsRecord |
|
45
|
|
|
*/ |
|
46
|
|
|
private $updateDnsRecord; |
|
47
|
|
|
/** |
|
48
|
|
|
* @Inject |
|
49
|
|
|
* @var Curl |
|
50
|
|
|
*/ |
|
51
|
|
|
private $curl; |
|
52
|
|
|
/** |
|
53
|
|
|
* @Inject |
|
54
|
|
|
* @var UpdateDnsRecordsResponse |
|
55
|
|
|
*/ |
|
56
|
|
|
private $responseHelper; |
|
57
|
|
|
/** |
|
58
|
|
|
* @Inject |
|
59
|
|
|
* @var UpdateDnsRecordFactory |
|
60
|
|
|
*/ |
|
61
|
|
|
private $requestFactory; |
|
62
|
|
|
/** |
|
63
|
|
|
* @Inject |
|
64
|
|
|
* @var SubDomainInfoFactory |
|
65
|
|
|
*/ |
|
66
|
|
|
private $subDomainFactory; |
|
67
|
|
|
/** |
|
68
|
|
|
* @var string |
|
69
|
|
|
*/ |
|
70
|
|
|
private $subDomain = 'www'; |
|
71
|
|
|
/** |
|
72
|
|
|
* @var string |
|
73
|
|
|
*/ |
|
74
|
|
|
private $subDomainId = '98765'; |
|
75
|
|
|
/** |
|
76
|
|
|
* @var string |
|
77
|
|
|
*/ |
|
78
|
|
|
private $type = IpType::IP_V4; |
|
79
|
|
|
/** |
|
80
|
|
|
* @var string |
|
81
|
|
|
*/ |
|
82
|
|
|
private $zoneId = '12345'; |
|
83
|
|
|
/** |
|
84
|
|
|
* @var string |
|
85
|
|
|
*/ |
|
86
|
|
|
private $ipAddress = '9.8.7.6'; |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* @test |
|
90
|
|
|
*/ |
|
91
|
|
|
public function itCanUpdateTheIpAddressSuccessfully() |
|
92
|
|
|
{ |
|
93
|
|
|
$response = $this->responseHelper->getFullJson(); |
|
94
|
|
|
$this->curl->setResponse($response); |
|
95
|
|
|
$class = $this->updateDnsRecord; |
|
96
|
|
|
$request = $this->getRequest(); |
|
97
|
|
|
$result = $class->changeIpAddress($request); |
|
98
|
|
|
$this->assertTrue($result); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* @test |
|
103
|
|
|
*/ |
|
104
|
|
|
public function itWillThrowAnExceptionIfTheChangedIpAddressIsNotWhatIsExcepted() |
|
105
|
|
|
{ |
|
106
|
|
|
$this->ipAddress = '1.2.3.4'; |
|
107
|
|
|
$response = $this->responseHelper->getFullJson(); |
|
108
|
|
|
$this->curl->setResponse($response); |
|
109
|
|
|
$class = $this->updateDnsRecord; |
|
110
|
|
|
$request = $this->getRequest(); |
|
111
|
|
|
$this->expectException(LogicException::class); |
|
112
|
|
|
$class->changeIpAddress($request); |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
/** |
|
116
|
|
|
* @test |
|
117
|
|
|
*/ |
|
118
|
|
|
public function willThrowAnExceptionIfThereIsAnError() |
|
119
|
|
|
{ |
|
120
|
|
|
$mockResponse = $this->responseHelper->getFullJson('false'); |
|
121
|
|
|
$this->curl->setResponse($mockResponse); |
|
122
|
|
|
$request = $this->getRequest(); |
|
123
|
|
|
$this->expectException(CloudFlareException::class); |
|
124
|
|
|
$this->updateDnsRecord->changeIpAddress($request); |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
/** |
|
128
|
|
|
* @return UpdateDnsRecords |
|
129
|
|
|
*/ |
|
130
|
|
|
private function getRequest(): UpdateDnsRecords |
|
131
|
|
|
{ |
|
132
|
|
|
$subDomain = $this->subDomainFactory->create($this->subDomain, $this->type); |
|
133
|
|
|
$subDomain->setSubDomainId($this->subDomainId); |
|
134
|
|
|
$subDomain->setIpAddress($this->ipAddress); |
|
135
|
|
|
$subDomain->setZoneId($this->zoneId); |
|
136
|
|
|
|
|
137
|
|
|
return $this->requestFactory->create($subDomain); |
|
138
|
|
|
} |
|
139
|
|
|
} |
|
140
|
|
|
|