SearchOrdersRequestTest   A
last analyzed

Complexity

Total Complexity 26

Size/Duplication

Total Lines 365
Duplicated Lines 16.71 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 26
lcom 1
cbo 5
dl 61
loc 365
rs 10
c 2
b 0
f 0

26 Methods

Rating   Name   Duplication   Size   Complexity  
A it_sets_seller_id_and_returns_itself() 9 9 1
A it_sets_ordered_datetime_range_and_returns_itself() 0 13 1
A it_cannot_set_ordered_datetime_range_when_to_is_earlier_than_from() 9 9 1
A it_cannot_set_to_of_ordered_datetime_range_more_than_once() 7 7 1
A it_sets_offset() 11 11 1
A it_cannot_set_offset_to_less_than_zero() 0 6 1
A it_cannot_set_limit_more_than_once() 0 8 1
A it_cannot_set_limit_to_less_than_zero() 0 6 1
A it_sets_order_id_and_returns_itself() 0 9 1
A it_cannot_order_id_seen_more_than_once() 0 7 1
A it_cannot_set_seller_id_more_than_once() 0 7 1
A it_sets_is_seen_and_returns_itself() 0 9 1
A it_cannot_set_is_seen_more_than_once() 0 7 1
A it_does_not_set_ordered_datetime_range_when_null() 0 18 1
A it_cannot_set_from_of_ordered_datetime_range_more_than_once() 7 7 1
A it_cannot_set_ordered_datetime_range_to_both_null() 0 6 1
A it_sets_order_status_and_returns_itself() 0 12 1
A it_cannot_set_order_status_more_than_once() 0 10 1
A it_sets_ship_status_and_returns_itself() 0 12 1
A it_cannot_set_ship_status_more_than_once() 0 10 1
A it_sets_store_status_and_returns_itself() 0 12 1
A it_cannot_set_store_status_more_than_once() 0 7 1
A it_cannot_set_offset_more_than_once() 8 8 1
A it_sets_limit() 0 11 1
A it_validates_that_seller_id_is_set() 10 10 1
A it_validates_that_order_id_or_datetime_is_set() 0 8 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Shippinno\YahooShoppingJp\Request;
4
5
use DateTimeImmutable;
6
use PHPUnit\Framework\TestCase;
7
use Shippinno\YahooShoppingJp\Enum\OrderStatus;
8
use Shippinno\YahooShoppingJp\Enum\ShipStatus;
9
use Shippinno\YahooShoppingJp\Enum\StoreStatus;
10
11
class SearchOrdersRequestTest extends TestCase
12
{
13
    /**
14
     * @test
15
     */
16
    public function it_sets_order_id_and_returns_itself()
17
    {
18
        $request = new SearchOrdersRequest;
19
20
        $this->assertSame($request, $request->setSellerId('SELLER_ID')->setOrderId('ORDER_ID'));
21
        $simpleXml = simplexml_load_string($request->getParams());
22
23
        $this->assertEquals('ORDER_ID', $simpleXml->Search->Condition->OrderId->__toString());
24
    }
25
26
    /**
27
     * @test
28
     * @expectedException \LogicException
29
     */
30
    public function it_cannot_order_id_seen_more_than_once()
31
    {
32
        $request = new SearchOrdersRequest;
33
        $this->assertSame($request, $request->setSellerId('SELLER_ID')->setOrderId('ORDER_ID'));
34
35
        $request->setOrderId('ORDER_ID2');
36
    }
37
38
    /**
39
     * @test
40
     */
41 View Code Duplication
    public function it_sets_seller_id_and_returns_itself()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
42
    {
43
        $request = new SearchOrdersRequest;
44
45
        $this->assertSame($request, $request->setOrderId('ORDER_ID')->setSellerId('SELLER_ID'));
46
        $simpleXml = simplexml_load_string($request->getParams());
47
48
        $this->assertEquals('SELLER_ID', $simpleXml->SellerId->__toString());
49
    }
50
51
    /**
52
     * @test
53
     * @expectedException \LogicException
54
     */
55
    public function it_cannot_set_seller_id_more_than_once()
56
    {
57
        $request = new SearchOrdersRequest;
58
        $this->assertSame($request, $request->setOrderId('ORDER_ID')->setSellerId('SELLER_ID_1'));
59
60
        $request->setSellerId('SELLER_ID_2');
61
    }
62
63
    /**
64
     * @test
65
     */
66
    public function it_sets_is_seen_and_returns_itself()
67
    {
68
        $request = new SearchOrdersRequest;
69
70
        $this->assertSame($request, $request->setOrderId('ORDER_ID')->setSellerId('SELLER_ID')->setIsSeen(true));
71
        $simpleXml = simplexml_load_string($request->getParams());
72
73
        $this->assertEquals('true', $simpleXml->Search->Condition->IsSeen->__toString());
74
    }
75
76
    /**
77
     * @test
78
     * @expectedException \LogicException
79
     */
80
    public function it_cannot_set_is_seen_more_than_once()
81
    {
82
        $request = new SearchOrdersRequest;
83
        $this->assertSame($request, $request->setOrderId('ORDER_ID')->setSellerId('SELLER_ID')->setIsSeen(false));
84
85
        $request->setIsSeen(true);
86
    }
87
88
    /**
89
     * @test
90
     */
91
    public function it_sets_ordered_datetime_range_and_returns_itself()
92
    {
93
        $request = new SearchOrdersRequest;
94
        $this->assertSame($request, $request->setSellerId('SELLER_ID'));
95
        $from = new DateTimeImmutable('2000-01-01 00:00:00');
96
        $to = new DateTimeImmutable('2000-01-01 00:00:01');
97
98
        $this->assertSame($request, $request->setOrderedDateTimeRange($from, $to));
99
        $simpleXml = simplexml_load_string($request->getParams());
100
101
        $this->assertEquals($from->format('YmdHis'), $simpleXml->Search->Condition->OrderTimeFrom->__toString());
102
        $this->assertEquals($to->format('YmdHis'), $simpleXml->Search->Condition->OrderTimeTo->__toString());
103
    }
104
105
    /**
106
     * @test
107
     * @expectedException \LogicException
108
     */
109 View Code Duplication
    public function it_cannot_set_ordered_datetime_range_when_to_is_earlier_than_from()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
110
    {
111
        $request = new SearchOrdersRequest;
112
        $this->assertSame($request, $request->setSellerId('SELLER_ID'));
113
        $from = new DateTimeImmutable('2000-01-01 00:00:01');
114
        $to = new DateTimeImmutable('2000-01-01 00:00:00');
115
116
        $request->setOrderedDateTimeRange($from, $to);
117
    }
118
119
    /**
120
     * @test
121
     */
122
    public function it_does_not_set_ordered_datetime_range_when_null()
123
    {
124
        $request = new SearchOrdersRequest;
125
        $this->assertSame($request, $request->setOrderId('ORDER_ID')->setSellerId('SELLER_ID'));
126
127
        $this->assertSame($request, $request->setOrderedDateTimeRange(null, new DateTimeImmutable()));
128
        $simpleXml = simplexml_load_string($request->getParams());
129
        $this->assertFalse(isset($simpleXml->Search->Condition->OrderTimeFrom));
130
131
132
        $request = new SearchOrdersRequest;
133
        $this->assertSame($request, $request->setOrderId('ORDER_ID')->setSellerId('SELLER_ID'));
134
135
        $this->assertSame($request, $request->setOrderedDateTimeRange(new DateTimeImmutable(), null));
136
        $simpleXml = simplexml_load_string($request->getParams());
137
138
        $this->assertFalse(isset($simpleXml->Search->Condition->OrderTimeTo));
139
    }
140
141
    /**
142
     * @test
143
     * @expectedException \LogicException
144
     */
145 View Code Duplication
    public function it_cannot_set_from_of_ordered_datetime_range_more_than_once()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
146
    {
147
        $request = new SearchOrdersRequest;
148
        $this->assertSame($request, $request->setOrderedDateTimeRange(new DateTimeImmutable, null));
149
150
        $request->setOrderedDateTimeRange(new DateTimeImmutable, null);
151
    }
152
153
    /**
154
     * @test
155
     * @expectedException \LogicException
156
     */
157 View Code Duplication
    public function it_cannot_set_to_of_ordered_datetime_range_more_than_once()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
158
    {
159
        $request = new SearchOrdersRequest;
160
        $this->assertSame($request, $request->setOrderedDateTimeRange(null, new DateTimeImmutable));
161
162
        $request->setOrderedDateTimeRange(null, new DateTimeImmutable);
163
    }
164
165
    /**
166
     * @test
167
     * @expectedException \InvalidArgumentException
168
     */
169
    public function it_cannot_set_ordered_datetime_range_to_both_null()
170
    {
171
        $request = new SearchOrdersRequest;
172
173
        $request->setOrderedDateTimeRange(null, null);
174
    }
175
176
    /**
177
     * @test
178
     */
179
    public function it_sets_order_status_and_returns_itself()
180
    {
181
        $request = new SearchOrdersRequest;
182
183
        $this->assertSame($request,
184
            $request->setOrderId('ORDER_ID')
185
                ->setSellerId('SELLER_ID')
186
                ->setOrderStatus(OrderStatus::PREORDERED()));
187
        $simpleXml = simplexml_load_string($request->getParams());
188
189
        $this->assertEquals(OrderStatus::PREORDERED()->getValue(), $simpleXml->Search->Condition->OrderStatus->__toString());
190
    }
191
192
    /**
193
     * @test
194
     * @expectedException \LogicException
195
     */
196
    public function it_cannot_set_order_status_more_than_once()
197
    {
198
        $request = new SearchOrdersRequest;
199
        $this->assertSame($request,
200
            $request->setOrderId('ORDER_ID')
201
                ->setSellerId('SELLER_ID')
202
                ->setOrderStatus(OrderStatus::PROCESSED()));
203
204
        $request->setOrderStatus(OrderStatus::PROCESSING());
205
    }
206
207
    /**
208
     * @test
209
     */
210
    public function it_sets_ship_status_and_returns_itself()
211
    {
212
        $request = new SearchOrdersRequest;
213
214
        $this->assertSame($request,
215
            $request->setOrderId('ORDER_ID')
216
                ->setSellerId('SELLER_ID')
217
                ->setShipStatus(ShipStatus::SHIPPABLE()));
218
        $simpleXml = simplexml_load_string($request->getParams());
219
220
        $this->assertEquals(ShipStatus::SHIPPABLE()->getValue(), $simpleXml->Search->Condition->ShipStatus->__toString());
221
    }
222
223
    /**
224
     * @test
225
     * @expectedException \LogicException
226
     */
227
    public function it_cannot_set_ship_status_more_than_once()
228
    {
229
        $request = new SearchOrdersRequest;
230
        $this->assertSame($request,
231
            $request->setOrderId('ORDER_ID')
232
                ->setSellerId('SELLER_ID')
233
                ->setShipStatus(ShipStatus::SHIPPED()));
234
235
        $request->setShipStatus(ShipStatus::UNSHIPPABLE());
236
    }
237
238
    /**
239
     * @test
240
     */
241
    public function it_sets_store_status_and_returns_itself()
242
    {
243
        $request = new SearchOrdersRequest;
244
245
        $this->assertSame($request,
246
            $request->setOrderId('ORDER_ID')
247
                ->setSellerId('SELLER_ID')
248
                ->setStoreStatus(StoreStatus::STORE_STATUS1()));
249
        $simpleXml = simplexml_load_string($request->getParams());
250
251
        $this->assertEquals(StoreStatus::STORE_STATUS1()->getValue(), $simpleXml->Search->Condition->StoreStatus->__toString());
252
    }
253
254
    /**
255
     * @test
256
     * @expectedException \LogicException
257
     */
258
    public function it_cannot_set_store_status_more_than_once()
259
    {
260
        $request = new SearchOrdersRequest;
261
        $this->assertSame($request, $request->setSellerId('SELLER_ID')->setStoreStatus(StoreStatus::STORE_STATUS2()));
262
263
        $request->setStoreStatus(StoreStatus::STORE_STATUS3());
264
    }
265
266
    /**
267
     * @test
268
     */
269 View Code Duplication
    public function it_sets_offset()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
270
    {
271
        $request = new SearchOrdersRequest;
272
        $this->assertSame($request, $request->setOrderId('ORDER_ID')->setSellerId('SELLER_ID'));
273
274
        $request->setOffset(5);
275
        $simpleXml = simplexml_load_string($request->getParams());
276
277
        $this->assertEquals(6, $simpleXml->Search->Start->__toString());
278
279
    }
280
281
    /**
282
     * @test
283
     * @expectedException \LogicException
284
     */
285 View Code Duplication
    public function it_cannot_set_offset_more_than_once()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
286
    {
287
        $request = new SearchOrdersRequest;
288
        $this->assertSame($request, $request->setOrderId('ORDER_ID')->setSellerId('SELLER_ID'));
289
        $this->assertSame($request, $request->setOffset(5));
290
291
        $request->setOffset(5);
292
    }
293
294
    /**
295
     * @test
296
     * @expectedException \InvalidArgumentException
297
     */
298
    public function it_cannot_set_offset_to_less_than_zero()
299
    {
300
        $request = new SearchOrdersRequest;
301
302
        $request->setOffset(-1);
303
    }
304
305
306
307
308
    /**
309
     * @test
310
     */
311
    public function it_sets_limit()
312
    {
313
        $request = new SearchOrdersRequest;
314
        $this->assertSame($request, $request->setOrderId('ORDER_ID')->setSellerId('SELLER_ID'));
315
316
        $request->setLimit(5);
317
        $simpleXml = simplexml_load_string($request->getParams());
318
319
        $this->assertEquals(5, $simpleXml->Search->Result->__toString());
320
321
    }
322
323
    /**
324
     * @test
325
     * @expectedException \LogicException
326
     */
327
    public function it_cannot_set_limit_more_than_once()
328
    {
329
        $request = new SearchOrdersRequest;
330
        $this->assertSame($request, $request->setSellerId('SELLER_ID'));
331
        $this->assertSame($request, $request->setLimit(5));
332
333
        $request->setLimit(5);
334
    }
335
336
    /**
337
     * @test
338
     * @expectedException \InvalidArgumentException
339
     */
340
    public function it_cannot_set_limit_to_less_than_zero()
341
    {
342
        $request = new SearchOrdersRequest;
343
344
        $request->setLimit(-1);
345
    }
346
347
    /**
348
     * @test
349
     * @expectedException \Shippinno\YahooShoppingJp\Exception\InvalidRequestException
350
     */
351 View Code Duplication
    public function it_validates_that_seller_id_is_set()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
352
    {
353
        $request = new SearchOrdersRequest;
354
        $from = new DateTimeImmutable('2000-01-01 00:00:00');
355
        $to = new DateTimeImmutable('2000-01-02 00:00:00');
356
357
        $this->assertSame($request, $request->setOrderedDateTimeRange($from, $to));
358
359
        $request->getParams();
360
    }
361
362
    /**
363
     * @test
364
     * @expectedException \Shippinno\YahooShoppingJp\Exception\InvalidRequestException
365
     * @expectedExceptionMessage OrderId,OrderTime or OrderTimeFrom&OrderTimeTo is necessary.
366
     */
367
    public function it_validates_that_order_id_or_datetime_is_set()
368
    {
369
        $request = new SearchOrdersRequest;
370
371
        $this->assertSame($request, $request->setSellerId('SELLER_ID'));
372
373
        $request->getParams();
374
    }
375
}
376