Passed
Push — master ( 7bbbd6...f6fec9 )
by Ross
03:14 queued 44s
created

ListZonesResultTest::getExampleJson()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 72
Code Lines 69

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 72
rs 9.102
c 0
b 0
f 0
cc 1
eloc 69
nc 1
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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\Responses\Results;
23
24
use RossMitchell\UpdateCloudFlare\Factories\Responses\Results\ListZoneResultsFactory;
25
use RossMitchell\UpdateCloudFlare\Responses\Results\ListZonesResult;
26
use RossMitchell\UpdateCloudFlare\Responses\Results\Owner;
27
use RossMitchell\UpdateCloudFlare\Responses\Results\Plan;
28
use RossMitchell\UpdateCloudFlare\Tests\AbstractTestClass;
29
30
/**
31
 * Class ListZonesResultTest
32
 * @testdox RossMitchell\UpdateCloudFlare\Responses\Results\ListZonesResult
33
 * @package RossMitchell\UpdateCloudFlare\Tests\Responses\Results
34
 */
35
class ListZonesResultTest extends AbstractTestClass
36
{
37
    /**
38
     * @Inject
39
     * @var ListZoneResultsFactory
40
     */
41
    private $factory;
42
43
    /**
44
     * @test
45
     */
46
    public function canBeCreatedUsingTheFactory()
47
    {
48
        $class = $this->createClass();
49
        $this->assertInstanceOf(ListZonesResult::class, $class);
50
    }
51
52
    private function createClass(\stdClass $json = null)
53
    {
54
        if ($json === null) {
55
            $json = $this->getExampleJson();
56
        }
57
        $results = $json->result;
58
        $result  = $results[0];
59
60
        return $this->factory->create($result);
61
    }
62
63
64
    /**
65
     * @test
66
     */
67
    public function canReturnTheId()
68
    {
69
        $class = $this->createClass();
70
        $this->assertEquals('023e105f4ecef8ad9ca31a8372d0c353', $class->getId());
71
    }
72
73
    /**
74
     * @test
75
     */
76
    public function canReturnTheName()
77
    {
78
        $class = $this->createClass();
79
        $this->assertEquals('example.com', $class->getName());
80
    }
81
82
    /**
83
     * @test
84
     */
85
    public function canReturnTheDevelopmentMode()
86
    {
87
        $class = $this->createClass();
88
        $this->assertEquals(7200, $class->getDevelopmentMode());
89
    }
90
91
    /**
92
     * @test
93
     */
94
    public function canReturnTheOriginalNameServers()
95
    {
96
        $class       = $this->createClass();
97
        $expected    = [
98
            "ns1.originaldnshost.com",
99
            "ns2.originaldnshost.com",
100
        ];
101
        $nameServers = $class->getOriginalNameServers();
102
        $this->assertInternalType('array', $nameServers);
103
        $this->assertEquals($expected, $nameServers);
104
    }
105
106
    /**
107
     * @test
108
     */
109
    public function canReturnTheOriginalRegistrar()
110
    {
111
        $class = $this->createClass();
112
        $this->assertEquals('GoDaddy', $class->getOriginalRegistrar());
113
    }
114
115
    /**
116
     * @test
117
     */
118
    public function canReturnTheOriginalDnsHost()
119
    {
120
        $class = $this->createClass();
121
        $this->assertEquals('NameCheap', $class->getOriginalDnsHost());
122
    }
123
124
    /**
125
     * @test
126
     */
127
    public function canReturnTheCreatedOn()
128
    {
129
        $class = $this->createClass();
130
        $this->assertEquals('2014-01-01T05:20:00.12345Z', $class->getCreatedOn());
131
    }
132
133
    /**
134
     * @test
135
     */
136
    public function canReturnTheModifiedOn()
137
    {
138
        $class = $this->createClass();
139
        $this->assertEquals('2014-01-01T05:20:00.12345Z', $class->getModifiedOn());
140
    }
141
142
    /**
143
     * @test
144
     */
145
    public function canReturnTheOwner()
146
    {
147
        $class = $this->createClass();
148
        $this->assertInstanceOf(Owner::class, $class->getOwner());
149
    }
150
151
    /**
152
     * @test
153
     */
154
    public function canReturnThePermissions()
155
    {
156
        $class       = $this->createClass();
157
        $expected    = [
158
            "#zone:read",
159
            "#zone:edit",
160
        ];
161
        $permissions = $class->getPermissions();
162
        $this->assertInternalType('array', $permissions);
163
        $this->assertEquals($expected, $permissions);
164
    }
165
166
    /**
167
     * @test
168
     */
169
    public function canReturnThePlan()
170
    {
171
        $class = $this->createClass();
172
        $this->assertInstanceOf(Plan::class, $class->getPlan());
173
    }
174
175
    /**
176
     * @test
177
     */
178
    public function canReturnThePlanPending()
179
    {
180
        $class = $this->createClass();
181
        $this->assertInstanceOf(Plan::class, $class->getPlanPending());
182
    }
183
184
    /**
185
     * @test
186
     */
187
    public function canReturnTheStatus()
188
    {
189
        $class = $this->createClass();
190
        $this->assertEquals('active', $class->getStatus());
191
    }
192
193
    /**
194
     * @test
195
     */
196
    public function canReturnThePaused()
197
    {
198
        $class = $this->createClass();
199
        $this->assertFalse($class->isPaused());
200
    }
201
202
    /**
203
     * @test
204
     */
205
    public function canReturnTheType()
206
    {
207
        $class = $this->createClass();
208
        $this->assertEquals('full', $class->getType());
209
    }
210
211
    /**
212
     * @test
213
     */
214
    public function canReturnTheNameServers()
215
    {
216
        $class       = $this->createClass();
217
        $expected    = [
218
            "tony.ns.cloudflare.com",
219
            "woz.ns.cloudflare.com",
220
        ];
221
        $nameServers = $class->getNameServers();
222
        $this->assertInternalType('array', $nameServers);
223
        $this->assertEquals($expected, $nameServers);
224
    }
225
226
    /**
227
     * @return \stdClass
228
     */
229
    private function getExampleJson(): \stdClass
230
    {
231
        $data = <<<JSON
232
{
233
  "success": true,
234
  "errors": [
235
    {}
236
  ],
237
  "messages": [
238
    {}
239
  ],
240
  "result": [
241
    {
242
      "id": "023e105f4ecef8ad9ca31a8372d0c353",
243
      "name": "example.com",
244
      "development_mode": 7200,
245
      "original_name_servers": [
246
        "ns1.originaldnshost.com",
247
        "ns2.originaldnshost.com"
248
      ],
249
      "original_registrar": "GoDaddy",
250
      "original_dnshost": "NameCheap",
251
      "created_on": "2014-01-01T05:20:00.12345Z",
252
      "modified_on": "2014-01-01T05:20:00.12345Z",
253
      "owner": {
254
        "id": "7c5dae5552338874e5053f2534d2767a",
255
        "email": "[email protected]",
256
        "owner_type": "user"
257
      },
258
      "permissions": [
259
        "#zone:read",
260
        "#zone:edit"
261
      ],
262
      "plan": {
263
        "id": "e592fd9519420ba7405e1307bff33214",
264
        "name": "Pro Plan",
265
        "price": 20,
266
        "currency": "USD",
267
        "frequency": "monthly",
268
        "legacy_id": "pro",
269
        "is_subscribed": true,
270
        "can_subscribe": true
271
      },
272
      "plan_pending": {
273
        "id": "e592fd9519420ba7405e1307bff33214",
274
        "name": "Pro Plan",
275
        "price": 20,
276
        "currency": "USD",
277
        "frequency": "monthly",
278
        "legacy_id": "pro",
279
        "is_subscribed": true,
280
        "can_subscribe": true
281
      },
282
      "status": "active",
283
      "paused": false,
284
      "type": "full",
285
      "name_servers": [
286
        "tony.ns.cloudflare.com",
287
        "woz.ns.cloudflare.com"
288
      ]
289
    }
290
  ],
291
  "result_info": {
292
    "page": 1,
293
    "per_page": 20,
294
    "count": 1,
295
    "total_count": 2000
296
  }
297
}
298
JSON;
299
300
        return \json_decode($data);
301
    }
302
}
303