1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Shippinno\YahooShoppingJp\Request; |
4
|
|
|
|
5
|
|
|
use DateTimeImmutable; |
6
|
|
|
use PHPUnit\Framework\TestCase; |
7
|
|
|
use Shippinno\YahooShoppingJp\Enum\ShipMethod; |
8
|
|
|
use Shippinno\YahooShoppingJp\Enum\ShipStatus; |
9
|
|
|
|
10
|
|
|
class UpdateOrderShippingStatusRequestTest extends TestCase |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* @test |
14
|
|
|
*/ |
15
|
|
|
public function it_sets_seller_id_and_returns_itself() |
16
|
|
|
{ |
17
|
|
|
$request = new UpdateOrderShippingStatusRequest; |
18
|
|
|
|
19
|
|
|
$this->assertSame($request, |
20
|
|
|
$request->setSellerId('SELLER_ID') |
21
|
|
|
->setOrderId('ORDER_ID') |
22
|
|
|
->setIsPointFix(true) |
23
|
|
|
->setShipStatus(ShipStatus::SHIPPABLE())); |
24
|
|
|
$simpleXml = simplexml_load_string($request->getParams()); |
25
|
|
|
|
26
|
|
|
$this->assertEquals('SELLER_ID', $simpleXml->SellerId->__toString()); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @test |
31
|
|
|
* @expectedException \LogicException |
32
|
|
|
*/ |
33
|
|
|
public function it_cannot_set_seller_id_more_than_once() |
34
|
|
|
{ |
35
|
|
|
$request = new UpdateOrderShippingStatusRequest; |
36
|
|
|
$this->assertSame($request, $request->setSellerId('SELLER_ID_1')); |
37
|
|
|
|
38
|
|
|
$request->setSellerId('SELLER_ID_2'); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @test |
43
|
|
|
*/ |
44
|
|
|
public function it_sets_order_id_and_returns_itself() |
45
|
|
|
{ |
46
|
|
|
$request = new UpdateOrderShippingStatusRequest; |
47
|
|
|
|
48
|
|
|
$this->assertSame($request, |
49
|
|
|
$request->setSellerId('SELLER_ID') |
50
|
|
|
->setOrderId('ORDER_ID') |
51
|
|
|
->setIsPointFix(true) |
52
|
|
|
->setShipStatus(ShipStatus::SHIPPABLE())); |
53
|
|
|
$simpleXml = simplexml_load_string($request->getParams()); |
54
|
|
|
|
55
|
|
|
$this->assertEquals('ORDER_ID', $simpleXml->Target->OrderId->__toString()); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @test |
60
|
|
|
* @expectedException \LogicException |
61
|
|
|
*/ |
62
|
|
|
public function it_cannot_set_order_id_more_than_once() |
63
|
|
|
{ |
64
|
|
|
$request = new UpdateOrderShippingStatusRequest; |
65
|
|
|
$this->assertSame($request, $request->setOrderId('ORDER_ID_1')); |
66
|
|
|
|
67
|
|
|
$request->setOrderId('ORDER_ID_2'); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @test |
72
|
|
|
*/ |
73
|
|
|
public function it_sets_is_point_fix_and_returns_itself() |
74
|
|
|
{ |
75
|
|
|
$request = new UpdateOrderShippingStatusRequest; |
76
|
|
|
|
77
|
|
|
$this->assertSame($request, |
78
|
|
|
$request->setSellerId('SELLER_ID') |
79
|
|
|
->setOrderId('ORDER_ID') |
80
|
|
|
->setIsPointFix(false) |
81
|
|
|
->setShipStatus(ShipStatus::SHIPPABLE())); |
82
|
|
|
$simpleXml = simplexml_load_string($request->getParams()); |
83
|
|
|
|
84
|
|
|
$this->assertEquals('false', $simpleXml->Target->IsPointFix->__toString()); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @test |
89
|
|
|
* @expectedException \LogicException |
90
|
|
|
*/ |
91
|
|
|
public function it_cannot_set_is_point_fix_more_than_once() |
92
|
|
|
{ |
93
|
|
|
$request = new UpdateOrderShippingStatusRequest; |
94
|
|
|
$this->assertSame($request, $request->setIsPointFix(true)); |
95
|
|
|
|
96
|
|
|
$request->setIsPointFix(false); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @test |
101
|
|
|
*/ |
102
|
|
View Code Duplication |
public function it_sets_operation_user_and_returns_itself() |
|
|
|
|
103
|
|
|
{ |
104
|
|
|
$request = new UpdateOrderShippingStatusRequest; |
105
|
|
|
|
106
|
|
|
$this->assertSame($request, |
107
|
|
|
$request->setSellerId('SELLER_ID') |
108
|
|
|
->setOrderId('ORDER_ID') |
109
|
|
|
->setIsPointFix(true) |
110
|
|
|
->setShipStatus(ShipStatus::SHIPPABLE()) |
111
|
|
|
->setOperationUser('OPERATION_USER')); |
112
|
|
|
$simpleXml = simplexml_load_string($request->getParams()); |
113
|
|
|
|
114
|
|
|
$this->assertEquals('OPERATION_USER', $simpleXml->Target->OperationUser->__toString()); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* @test |
119
|
|
|
* @expectedException \LogicException |
120
|
|
|
*/ |
121
|
|
|
public function it_cannot_set_operation_user_more_than_once() |
122
|
|
|
{ |
123
|
|
|
$request = new UpdateOrderShippingStatusRequest; |
124
|
|
|
$this->assertSame($request, $request->setOperationUser('OPERATION_USER_1')); |
125
|
|
|
|
126
|
|
|
$request->setOperationUser('OPERATION_USER_2'); |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* @test |
131
|
|
|
*/ |
132
|
|
View Code Duplication |
public function it_sets_ship_status_and_returns_itself() |
|
|
|
|
133
|
|
|
{ |
134
|
|
|
$request = new UpdateOrderShippingStatusRequest; |
135
|
|
|
|
136
|
|
|
$this->assertSame($request, |
137
|
|
|
$request->setSellerId('SELLER_ID') |
138
|
|
|
->setOrderId('ORDER_ID') |
139
|
|
|
->setIsPointFix(false) |
140
|
|
|
->setShipStatus(ShipStatus::SHIPPABLE())); |
141
|
|
|
$simpleXml = simplexml_load_string($request->getParams()); |
142
|
|
|
|
143
|
|
|
$this->assertEquals(ShipStatus::SHIPPABLE()->getValue(), $simpleXml->Order->Ship->ShipStatus->__toString()); |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* @test |
148
|
|
|
* @expectedException \LogicException |
149
|
|
|
*/ |
150
|
|
|
public function it_cannot_set_ship_status_more_than_once() |
151
|
|
|
{ |
152
|
|
|
$request = new UpdateOrderShippingStatusRequest; |
153
|
|
|
$this->assertSame($request, $request->setShipStatus(ShipStatus::SHIPPED())); |
154
|
|
|
|
155
|
|
|
$request->setShipStatus(ShipStatus::DELIVERED()); |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
/** |
159
|
|
|
* @test |
160
|
|
|
*/ |
161
|
|
View Code Duplication |
public function it_sets_ship_method_and_returns_itself() |
|
|
|
|
162
|
|
|
{ |
163
|
|
|
$request = new UpdateOrderShippingStatusRequest; |
164
|
|
|
|
165
|
|
|
$this->assertSame($request, |
166
|
|
|
$request->setSellerId('SELLER_ID') |
167
|
|
|
->setOrderId('ORDER_ID') |
168
|
|
|
->setIsPointFix(false) |
169
|
|
|
->setShipStatus(ShipStatus::SHIPPABLE()) |
170
|
|
|
->setShipMethod(ShipMethod::METHOD1())); |
171
|
|
|
$simpleXml = simplexml_load_string($request->getParams()); |
172
|
|
|
|
173
|
|
|
$this->assertEquals(ShipMethod::METHOD1()->getValue(), $simpleXml->Order->Ship->ShipMethod->__toString()); |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
/** |
177
|
|
|
* @test |
178
|
|
|
* @expectedException \LogicException |
179
|
|
|
*/ |
180
|
|
|
public function it_cannot_set_ship_method_more_than_once() |
181
|
|
|
{ |
182
|
|
|
$request = new UpdateOrderShippingStatusRequest; |
183
|
|
|
$this->assertSame($request, $request->setShipMethod(ShipMethod::METHOD1())); |
184
|
|
|
|
185
|
|
|
$request->setShipMethod(ShipMethod::METHOD2()); |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
/** |
189
|
|
|
* @test |
190
|
|
|
*/ |
191
|
|
View Code Duplication |
public function it_sets_ship_notes_and_returns_itself() |
|
|
|
|
192
|
|
|
{ |
193
|
|
|
$request = new UpdateOrderShippingStatusRequest; |
194
|
|
|
|
195
|
|
|
$this->assertSame($request, |
196
|
|
|
$request->setSellerId('SELLER_ID') |
197
|
|
|
->setOrderId('ORDER_ID') |
198
|
|
|
->setIsPointFix(false) |
199
|
|
|
->setShipStatus(ShipStatus::SHIPPABLE()) |
200
|
|
|
->setShipNotes('SHIP_NOTES')); |
201
|
|
|
$simpleXml = simplexml_load_string($request->getParams()); |
202
|
|
|
|
203
|
|
|
$this->assertEquals('SHIP_NOTES', $simpleXml->Order->Ship->ShipNotes->__toString()); |
204
|
|
|
} |
205
|
|
|
|
206
|
|
|
/** |
207
|
|
|
* @test |
208
|
|
|
* @expectedException \LogicException |
209
|
|
|
*/ |
210
|
|
|
public function it_cannot_set_ship_notes_more_than_once() |
211
|
|
|
{ |
212
|
|
|
$request = new UpdateOrderShippingStatusRequest; |
213
|
|
|
$this->assertSame($request, $request->setShipNotes('SHIP_NOTES_1')); |
214
|
|
|
|
215
|
|
|
$request->setShipNotes('SHIP_NOTES_2'); |
216
|
|
|
} |
217
|
|
|
|
218
|
|
|
/** |
219
|
|
|
* @test |
220
|
|
|
* @expectedException \InvalidArgumentException |
221
|
|
|
*/ |
222
|
|
|
public function it_cannot_set_ship_notes_too_long_string() |
223
|
|
|
{ |
224
|
|
|
$request = new UpdateOrderShippingStatusRequest; |
225
|
|
|
$longStr = str_pad('SHIP_NOTES', 501, "_", STR_PAD_BOTH); |
226
|
|
|
$request->setShipNotes($longStr); |
227
|
|
|
} |
228
|
|
|
|
229
|
|
|
/** |
230
|
|
|
* @test |
231
|
|
|
*/ |
232
|
|
View Code Duplication |
public function it_sets_ship_invoice_number1_and_returns_itself() |
|
|
|
|
233
|
|
|
{ |
234
|
|
|
$request = new UpdateOrderShippingStatusRequest; |
235
|
|
|
|
236
|
|
|
$this->assertSame($request, |
237
|
|
|
$request->setSellerId('SELLER_ID') |
238
|
|
|
->setOrderId('ORDER_ID') |
239
|
|
|
->setIsPointFix(false) |
240
|
|
|
->setShipStatus(ShipStatus::SHIPPABLE()) |
241
|
|
|
->setShipInvoiceNumber1('SHIP_INVOICE_NUMBER1')); |
242
|
|
|
$simpleXml = simplexml_load_string($request->getParams()); |
243
|
|
|
|
244
|
|
|
$this->assertEquals('SHIP_INVOICE_NUMBER1', $simpleXml->Order->Ship->ShipInvoiceNumber1->__toString()); |
245
|
|
|
} |
246
|
|
|
|
247
|
|
|
/** |
248
|
|
|
* @test |
249
|
|
|
* @expectedException \LogicException |
250
|
|
|
*/ |
251
|
|
|
public function it_cannot_set_ship_invoice_number1_more_than_once() |
252
|
|
|
{ |
253
|
|
|
$request = new UpdateOrderShippingStatusRequest; |
254
|
|
|
$this->assertSame($request, $request->setShipInvoiceNumber1('SHIP_INVOICE_NUMBER1_1')); |
255
|
|
|
|
256
|
|
|
$request->setShipInvoiceNumber1('SHIP_INVOICE_NUMBER1_2'); |
257
|
|
|
} |
258
|
|
|
|
259
|
|
|
/** |
260
|
|
|
* @test |
261
|
|
|
*/ |
262
|
|
View Code Duplication |
public function it_sets_ship_invoice_number2_and_returns_itself() |
|
|
|
|
263
|
|
|
{ |
264
|
|
|
$request = new UpdateOrderShippingStatusRequest; |
265
|
|
|
|
266
|
|
|
$this->assertSame($request, |
267
|
|
|
$request->setSellerId('SELLER_ID') |
268
|
|
|
->setOrderId('ORDER_ID') |
269
|
|
|
->setIsPointFix(false) |
270
|
|
|
->setShipStatus(ShipStatus::SHIPPABLE()) |
271
|
|
|
->setShipInvoiceNumber2('SHIP_INVOICE_NUMBER2')); |
272
|
|
|
$simpleXml = simplexml_load_string($request->getParams()); |
273
|
|
|
|
274
|
|
|
$this->assertEquals('SHIP_INVOICE_NUMBER2', $simpleXml->Order->Ship->ShipInvoiceNumber2->__toString()); |
275
|
|
|
} |
276
|
|
|
|
277
|
|
|
/** |
278
|
|
|
* @test |
279
|
|
|
* @expectedException \LogicException |
280
|
|
|
*/ |
281
|
|
|
public function it_cannot_set_ship_invoice_number2_more_than_once() |
282
|
|
|
{ |
283
|
|
|
$request = new UpdateOrderShippingStatusRequest; |
284
|
|
|
$this->assertSame($request, $request->setShipInvoiceNumber2('SHIP_INVOICE_NUMBER2_1')); |
285
|
|
|
|
286
|
|
|
$request->setShipInvoiceNumber2('SHIP_INVOICE_NUMBER2_2'); |
287
|
|
|
} |
288
|
|
|
|
289
|
|
|
/** |
290
|
|
|
* @test |
291
|
|
|
*/ |
292
|
|
View Code Duplication |
public function it_sets_ship_url_and_returns_itself() |
|
|
|
|
293
|
|
|
{ |
294
|
|
|
$request = new UpdateOrderShippingStatusRequest; |
295
|
|
|
|
296
|
|
|
$this->assertSame($request, |
297
|
|
|
$request->setSellerId('SELLER_ID') |
298
|
|
|
->setOrderId('ORDER_ID') |
299
|
|
|
->setIsPointFix(false) |
300
|
|
|
->setShipStatus(ShipStatus::SHIPPABLE()) |
301
|
|
|
->setShipUrl('https://hogehoge')); |
302
|
|
|
$simpleXml = simplexml_load_string($request->getParams()); |
303
|
|
|
|
304
|
|
|
$this->assertEquals('![CDATA[https://hogehoge]]', $simpleXml->Order->Ship->ShipUrl->__toString()); |
305
|
|
|
} |
306
|
|
|
|
307
|
|
|
/** |
308
|
|
|
* @test |
309
|
|
|
* @expectedException \LogicException |
310
|
|
|
*/ |
311
|
|
|
public function it_cannot_set_ship_url_more_than_once() |
312
|
|
|
{ |
313
|
|
|
$request = new UpdateOrderShippingStatusRequest; |
314
|
|
|
$this->assertSame($request, $request->setShipUrl('https://hogehoge')); |
315
|
|
|
|
316
|
|
|
$request->setShipUrl('https://hogehoge2'); |
317
|
|
|
} |
318
|
|
|
|
319
|
|
|
/** |
320
|
|
|
* @test |
321
|
|
|
*/ |
322
|
|
View Code Duplication |
public function it_sets_ship_date_and_returns_itself() |
|
|
|
|
323
|
|
|
{ |
324
|
|
|
$request = new UpdateOrderShippingStatusRequest; |
325
|
|
|
|
326
|
|
|
date_default_timezone_set('UTC'); |
327
|
|
|
|
328
|
|
|
$this->assertSame($request, |
329
|
|
|
$request->setSellerId('SELLER_ID') |
330
|
|
|
->setOrderId('ORDER_ID') |
331
|
|
|
->setIsPointFix(false) |
332
|
|
|
->setShipStatus(ShipStatus::SHIPPABLE()) |
333
|
|
|
->setShipDate(new DateTimeImmutable('2017-04-11 20:00:00'))); |
334
|
|
|
$simpleXml = simplexml_load_string($request->getParams()); |
335
|
|
|
|
336
|
|
|
$this->assertEquals('20170412', $simpleXml->Order->Ship->ShipDate->__toString()); |
337
|
|
|
} |
338
|
|
|
|
339
|
|
|
/** |
340
|
|
|
* @test |
341
|
|
|
* @expectedException \LogicException |
342
|
|
|
*/ |
343
|
|
View Code Duplication |
public function it_cannot_set_ship_date_more_than_once() |
|
|
|
|
344
|
|
|
{ |
345
|
|
|
$request = new UpdateOrderShippingStatusRequest; |
346
|
|
|
$this->assertSame($request, $request->setShipDate(new DateTimeImmutable('2017-04-11 20:00:00'))); |
347
|
|
|
|
348
|
|
|
$request->setShipDate(new DateTimeImmutable('2017-04-11 21:00:00')); |
349
|
|
|
} |
350
|
|
|
|
351
|
|
|
/** |
352
|
|
|
* @test |
353
|
|
|
*/ |
354
|
|
View Code Duplication |
public function it_sets_arrival_date_and_returns_itself() |
|
|
|
|
355
|
|
|
{ |
356
|
|
|
$request = new UpdateOrderShippingStatusRequest; |
357
|
|
|
|
358
|
|
|
date_default_timezone_set('UTC'); |
359
|
|
|
|
360
|
|
|
$this->assertSame($request, |
361
|
|
|
$request->setSellerId('SELLER_ID') |
362
|
|
|
->setOrderId('ORDER_ID') |
363
|
|
|
->setIsPointFix(false) |
364
|
|
|
->setShipStatus(ShipStatus::SHIPPABLE()) |
365
|
|
|
->setArrivalDate(new DateTimeImmutable('2017-04-11 20:00:00'))); |
366
|
|
|
$simpleXml = simplexml_load_string($request->getParams()); |
367
|
|
|
|
368
|
|
|
$this->assertEquals('20170412', $simpleXml->Order->Ship->ArrivalDate->__toString()); |
369
|
|
|
} |
370
|
|
|
|
371
|
|
|
/** |
372
|
|
|
* @test |
373
|
|
|
* @expectedException \LogicException |
374
|
|
|
*/ |
375
|
|
View Code Duplication |
public function it_cannot_set_arrival_date_more_than_once() |
|
|
|
|
376
|
|
|
{ |
377
|
|
|
$request = new UpdateOrderShippingStatusRequest; |
378
|
|
|
$this->assertSame($request, $request->setArrivalDate(new DateTimeImmutable('2017-04-11 20:00:00'))); |
379
|
|
|
|
380
|
|
|
$request->setArrivalDate(new DateTimeImmutable('2017-04-11 21:00:00')); |
381
|
|
|
} |
382
|
|
|
} |
383
|
|
|
|
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.