willThrowAnExceptionIfTheIsSubscribedIsMissing()   A
last analyzed

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\Responses\Results;
23
24
use RossMitchell\UpdateCloudFlare\Factories\Responses\Results\PlanFactory;
25
use RossMitchell\UpdateCloudFlare\Responses\Results\Plan;
26
use RossMitchell\UpdateCloudFlare\Tests\AbstractTestClass;
27
use RossMitchell\UpdateCloudFlare\Tests\Fakes\Helpers\ListZonesResponse;
28
use Symfony\Component\Console\Exception\LogicException;
29
30
/**
31
 * Class PlanTest
32
 * @testdox RossMitchell\UpdateCloudFlare\Responses\Results\Plan
33
 * @package RossMitchell\UpdateCloudFlare\Tests\Responses\Results
34
 */
35
class PlanTest extends AbstractTestClass
36
{
37
    /**
38
     * @Inject
39
     * @var PlanFactory
40
     */
41
    private $factory;
42
43
    /**
44
     * @Inject
45
     * @var ListZonesResponse
46
     */
47
    private $responseHelper;
48
49
    /**
50
     * @test
51
     */
52
    public function canCreateTheClassUsingTheFactory(): void
53
    {
54
        $class = $this->createClass();
55
        $this->assertInstanceOf(Plan::class, $class);
56
    }
57
58
    /**
59
     * @test
60
     */
61
    public function canReturnTheId(): void
62
    {
63
        $class = $this->createClass();
64
        $this->assertEquals('e592fd9519420ba7405e1307bff33214', $class->getId());
65
    }
66
67
    /**
68
     * @test
69
     */
70
    public function canReturnTheName(): void
71
    {
72
        $class = $this->createClass();
73
        $this->assertEquals('Pro Plan', $class->getName());
74
    }
75
76
    /**
77
     * @test
78
     */
79
    public function canReturnThePrice(): void
80
    {
81
        $class = $this->createClass();
82
        $this->assertEquals(20, $class->getPrice());
83
    }
84
85
    /**
86
     * @test
87
     */
88
    public function canReturnTheCurrency(): void
89
    {
90
        $class = $this->createClass();
91
        $this->assertEquals('USD', $class->getCurrency());
92
    }
93
94
    /**
95
     * @test
96
     */
97
    public function canReturnTheFrequency(): void
98
    {
99
        $class = $this->createClass();
100
        $this->assertEquals('monthly', $class->getFrequency());
101
    }
102
103
    /**
104
     * @test
105
     */
106
    public function canReturnTheLegacyId(): void
107
    {
108
        $class = $this->createClass();
109
        $this->assertEquals('pro', $class->getLegacyId());
110
    }
111
112
    /**
113
     * @test
114
     */
115
    public function canReturnTheIsSubscribed(): void
116
    {
117
        $class = $this->createClass();
118
        $this->assertTrue($class->getIsSubscribed());
119
    }
120
121
    /**
122
     * @test
123
     */
124
    public function canReturnTheCanSubscribe(): void
125
    {
126
        $class = $this->createClass();
127
        $this->assertTrue($class->getCanSubscribe());
128
    }
129
130
    /**
131
     * @test
132
     */
133
    public function willThrowAnExceptionIfTheIdIsMissing(): void
134
    {
135
        $json = $this->getJson();
136
        unset($json->id);
137
        $this->expectException(LogicException::class);
138
        $this->createClass($json);
139
    }
140
141
    /**
142
     * @test
143
     */
144
    public function willThrowAnExceptionIfTheNameIsMissing(): void
145
    {
146
        $json = $this->getJson();
147
        unset($json->name);
148
        $this->expectException(LogicException::class);
149
        $this->createClass($json);
150
    }
151
152
    /**
153
     * @test
154
     */
155
    public function willThrowAnExceptionIfThePriceIsMissing(): void
156
    {
157
        $json = $this->getJson();
158
        unset($json->price);
159
        $this->expectException(LogicException::class);
160
        $this->createClass($json);
161
    }
162
163
    /**
164
     * @test
165
     */
166
    public function willThrowAnExceptionIfTheCurrencyIsMissing(): void
167
    {
168
        $json = $this->getJson();
169
        unset($json->currency);
170
        $this->expectException(LogicException::class);
171
        $this->createClass($json);
172
    }
173
174
    /**
175
     * @test
176
     */
177
    public function willThrowAnExceptionIfTheFrequencyIsMissing(): void
178
    {
179
        $json = $this->getJson();
180
        unset($json->frequency);
181
        $this->expectException(LogicException::class);
182
        $this->createClass($json);
183
    }
184
185
    /**
186
     * @test
187
     */
188
    public function willThrowAnExceptionIfTheLegacyIdIsMissing(): void
189
    {
190
        $json = $this->getJson();
191
        unset($json->legacy_id);
192
        $this->expectException(LogicException::class);
193
        $this->createClass($json);
194
    }
195
196
    /**
197
     * @test
198
     */
199
    public function willThrowAnExceptionIfTheIsSubscribedIsMissing(): void
200
    {
201
        $json = $this->getJson();
202
        unset($json->is_subscribed);
203
        $this->expectException(LogicException::class);
204
        $this->createClass($json);
205
    }
206
207
    /**
208
     * @test
209
     */
210
    public function willThrowAnExceptionIfTheCanSubscribeIsMissing(): void
211
    {
212
        $json = $this->getJson();
213
        unset($json->can_subscribe);
214
        $this->expectException(LogicException::class);
215
        $this->createClass($json);
216
    }
217
218
    /**
219
     * @param \stdClass|null $json
220
     *
221
     * @return Plan
222
     */
223
    private function createClass(\stdClass $json = null): Plan
224
    {
225
        if ($json === null) {
226
            $json = $this->getJson();
227
        }
228
229
        return $this->factory->create($json);
230
    }
231
232
    /**
233
     * @return \stdClass
234
     */
235
    private function getJson(): \stdClass
236
    {
237
        $json = $this->responseHelper->getPlanJson();
238
239
        return \json_decode($json);
240
    }
241
}
242