Test Failed
Pull Request — master (#19)
by
unknown
02:23
created

UpdateOrderShippingStatusRequestTest   A

Complexity

Total Complexity 26

Size/Duplication

Total Lines 392
Duplicated Lines 33.16 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 26
lcom 1
cbo 3
dl 130
loc 392
rs 10
c 1
b 0
f 0

26 Methods

Rating   Name   Duplication   Size   Complexity  
A it_sets_seller_id_and_returns_itself() 0 13 1
A it_cannot_set_seller_id_more_than_once() 0 7 1
A it_sets_order_id_and_returns_itself() 0 13 1
A it_cannot_set_order_id_more_than_once() 0 7 1
A it_sets_is_point_fix_and_returns_itself() 0 13 1
A it_cannot_set_is_point_fix_more_than_once() 0 7 1
A it_sets_operation_user_and_returns_itself() 14 14 1
A it_cannot_set_operation_user_more_than_once() 0 7 1
A it_sets_ship_status_and_returns_itself() 0 13 1
A it_cannot_set_ship_status_more_than_once() 0 7 1
A it_sets_ship_method_and_returns_itself() 14 14 1
A it_cannot_set_ship_method_more_than_once() 0 7 1
A it_cannot_set_ship_method_invalid_string() 0 5 1
A it_sets_ship_notes_and_returns_itself() 14 14 1
A it_cannot_set_ship_notes_more_than_once() 0 7 1
A it_cannot_set_ship_notes_too_long_string() 0 15 1
A it_sets_ship_invoice_number1_and_returns_itself() 14 14 1
A it_cannot_set_ship_invoice_number1_more_than_once() 0 7 1
A it_sets_ship_invoice_number2_and_returns_itself() 14 14 1
A it_cannot_set_ship_invoice_number2_more_than_once() 0 7 1
A it_sets_ship_url_and_returns_itself() 14 14 1
A it_cannot_set_ship_url_more_than_once() 0 7 1
A it_sets_ship_date_and_returns_itself() 16 16 1
A it_cannot_set_ship_date_more_than_once() 7 7 1
A it_sets_arrival_date_and_returns_itself() 16 16 1
A it_cannot_set_arrival_date_more_than_once() 7 7 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\ShipStatus;
8
9
class UpdateOrderShippingStatusRequestTest extends TestCase
10
{
11
    /**
12
     * @test
13
     */
14
    public function it_sets_seller_id_and_returns_itself()
15
    {
16
        $request = new UpdateOrderShippingStatusRequest;
17
18
        $this->assertSame($request,
19
                        $request->setSellerId('SELLER_ID')
20
                                ->setOrderId('ORDER_ID')
21
                                ->setIsPointFix(true)
22
                                ->setShipStatus(ShipStatus::SHIPPABLE()));
23
        $simpleXml = simplexml_load_string($request->getParams());
24
25
        $this->assertEquals('SELLER_ID', $simpleXml->SellerId->__toString());
26
    }
27
28
    /**
29
     * @test
30
     * @expectedException \LogicException
31
     */
32
    public function it_cannot_set_seller_id_more_than_once()
33
    {
34
        $request = new UpdateOrderShippingStatusRequest;
35
        $this->assertSame($request, $request->setSellerId('SELLER_ID_1'));
36
37
        $request->setSellerId('SELLER_ID_2');
38
    }
39
40
    /**
41
     * @test
42
     */
43
    public function it_sets_order_id_and_returns_itself()
44
    {
45
        $request = new UpdateOrderShippingStatusRequest;
46
47
        $this->assertSame($request,
48
            $request->setSellerId('SELLER_ID')
49
                ->setOrderId('ORDER_ID')
50
                ->setIsPointFix(true)
51
                ->setShipStatus(ShipStatus::SHIPPABLE()));
52
        $simpleXml = simplexml_load_string($request->getParams());
53
54
        $this->assertEquals('ORDER_ID', $simpleXml->Target->OrderId->__toString());
55
    }
56
57
    /**
58
     * @test
59
     * @expectedException \LogicException
60
     */
61
    public function it_cannot_set_order_id_more_than_once()
62
    {
63
        $request = new UpdateOrderShippingStatusRequest;
64
        $this->assertSame($request, $request->setOrderId('ORDER_ID_1'));
65
66
        $request->setOrderId('ORDER_ID_2');
67
    }
68
69
    /**
70
     * @test
71
     */
72
    public function it_sets_is_point_fix_and_returns_itself()
73
    {
74
        $request = new UpdateOrderShippingStatusRequest;
75
76
        $this->assertSame($request,
77
            $request->setSellerId('SELLER_ID')
78
                ->setOrderId('ORDER_ID')
79
                ->setIsPointFix(false)
80
                ->setShipStatus(ShipStatus::SHIPPABLE()));
81
        $simpleXml = simplexml_load_string($request->getParams());
82
83
        $this->assertEquals('false', $simpleXml->Target->IsPointFix->__toString());
84
    }
85
86
    /**
87
     * @test
88
     * @expectedException \LogicException
89
     */
90
    public function it_cannot_set_is_point_fix_more_than_once()
91
    {
92
        $request = new UpdateOrderShippingStatusRequest;
93
        $this->assertSame($request, $request->setIsPointFix(true));
94
95
        $request->setIsPointFix(false);
96
    }
97
98
    /**
99
     * @test
100
     */
101 View Code Duplication
    public function it_sets_operation_user_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...
102
    {
103
        $request = new UpdateOrderShippingStatusRequest;
104
105
        $this->assertSame($request,
106
            $request->setSellerId('SELLER_ID')
107
                ->setOrderId('ORDER_ID')
108
                ->setIsPointFix(true)
109
                ->setShipStatus(ShipStatus::SHIPPABLE())
110
                ->setOperationUser('OPERATION_USER'));
111
        $simpleXml = simplexml_load_string($request->getParams());
112
113
        $this->assertEquals('OPERATION_USER', $simpleXml->Target->OperationUser->__toString());
114
    }
115
116
    /**
117
     * @test
118
     * @expectedException \LogicException
119
     */
120
    public function it_cannot_set_operation_user_more_than_once()
121
    {
122
        $request = new UpdateOrderShippingStatusRequest;
123
        $this->assertSame($request, $request->setOperationUser('OPERATION_USER_1'));
124
125
        $request->setOperationUser('OPERATION_USER_2');
126
    }
127
128
    /**
129
     * @test
130
     */
131
    public function it_sets_ship_status_and_returns_itself()
132
    {
133
        $request = new UpdateOrderShippingStatusRequest;
134
135
        $this->assertSame($request,
136
            $request->setSellerId('SELLER_ID')
137
                ->setOrderId('ORDER_ID')
138
                ->setIsPointFix(false)
139
                ->setShipStatus(ShipStatus::SHIPPABLE()));
140
        $simpleXml = simplexml_load_string($request->getParams());
141
142
        $this->assertEquals(ShipStatus::SHIPPABLE()->getValue(), $simpleXml->Order->Ship->ShipStatus->__toString());
143
    }
144
145
    /**
146
     * @test
147
     * @expectedException \LogicException
148
     */
149
    public function it_cannot_set_ship_status_more_than_once()
150
    {
151
        $request = new UpdateOrderShippingStatusRequest;
152
        $this->assertSame($request, $request->setShipStatus(ShipStatus::SHIPPED()));
153
154
        $request->setShipStatus(ShipStatus::DELIVERED());
155
    }
156
157
    /**
158
     * @test
159
     */
160 View Code Duplication
    public function it_sets_ship_method_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...
161
    {
162
        $request = new UpdateOrderShippingStatusRequest;
163
164
        $this->assertSame($request,
165
            $request->setSellerId('SELLER_ID')
166
                ->setOrderId('ORDER_ID')
167
                ->setIsPointFix(false)
168
                ->setShipStatus(ShipStatus::SHIPPABLE())
169
                ->setShipMethod('postage16'));
0 ignored issues
show
Documentation introduced by
'postage16' is of type string, but the function expects a object<Shippinno\YahooSh...gJp\Request\ShipMethod>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
170
        $simpleXml = simplexml_load_string($request->getParams());
171
172
        $this->assertEquals('postage16', $simpleXml->Order->Ship->ShipMethod->__toString());
173
    }
174
175
    /**
176
     * @test
177
     * @expectedException \LogicException
178
     */
179
    public function it_cannot_set_ship_method_more_than_once()
180
    {
181
        $request = new UpdateOrderShippingStatusRequest;
182
        $this->assertSame($request, $request->setShipMethod('postage1'));
0 ignored issues
show
Documentation introduced by
'postage1' is of type string, but the function expects a object<Shippinno\YahooSh...gJp\Request\ShipMethod>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
183
184
        $request->setShipMethod('postage2');
0 ignored issues
show
Documentation introduced by
'postage2' is of type string, but the function expects a object<Shippinno\YahooSh...gJp\Request\ShipMethod>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
185
    }
186
187
    /**
188
     * @test
189
     * @expectedException \InvalidArgumentException
190
     */
191
    public function it_cannot_set_ship_method_invalid_string()
192
    {
193
        $request = new UpdateOrderShippingStatusRequest;
194
        $request->setShipMethod('postageXX');
0 ignored issues
show
Documentation introduced by
'postageXX' is of type string, but the function expects a object<Shippinno\YahooSh...gJp\Request\ShipMethod>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
195
    }
196
197
    /**
198
     * @test
199
     */
200 View Code Duplication
    public function it_sets_ship_notes_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...
201
    {
202
        $request = new UpdateOrderShippingStatusRequest;
203
204
        $this->assertSame($request,
205
            $request->setSellerId('SELLER_ID')
206
                ->setOrderId('ORDER_ID')
207
                ->setIsPointFix(false)
208
                ->setShipStatus(ShipStatus::SHIPPABLE())
209
                ->setShipNotes('SHIP_NOTES'));
210
        $simpleXml = simplexml_load_string($request->getParams());
211
212
        $this->assertEquals('SHIP_NOTES', $simpleXml->Order->Ship->ShipNotes->__toString());
213
    }
214
215
    /**
216
     * @test
217
     * @expectedException \LogicException
218
     */
219
    public function it_cannot_set_ship_notes_more_than_once()
220
    {
221
        $request = new UpdateOrderShippingStatusRequest;
222
        $this->assertSame($request, $request->setShipNotes('SHIP_NOTES_1'));
223
224
        $request->setShipNotes('SHIP_NOTES_2');
225
    }
226
227
    /**
228
     * @test
229
     * @expectedException \InvalidArgumentException
230
     */
231
    public function it_cannot_set_ship_notes_too_long_string()
232
    {
233
        $request = new UpdateOrderShippingStatusRequest;
234
        $longStr = '12345678901234567890123456789012345678901234567890'
235
            .'12345678901234567890123456789012345678901234567890'
236
            .'12345678901234567890123456789012345678901234567890'
237
            .'12345678901234567890123456789012345678901234567890'
238
            .'12345678901234567890123456789012345678901234567890'
239
            .'12345678901234567890123456789012345678901234567890'
240
            .'12345678901234567890123456789012345678901234567890'
241
            .'12345678901234567890123456789012345678901234567890'
242
            .'12345678901234567890123456789012345678901234567890'
243
            .'12345678901234567890123456789012345678901234567890x';
244
        $request->setShipNotes($longStr);
245
    }
246
247
    /**
248
     * @test
249
     */
250 View Code Duplication
    public function it_sets_ship_invoice_number1_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...
251
    {
252
        $request = new UpdateOrderShippingStatusRequest;
253
254
        $this->assertSame($request,
255
            $request->setSellerId('SELLER_ID')
256
                ->setOrderId('ORDER_ID')
257
                ->setIsPointFix(false)
258
                ->setShipStatus(ShipStatus::SHIPPABLE())
259
                ->setShipInvoiceNumber1('SHIP_INVOICE_NUMBER1'));
260
        $simpleXml = simplexml_load_string($request->getParams());
261
262
        $this->assertEquals('SHIP_INVOICE_NUMBER1', $simpleXml->Order->Ship->ShipInvoiceNumber1->__toString());
263
    }
264
265
    /**
266
     * @test
267
     * @expectedException \LogicException
268
     */
269
    public function it_cannot_set_ship_invoice_number1_more_than_once()
270
    {
271
        $request = new UpdateOrderShippingStatusRequest;
272
        $this->assertSame($request, $request->setShipInvoiceNumber1('SHIP_INVOICE_NUMBER1_1'));
273
274
        $request->setShipInvoiceNumber1('SHIP_INVOICE_NUMBER1_2');
275
    }
276
277
    /**
278
     * @test
279
     */
280 View Code Duplication
    public function it_sets_ship_invoice_number2_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...
281
    {
282
        $request = new UpdateOrderShippingStatusRequest;
283
284
        $this->assertSame($request,
285
            $request->setSellerId('SELLER_ID')
286
                ->setOrderId('ORDER_ID')
287
                ->setIsPointFix(false)
288
                ->setShipStatus(ShipStatus::SHIPPABLE())
289
                ->setShipInvoiceNumber2('SHIP_INVOICE_NUMBER2'));
290
        $simpleXml = simplexml_load_string($request->getParams());
291
292
        $this->assertEquals('SHIP_INVOICE_NUMBER2', $simpleXml->Order->Ship->ShipInvoiceNumber2->__toString());
293
    }
294
295
    /**
296
     * @test
297
     * @expectedException \LogicException
298
     */
299
    public function it_cannot_set_ship_invoice_number2_more_than_once()
300
    {
301
        $request = new UpdateOrderShippingStatusRequest;
302
        $this->assertSame($request, $request->setShipInvoiceNumber2('SHIP_INVOICE_NUMBER2_1'));
303
304
        $request->setShipInvoiceNumber2('SHIP_INVOICE_NUMBER2_2');
305
    }
306
307
    /**
308
     * @test
309
     */
310 View Code Duplication
    public function it_sets_ship_url_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...
311
    {
312
        $request = new UpdateOrderShippingStatusRequest;
313
314
        $this->assertSame($request,
315
            $request->setSellerId('SELLER_ID')
316
                ->setOrderId('ORDER_ID')
317
                ->setIsPointFix(false)
318
                ->setShipStatus(ShipStatus::SHIPPABLE())
319
                ->setShipUrl('https://hogehoge'));
320
        $simpleXml = simplexml_load_string($request->getParams());
321
322
        $this->assertEquals('![CDATA[https://hogehoge]]', $simpleXml->Order->Ship->ShipUrl->__toString());
323
    }
324
325
    /**
326
     * @test
327
     * @expectedException \LogicException
328
     */
329
    public function it_cannot_set_ship_url_more_than_once()
330
    {
331
        $request = new UpdateOrderShippingStatusRequest;
332
        $this->assertSame($request, $request->setShipUrl('https://hogehoge'));
333
334
        $request->setShipUrl('https://hogehoge2');
335
    }
336
337
    /**
338
     * @test
339
     */
340 View Code Duplication
    public function it_sets_ship_date_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...
341
    {
342
        $request = new UpdateOrderShippingStatusRequest;
343
344
        date_default_timezone_set('UTC');
345
346
        $this->assertSame($request,
347
            $request->setSellerId('SELLER_ID')
348
                ->setOrderId('ORDER_ID')
349
                ->setIsPointFix(false)
350
                ->setShipStatus(ShipStatus::SHIPPABLE())
351
                ->setShipDate(new DateTimeImmutable('2017-04-11 20:00:00')));
352
        $simpleXml = simplexml_load_string($request->getParams());
353
354
        $this->assertEquals('20170412', $simpleXml->Order->Ship->ShipDate->__toString());
355
    }
356
357
    /**
358
     * @test
359
     * @expectedException \LogicException
360
     */
361 View Code Duplication
    public function it_cannot_set_ship_date_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...
362
    {
363
        $request = new UpdateOrderShippingStatusRequest;
364
        $this->assertSame($request, $request->setShipDate(new DateTimeImmutable('2017-04-11 20:00:00')));
365
366
        $request->setShipDate(new DateTimeImmutable('2017-04-11 21:00:00'));
367
    }
368
369
    /**
370
     * @test
371
     */
372 View Code Duplication
    public function it_sets_arrival_date_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...
373
    {
374
        $request = new UpdateOrderShippingStatusRequest;
375
376
        date_default_timezone_set('UTC');
377
378
        $this->assertSame($request,
379
            $request->setSellerId('SELLER_ID')
380
                ->setOrderId('ORDER_ID')
381
                ->setIsPointFix(false)
382
                ->setShipStatus(ShipStatus::SHIPPABLE())
383
                ->setArrivalDate(new DateTimeImmutable('2017-04-11 20:00:00')));
384
        $simpleXml = simplexml_load_string($request->getParams());
385
386
        $this->assertEquals('20170412', $simpleXml->Order->Ship->ArrivalDate->__toString());
387
    }
388
389
    /**
390
     * @test
391
     * @expectedException \LogicException
392
     */
393 View Code Duplication
    public function it_cannot_set_arrival_date_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...
394
    {
395
        $request = new UpdateOrderShippingStatusRequest;
396
        $this->assertSame($request, $request->setArrivalDate(new DateTimeImmutable('2017-04-11 20:00:00')));
397
398
        $request->setArrivalDate(new DateTimeImmutable('2017-04-11 21:00:00'));
399
    }
400
}
401