Passed
Push — master ( 5a4662...8f9c8a )
by Ross
02:40
created

willThrowAnExceptionIfAnUndefinedZoneIsRequested()   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 declare(strict_types = 1);
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\Exceptions\CloudFlareException;
25
use RossMitchell\UpdateCloudFlare\Model\Requests\GetZoneId;
26
use RossMitchell\UpdateCloudFlare\Tests\AbstractTestClass;
27
use RossMitchell\UpdateCloudFlare\Tests\Fakes\Curl;
28
use RossMitchell\UpdateCloudFlare\Tests\Fakes\Helpers\ListZonesResponse;
29
use Symfony\Component\Console\Exception\LogicException;
30
31
/**
32
 * Class GetZoneIdTest
33
 * @testdox RossMitchell\UpdateCloudFlare\Model\Requests\GetZoneId
34
 * @package RossMitchell\UpdateCloudFlare\Tests\Model\Requests
35
 */
36
class GetZoneIdTest extends AbstractTestClass
37
{
38
    /**
39
     * @Inject
40
     * @var GetZoneId
41
     */
42
    private $getZoneId;
43
44
    /**
45
     * @Inject
46
     * @var Curl
47
     */
48
    private $curl;
49
50
    /**
51
     * @Inject
52
     * @var ListZonesResponse
53
     */
54
    private $responseHelper;
55
56
    /**
57
     * @test
58
     */
59
    public function canReturnTheExpectedZoneId()
60
    {
61
        $mockResponse = $this->getJson();
62
        $this->curl->setResponse($mockResponse);
63
        $id = $this->getZoneId->getZoneId();
64
        $this->assertEquals('023e105f4ecef8ad9ca31a8372d0c353', $id);
65
    }
66
67
    /**
68
     * @test
69
     */
70
    public function willThrowAnExceptionIfThereIsAnError()
71
    {
72
        $mockResponse = $this->getJson('false');
73
        $this->curl->setResponse($mockResponse);
74
        $this->expectException(CloudFlareException::class);
75
        $this->getZoneId->getZoneId();
76
    }
77
78
    /**
79
     * @test
80
     */
81
    public function willThrowAnExceptionIfAnUndefinedZoneIsRequested()
82
    {
83
        $mockResponse = $this->getJson();
84
        $this->curl->setResponse($mockResponse);
85
        $this->expectException(LogicException::class);
86
        $this->getZoneId->getZoneId(3);
87
    }
88
89
    /**
90
     * @param string $success
91
     *
92
     * @return string
93
     */
94
    private function getJson(string $success = 'true'): string
95
    {
96
        return $this->responseHelper->getFullJson($success);
97
    }
98
}
99