|
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\Model\Requests; |
|
24
|
|
|
|
|
25
|
|
|
use RossMitchell\UpdateCloudFlare\Data\IpType; |
|
26
|
|
|
use RossMitchell\UpdateCloudFlare\Exceptions\CloudFlareException; |
|
27
|
|
|
use RossMitchell\UpdateCloudFlare\Factories\Requests\DnsRecordsFactory; |
|
28
|
|
|
use RossMitchell\UpdateCloudFlare\Model\Requests\GetSubDomainInfo; |
|
29
|
|
|
use RossMitchell\UpdateCloudFlare\Requests\DnsRecords; |
|
30
|
|
|
use RossMitchell\UpdateCloudFlare\Tests\AbstractTestClass; |
|
31
|
|
|
use RossMitchell\UpdateCloudFlare\Tests\Fakes\Curl; |
|
32
|
|
|
use RossMitchell\UpdateCloudFlare\Tests\Fakes\Helpers\DnsRecordsResponse; |
|
33
|
|
|
use Symfony\Component\Console\Exception\LogicException; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Class GetSubDomainInformationTest |
|
37
|
|
|
* @testdox RossMitchell\UpdateCloudFlare\Model\Requests\GetSubDomainInfo |
|
38
|
|
|
* @package RossMitchell\UpdateCloudFlare\Tests\Model\Requests |
|
39
|
|
|
*/ |
|
40
|
|
|
class GetSubDomainInformationTest extends AbstractTestClass |
|
41
|
|
|
{ |
|
42
|
|
|
/** |
|
43
|
|
|
* @Inject |
|
44
|
|
|
* @var GetSubDomainInfo |
|
45
|
|
|
*/ |
|
46
|
|
|
private $subDomainInfo; |
|
47
|
|
|
/** |
|
48
|
|
|
* @Inject |
|
49
|
|
|
* @var Curl |
|
50
|
|
|
*/ |
|
51
|
|
|
private $curl; |
|
52
|
|
|
/** |
|
53
|
|
|
* @Inject |
|
54
|
|
|
* @var DnsRecordsResponse |
|
55
|
|
|
*/ |
|
56
|
|
|
private $responseHelper; |
|
57
|
|
|
/** |
|
58
|
|
|
* @Inject |
|
59
|
|
|
* @var DnsRecordsFactory |
|
60
|
|
|
*/ |
|
61
|
|
|
private $requestFactory; |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* @test |
|
65
|
|
|
*/ |
|
66
|
|
|
public function itReturnsTheCorrectIpAddress(): void |
|
67
|
|
|
{ |
|
68
|
|
|
$response = $this->responseHelper->getFullJson(); |
|
69
|
|
|
$this->curl->setResponse($response); |
|
70
|
|
|
$request = $this->getRequest(); |
|
71
|
|
|
$class = $this->subDomainInfo; |
|
72
|
|
|
$class->collectionInformation($request); |
|
73
|
|
|
$this->assertEquals('1.2.3.4', $class->getSubDomainIpAddress()); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* @test |
|
78
|
|
|
*/ |
|
79
|
|
|
public function itReturnsTheCorrectSubDomainId(): void |
|
80
|
|
|
{ |
|
81
|
|
|
$response = $this->responseHelper->getFullJson(); |
|
82
|
|
|
$this->curl->setResponse($response); |
|
83
|
|
|
$request = $this->getRequest(); |
|
84
|
|
|
$class = $this->subDomainInfo; |
|
85
|
|
|
$class->collectionInformation($request); |
|
86
|
|
|
$this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $class->getSubDomainId()); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* @test |
|
91
|
|
|
*/ |
|
92
|
|
|
public function itThrowsAnExceptionIfYouTryToGetTheIpAddressEarly(): void |
|
93
|
|
|
{ |
|
94
|
|
|
$this->expectException(LogicException::class); |
|
95
|
|
|
$this->subDomainInfo->getSubDomainIpAddress(); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* @test |
|
100
|
|
|
*/ |
|
101
|
|
|
public function itThrowsAnExceptionIfYouTryToGetTheIdEarly(): void |
|
102
|
|
|
{ |
|
103
|
|
|
$this->expectException(LogicException::class); |
|
104
|
|
|
$this->subDomainInfo->getSubDomainId(); |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
/** |
|
108
|
|
|
* @test |
|
109
|
|
|
*/ |
|
110
|
|
|
public function willThrowAnExceptionIfThereIsAnError(): void |
|
111
|
|
|
{ |
|
112
|
|
|
$mockResponse = $this->responseHelper->getFullJson('false'); |
|
113
|
|
|
$this->curl->setResponse($mockResponse); |
|
114
|
|
|
$request = $this->getRequest(); |
|
115
|
|
|
$this->expectException(CloudFlareException::class); |
|
116
|
|
|
$this->subDomainInfo->collectionInformation($request); |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
/** |
|
120
|
|
|
* @param string $subDomain |
|
121
|
|
|
* @param string $type |
|
122
|
|
|
* @param string $zoneId |
|
123
|
|
|
* |
|
124
|
|
|
* @return DnsRecords |
|
125
|
|
|
*/ |
|
126
|
|
|
private function getRequest(string $subDomain = 'www', string $type = IpType::IP_V4, $zoneId = '12345'): DnsRecords |
|
127
|
|
|
{ |
|
128
|
|
|
return $this->requestFactory->create($subDomain, $type, $zoneId); |
|
129
|
|
|
} |
|
130
|
|
|
} |
|
131
|
|
|
|