Completed
Push — master ( 4d3fdb...fd1b5e )
by Ross
02:40
created

UpdateDnsRecordTest::getRequest()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
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\Requests;
23
24
use RossMitchell\UpdateCloudFlare\Data\IpType;
25
use RossMitchell\UpdateCloudFlare\Factories\Data\SubDomainInfoFactory;
26
use RossMitchell\UpdateCloudFlare\Factories\Requests\UpdateDnsRecordFactory;
27
28
class UpdateDnsRecordTest extends AbstractRequest
29
{
30
    /**
31
     * @Inject
32
     * @var UpdateDnsRecordFactory
33
     */
34
    private $factory;
35
    /**
36
     * @Inject
37
     * @var SubDomainInfoFactory
38
     */
39
    private $subDomainFactory;
40
    /**
41
     * @var string
42
     */
43
    private $subDomain = 'www';
44
    /**
45
     * @var string
46
     */
47
    private $subDomainId = '98765';
48
    /**
49
     * @var string
50
     */
51
    private $type = IpType::IP_V4;
52
    /**
53
     * @var string
54
     */
55
    private $zoneId = '12345';
56
    /**
57
     * @var string
58
     */
59
    private $ipAddress = '9.8.7.6';
60
61
    /**
62
     * @return mixed
63
     */
64
    public function getRequest()
65
    {
66
        $subDomain = $this->subDomainFactory->create($this->subDomain, $this->type);
67
        $subDomain->setSubDomainId($this->subDomainId);
68
        $subDomain->setIpAddress($this->ipAddress);
69
        $subDomain->setZoneId($this->zoneId);
70
71
        return $this->factory->create($subDomain);
72
    }
73
74
    /**
75
     * @return array
76
     */
77
    public function getHeaders(): array
78
    {
79
        return [
80
            'X-Auth-Email: [email protected]',
81
            'X-Auth-Key: 123456789',
82
            'Content-Type: application/json',
83
        ];
84
    }
85
86
    /**
87
     * @return string
88
     */
89
    public function getRequestType(): string
90
    {
91
        return 'PUT';
92
    }
93
94
    /**
95
     * @return array
96
     */
97
    public function getFields(): array
98
    {
99
        return [
100
            'type'    => $this->type,
101
            'name'    => $this->subDomain.'.example.com',
102
            'content' => $this->ipAddress,
103
        ];
104
    }
105
106
    /**
107
     * @return string
108
     */
109
    public function getUrl(): string
110
    {
111
        $zoneId      = $this->zoneId;
112
        $subDomainId = $this->subDomainId;
113
114
        return "https://api.cloudflare.com/client/v4/zones/${zoneId}/dns_records/${subDomainId}";
115
    }
116
}
117