Completed
Push — master ( d82a91...4d3fdb )
by Ross
02:33
created

GetSubDomainInformationTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 82
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 6
dl 0
loc 82
rs 10
c 0
b 0
f 0

6 Methods

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