1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Shippinno\YahooShoppingJp\Test\Unit\Request; |
4
|
|
|
|
5
|
|
|
use Shippinno\YahooShoppingJp\Request\UpdateOrderStatusRequest; |
6
|
|
|
|
7
|
|
|
use PHPUnit\Framework\TestCase; |
8
|
|
|
use Shippinno\YahooShoppingJp\Enum\OrderStatus; |
9
|
|
|
use Shippinno\YahooShoppingJp\Enum\CancelReason; |
10
|
|
|
|
11
|
|
|
class UpdateOrderStatusRequestTest extends TestCase |
12
|
|
|
{ |
13
|
|
|
const VALID_SELLER_ID = 'SELLER_ID'; |
14
|
|
|
const VALID_ORDER_ID = 'ORDER_ID'; |
15
|
|
|
const VALID_IS_POINT_FIX = true; |
16
|
|
|
const VALID_OPERATION_USER = 'OPERATION_USER'; |
17
|
|
|
|
18
|
|
|
protected $order_status; |
19
|
|
|
protected $cancel_reason; |
20
|
|
|
|
21
|
|
|
protected function setUp() |
22
|
|
|
{ |
23
|
|
|
$this->order_status = OrderStatus::PROCESSED(); |
24
|
|
|
$this->cancel_reason = CancelReason::ADDRESS_UNKNOWN(); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @test |
29
|
|
|
*/ |
30
|
|
|
public function create_instance_with_only_required_fields() |
31
|
|
|
{ |
32
|
|
|
$instance = new UpdateOrderStatusRequest; |
33
|
|
|
$this->assertInstanceOf(UpdateOrderStatusRequest::class, $instance); |
34
|
|
|
|
35
|
|
|
$this->assertSame($instance, $instance->setSellerId(self::VALID_SELLER_ID)); |
36
|
|
|
$this->assertSame($instance, $instance->setOrderId(self::VALID_ORDER_ID)); |
37
|
|
|
$this->assertSame($instance, $instance->setIsPointFix(self::VALID_IS_POINT_FIX)); |
38
|
|
|
$this->assertSame($instance, $instance->setOrderStatus($this->order_status)); |
39
|
|
|
|
40
|
|
|
return $instance; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @test |
45
|
|
|
* @depends create_instance_with_only_required_fields |
46
|
|
|
*/ |
47
|
|
|
public function check_SellerId_value($instance) |
48
|
|
|
{ |
49
|
|
|
$simpleXml = simplexml_load_string($instance->getParams()); |
50
|
|
|
|
51
|
|
|
$this->assertEquals(self::VALID_SELLER_ID, $simpleXml->SellerId->__toString()); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @test |
56
|
|
|
* @depends create_instance_with_only_required_fields |
57
|
|
|
* @expectedException \LogicException |
58
|
|
|
*/ |
59
|
|
|
public function set_SellerId_once(UpdateOrderStatusRequest $instance) |
60
|
|
|
{ |
61
|
|
|
$instance->setSellerId(self::VALID_SELLER_ID); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @test |
66
|
|
|
* @depends create_instance_with_only_required_fields |
67
|
|
|
*/ |
68
|
|
|
public function check_OrderId_value($instance) |
69
|
|
|
{ |
70
|
|
|
$simpleXml = simplexml_load_string($instance->getParams()); |
71
|
|
|
|
72
|
|
|
$this->assertEquals(self::VALID_ORDER_ID, $simpleXml->Target->OrderId->__toString()); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @test |
77
|
|
|
* @depends create_instance_with_only_required_fields |
78
|
|
|
* @expectedException \LogicException |
79
|
|
|
*/ |
80
|
|
|
public function set_OrderId_once($instance) |
81
|
|
|
{ |
82
|
|
|
$instance->setOrderId(self::VALID_ORDER_ID); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @test |
87
|
|
|
* @depends create_instance_with_only_required_fields |
88
|
|
|
*/ |
89
|
|
|
public function check_IsPointFix_value($instance) |
90
|
|
|
{ |
91
|
|
|
$simpleXml = simplexml_load_string($instance->getParams()); |
92
|
|
|
|
93
|
|
|
$this->assertEquals(var_export(self::VALID_IS_POINT_FIX, TRUE), $simpleXml->Target->IsPointFix->__toString()); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @test |
98
|
|
|
* @depends create_instance_with_only_required_fields |
99
|
|
|
* @expectedException \LogicException |
100
|
|
|
*/ |
101
|
|
|
public function set_IsPointFix_once($instance) |
102
|
|
|
{ |
103
|
|
|
$instance->setIsPointFix(self::VALID_IS_POINT_FIX); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* @test |
108
|
|
|
* @depends create_instance_with_only_required_fields |
109
|
|
|
*/ |
110
|
|
|
public function check_OrderStatus_value($instance) |
111
|
|
|
{ |
112
|
|
|
$simpleXml = simplexml_load_string($instance->getParams()); |
113
|
|
|
|
114
|
|
|
$this->assertEquals($this->order_status->getValue(), $simpleXml->Order->OrderStatus->__toString()); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* @test |
119
|
|
|
* @depends create_instance_with_only_required_fields |
120
|
|
|
* @expectedException \LogicException |
121
|
|
|
*/ |
122
|
|
|
public function set_OrderStatus_once($instance) |
123
|
|
|
{ |
124
|
|
|
$instance->setOrderStatus($this->order_status); |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* @test |
129
|
|
|
* @depends create_instance_with_only_required_fields |
130
|
|
|
* @expectedException \LogicException |
131
|
|
|
*/ |
132
|
|
|
public function set_OperationUser_once($instance) |
133
|
|
|
{ $instance->setOperationUser(self::VALID_OPERATION_USER); |
134
|
|
|
|
135
|
|
|
$instance->setOperationUser(self::VALID_OPERATION_USER); |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* @test |
140
|
|
|
* @depends create_instance_with_only_required_fields |
141
|
|
|
*/ |
142
|
|
|
public function check_OperationUser_value($instance) |
143
|
|
|
{ |
144
|
|
|
$simpleXml = simplexml_load_string($instance->getParams()); |
145
|
|
|
|
146
|
|
|
$this->assertEquals(self::VALID_OPERATION_USER, $simpleXml->Target->OperationUser->__toString()); |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
/** |
150
|
|
|
* @test |
151
|
|
|
* @depends create_instance_with_only_required_fields |
152
|
|
|
* @expectedException \LogicException |
153
|
|
|
*/ |
154
|
|
|
public function set_CancelReason_once($instance) |
155
|
|
|
{ |
156
|
|
|
$instance->setCancelReason($this->cancel_reason); |
157
|
|
|
|
158
|
|
|
$instance->setCancelReason($this->cancel_reason); |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
/** |
162
|
|
|
* @test |
163
|
|
|
* @depends create_instance_with_only_required_fields |
164
|
|
|
*/ |
165
|
|
|
public function check_CancelReason_value($instance) |
166
|
|
|
{ |
167
|
|
|
$simpleXml = simplexml_load_string($instance->getParams()); |
168
|
|
|
|
169
|
|
|
$this->assertEquals($this->cancel_reason->getValue(), $simpleXml->Order->CancelReason->__toString()); |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
/** |
173
|
|
|
* @test |
174
|
|
|
* @expectedException \Shippinno\YahooShoppingJp\Exception\InvalidRequestException |
175
|
|
|
*/ |
176
|
|
|
public function validate_not_set_SellerId() |
177
|
|
|
{ |
178
|
|
|
$request = (new UpdateOrderStatusRequest) |
179
|
|
|
->setOrderId(self::VALID_ORDER_ID) |
180
|
|
|
->setIsPointFix(self::VALID_IS_POINT_FIX) |
181
|
|
|
->setOrderStatus($this->order_status); |
182
|
|
|
|
183
|
|
|
$request->getParams(); |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
/** |
187
|
|
|
* @test |
188
|
|
|
* @expectedException \Shippinno\YahooShoppingJp\Exception\InvalidRequestException |
189
|
|
|
*/ |
190
|
|
|
public function validate_not_set_OrderId() |
191
|
|
|
{ |
192
|
|
|
$request = (new UpdateOrderStatusRequest) |
193
|
|
|
->setSellerId(self::VALID_SELLER_ID) |
194
|
|
|
->setIsPointFix(self::VALID_IS_POINT_FIX) |
195
|
|
|
->setOrderStatus($this->order_status); |
196
|
|
|
|
197
|
|
|
$request->getParams(); |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
/** |
201
|
|
|
* @test |
202
|
|
|
* @expectedException \Shippinno\YahooShoppingJp\Exception\InvalidRequestException |
203
|
|
|
*/ |
204
|
|
|
public function validate_not_set_IsPointFix() |
205
|
|
|
{ |
206
|
|
|
$request = (new UpdateOrderStatusRequest) |
207
|
|
|
->setSellerId(self::VALID_SELLER_ID) |
208
|
|
|
->setOrderId(self::VALID_ORDER_ID) |
209
|
|
|
->setOrderStatus($this->order_status); |
210
|
|
|
|
211
|
|
|
$request->getParams(); |
212
|
|
|
} |
213
|
|
|
|
214
|
|
|
/** |
215
|
|
|
* @test |
216
|
|
|
* @expectedException \Shippinno\YahooShoppingJp\Exception\InvalidRequestException |
217
|
|
|
*/ |
218
|
|
|
public function validate_not_set_OrderStatus() |
219
|
|
|
{ |
220
|
|
|
$request = (new UpdateOrderStatusRequest) |
221
|
|
|
->setSellerId(self::VALID_SELLER_ID) |
222
|
|
|
->setOrderId(self::VALID_ORDER_ID) |
223
|
|
|
->setIsPointFix(self::VALID_IS_POINT_FIX); |
224
|
|
|
|
225
|
|
|
$request->getParams(); |
226
|
|
|
} |
227
|
|
|
|
228
|
|
|
/** |
229
|
|
|
* @test |
230
|
|
|
* @expectedException \Shippinno\YahooShoppingJp\Exception\InvalidRequestException |
231
|
|
|
*/ |
232
|
|
|
public function validate_OrderStatus_and_IsPointFix() |
233
|
|
|
{ |
234
|
|
|
$request = (new UpdateOrderStatusRequest) |
235
|
|
|
->setSellerId(self::VALID_SELLER_ID) |
236
|
|
|
->setOrderId(self::VALID_ORDER_ID); |
237
|
|
|
|
238
|
|
|
$request |
239
|
|
|
->setIsPointFix(false) |
240
|
|
|
->setOrderStatus(OrderStatus::PROCESSED()); |
241
|
|
|
|
242
|
|
|
$request->getParams(); |
243
|
|
|
} |
244
|
|
|
|
245
|
|
|
} |
246
|
|
|
|