Passed
Push — master ( f6fec9...1a2738 )
by Ross
02:32
created

willThrowAnExceptionIfTheDevelopmentModeIsMissing()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
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\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
use Symfony\Component\Console\Exception\LogicException;
30
31
/**
32
 * Class ListZonesResultTest
33
 * @testdox RossMitchell\UpdateCloudFlare\Responses\Results\ListZonesResult
34
 * @package RossMitchell\UpdateCloudFlare\Tests\Responses\Results
35
 */
36
class ListZonesResultTest extends AbstractTestClass
37
{
38
    /**
39
     * @Inject
40
     * @var ListZoneResultsFactory
41
     */
42
    private $factory;
43
44
    /**
45
     * @test
46
     */
47
    public function canBeCreatedUsingTheFactory()
48
    {
49
        $class = $this->createClass();
50
        $this->assertInstanceOf(ListZonesResult::class, $class);
51
    }
52
53
    /**
54
     * @test
55
     */
56
    public function canReturnTheId()
57
    {
58
        $class = $this->createClass();
59
        $this->assertEquals('023e105f4ecef8ad9ca31a8372d0c353', $class->getId());
60
    }
61
62
    /**
63
     * @test
64
     */
65
    public function canReturnTheName()
66
    {
67
        $class = $this->createClass();
68
        $this->assertEquals('example.com', $class->getName());
69
    }
70
71
    /**
72
     * @test
73
     */
74
    public function canReturnTheDevelopmentMode()
75
    {
76
        $class = $this->createClass();
77
        $this->assertEquals(7200, $class->getDevelopmentMode());
78
    }
79
80
    /**
81
     * @test
82
     */
83
    public function canReturnTheOriginalNameServers()
84
    {
85
        $class       = $this->createClass();
86
        $expected    = [
87
            "ns1.originaldnshost.com",
88
            "ns2.originaldnshost.com",
89
        ];
90
        $nameServers = $class->getOriginalNameServers();
91
        $this->assertInternalType('array', $nameServers);
92
        $this->assertEquals($expected, $nameServers);
93
    }
94
95
    /**
96
     * @test
97
     */
98
    public function canReturnTheOriginalRegistrar()
99
    {
100
        $class = $this->createClass();
101
        $this->assertEquals('GoDaddy', $class->getOriginalRegistrar());
102
    }
103
104
    /**
105
     * @test
106
     */
107
    public function canReturnTheOriginalDnsHost()
108
    {
109
        $class = $this->createClass();
110
        $this->assertEquals('NameCheap', $class->getOriginalDnsHost());
111
    }
112
113
    /**
114
     * @test
115
     */
116
    public function canReturnTheCreatedOn()
117
    {
118
        $class = $this->createClass();
119
        $this->assertEquals('2014-01-01T05:20:00.12345Z', $class->getCreatedOn());
120
    }
121
122
    /**
123
     * @test
124
     */
125
    public function canReturnTheModifiedOn()
126
    {
127
        $class = $this->createClass();
128
        $this->assertEquals('2014-01-01T05:20:00.12345Z', $class->getModifiedOn());
129
    }
130
131
    /**
132
     * @test
133
     */
134
    public function canReturnTheOwner()
135
    {
136
        $class = $this->createClass();
137
        $this->assertInstanceOf(Owner::class, $class->getOwner());
138
    }
139
140
    /**
141
     * @test
142
     */
143
    public function canReturnThePermissions()
144
    {
145
        $class       = $this->createClass();
146
        $expected    = [
147
            "#zone:read",
148
            "#zone:edit",
149
        ];
150
        $permissions = $class->getPermissions();
151
        $this->assertInternalType('array', $permissions);
152
        $this->assertEquals($expected, $permissions);
153
    }
154
155
    /**
156
     * @test
157
     */
158
    public function canReturnThePlan()
159
    {
160
        $class = $this->createClass();
161
        $this->assertInstanceOf(Plan::class, $class->getPlan());
162
    }
163
164
    /**
165
     * @test
166
     */
167
    public function canReturnThePlanPending()
168
    {
169
        $class = $this->createClass();
170
        $this->assertInstanceOf(Plan::class, $class->getPlanPending());
171
    }
172
173
    /**
174
     * @test
175
     */
176
    public function canReturnTheStatus()
177
    {
178
        $class = $this->createClass();
179
        $this->assertEquals('active', $class->getStatus());
180
    }
181
182
    /**
183
     * @test
184
     */
185
    public function canReturnIsPaused()
186
    {
187
        $class = $this->createClass();
188
        $this->assertFalse($class->isPaused());
189
    }
190
191
    /**
192
     * @test
193
     */
194
    public function canReturnTheType()
195
    {
196
        $class = $this->createClass();
197
        $this->assertEquals('full', $class->getType());
198
    }
199
200
    /**
201
     * @test
202
     */
203
    public function canReturnTheNameServers()
204
    {
205
        $class       = $this->createClass();
206
        $expected    = [
207
            "tony.ns.cloudflare.com",
208
            "woz.ns.cloudflare.com",
209
        ];
210
        $nameServers = $class->getNameServers();
211
        $this->assertInternalType('array', $nameServers);
212
        $this->assertEquals($expected, $nameServers);
213
    }
214
215
    /**
216
     * @test
217
     */
218
    public function willThrowAnExceptionIfTheIdIsMissing()
219
    {
220
        $json = $this->getExampleJson();
221
        unset($json->id);
222
        $this->expectException(LogicException::class);
223
        $this->createClass($json);
224
    }
225
226
    /**
227
     * @test
228
     */
229
    public function willThrowAnExceptionIfTheNameIsMissing()
230
    {
231
        $json = $this->getExampleJson();
232
        unset($json->name);
233
        $this->expectException(LogicException::class);
234
        $this->createClass($json);
235
    }
236
237
    /**
238
     * @test
239
     */
240
    public function willThrowAnExceptionIfTheDevelopmentModeIsMissing()
241
    {
242
        $json = $this->getExampleJson();
243
        unset($json->development_mode);
244
        $this->expectException(LogicException::class);
245
        $this->createClass($json);
246
    }
247
248
    /**
249
     * @test
250
     */
251
    public function willThrowAnExceptionIfTheOriginalNameServersIsMissing()
252
    {
253
        $json = $this->getExampleJson();
254
        unset($json->original_name_servers);
255
        $this->expectException(LogicException::class);
256
        $this->createClass($json);
257
    }
258
259
    /**
260
     * @test
261
     */
262
    public function willThrowAnExceptionIfTheOriginalRegistrarIsMissing()
263
    {
264
        $json = $this->getExampleJson();
265
        unset($json->original_registrar);
266
        $this->expectException(LogicException::class);
267
        $this->createClass($json);
268
    }
269
270
    /**
271
     * @test
272
     */
273
    public function willThrowAnExceptionIfTheOriginalDnsHostIsMissing()
274
    {
275
        $json = $this->getExampleJson();
276
        unset($json->original_dnshost);
277
        $this->expectException(LogicException::class);
278
        $this->createClass($json);
279
    }
280
281
    /**
282
     * @test
283
     */
284
    public function willThrowAnExceptionIfTheCreatedOnIsMissing()
285
    {
286
        $json = $this->getExampleJson();
287
        unset($json->created_on);
288
        $this->expectException(LogicException::class);
289
        $this->createClass($json);
290
    }
291
292
    /**
293
     * @test
294
     */
295
    public function willThrowAnExceptionIfTheModifiedOnIsMissing()
296
    {
297
        $json = $this->getExampleJson();
298
        unset($json->modified_on);
299
        $this->expectException(LogicException::class);
300
        $this->createClass($json);
301
    }
302
303
    /**
304
     * @test
305
     */
306
    public function willThrowAnExceptionIfTheOwnerIsMissing()
307
    {
308
        $json = $this->getExampleJson();
309
        unset($json->owner);
310
        $this->expectException(LogicException::class);
311
        $this->createClass($json);
312
    }
313
314
    /**
315
     * @test
316
     */
317
    public function willThrowAnExceptionIfThePermissionsIsMissing()
318
    {
319
        $json = $this->getExampleJson();
320
        unset($json->permissions);
321
        $this->expectException(LogicException::class);
322
        $this->createClass($json);
323
    }
324
325
    /**
326
     * @test
327
     */
328
    public function willThrowAnExceptionIfThePlanIsMissing()
329
    {
330
        $json = $this->getExampleJson();
331
        unset($json->plan);
332
        $this->expectException(LogicException::class);
333
        $this->createClass($json);
334
    }
335
336
    /**
337
     * @test
338
     */
339
    public function willThrowAnExceptionIfThePlanPendingIsMissing()
340
    {
341
        $json = $this->getExampleJson();
342
        unset($json->plan_pending);
343
        $this->expectException(LogicException::class);
344
        $this->createClass($json);
345
    }
346
347
    /**
348
     * @test
349
     */
350
    public function willThrowAnExceptionIfTheStatusIsMissing()
351
    {
352
        $json = $this->getExampleJson();
353
        unset($json->status);
354
        $this->expectException(LogicException::class);
355
        $this->createClass($json);
356
    }
357
358
    /**
359
     * @test
360
     */
361
    public function willThrowAnExceptionIfIsPausedIsMissing()
362
    {
363
        $json = $this->getExampleJson();
364
        unset($json->paused);
365
        $this->expectException(LogicException::class);
366
        $this->createClass($json);
367
    }
368
369
    /**
370
     * @test
371
     */
372
    public function willThrowAnExceptionIfTheTypeIsMissing()
373
    {
374
        $json = $this->getExampleJson();
375
        unset($json->type);
376
        $this->expectException(LogicException::class);
377
        $this->createClass($json);
378
    }
379
380
    /**
381
     * @test
382
     */
383
    public function willThrowAnExceptionIfTheNameServersIsMissing()
384
    {
385
        $json = $this->getExampleJson();
386
        unset($json->name_servers);
387
        $this->expectException(LogicException::class);
388
        $this->createClass($json);
389
    }
390
391
    private function createClass(\stdClass $json = null)
392
    {
393
        if ($json === null) {
394
            $json = $this->getExampleJson();
395
        }
396
397
        return $this->factory->create($json);
398
    }
399
400
    /**
401
     * Taken from here https://api.cloudflare.com/#zone-list-zones
402
     * @return \stdClass
403
     */
404
    private function getExampleJson(): \stdClass
405
    {
406
        $data = <<<JSON
407
{
408
    "id": "023e105f4ecef8ad9ca31a8372d0c353",
409
    "name": "example.com",
410
    "development_mode": 7200,
411
    "original_name_servers": [
412
        "ns1.originaldnshost.com",
413
        "ns2.originaldnshost.com"
414
    ],
415
    "original_registrar": "GoDaddy",
416
    "original_dnshost": "NameCheap",
417
    "created_on": "2014-01-01T05:20:00.12345Z",
418
    "modified_on": "2014-01-01T05:20:00.12345Z",
419
    "owner": {
420
        "id": "7c5dae5552338874e5053f2534d2767a",
421
        "email": "[email protected]",
422
        "owner_type": "user"
423
    },
424
    "permissions": [
425
        "#zone:read",
426
        "#zone:edit"
427
    ],
428
    "plan": {
429
        "id": "e592fd9519420ba7405e1307bff33214",
430
        "name": "Pro Plan",
431
        "price": 20,
432
        "currency": "USD",
433
        "frequency": "monthly",
434
        "legacy_id": "pro",
435
        "is_subscribed": true,
436
        "can_subscribe": true
437
    },
438
    "plan_pending": {
439
        "id": "e592fd9519420ba7405e1307bff33214",
440
        "name": "Pro Plan",
441
        "price": 20,
442
        "currency": "USD",
443
        "frequency": "monthly",
444
        "legacy_id": "pro",
445
        "is_subscribed": true,
446
        "can_subscribe": true
447
    },
448
    "status": "active",
449
    "paused": false,
450
    "type": "full",
451
    "name_servers": [
452
        "tony.ns.cloudflare.com",
453
        "woz.ns.cloudflare.com"
454
    ]
455
}
456
JSON;
457
458
        return \json_decode($data);
459
    }
460
}
461