|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Lamoda\OmsClient\Tests\V2; |
|
6
|
|
|
|
|
7
|
|
|
use GuzzleHttp\ClientInterface; |
|
8
|
|
|
use GuzzleHttp\Exception\BadResponseException; |
|
9
|
|
|
use GuzzleHttp\Psr7\Response; |
|
10
|
|
|
use GuzzleHttp\RequestOptions; |
|
11
|
|
|
use Lamoda\OmsClient\Exception\OmsGeneralErrorException; |
|
12
|
|
|
use Lamoda\OmsClient\Exception\OmsRequestErrorException; |
|
13
|
|
|
use Lamoda\OmsClient\Serializer\SerializerInterface; |
|
14
|
|
|
use Lamoda\OmsClient\V2\Dto\CloseICArrayResponse; |
|
15
|
|
|
use Lamoda\OmsClient\V2\Dto\GetICBufferStatusResponse; |
|
16
|
|
|
use Lamoda\OmsClient\V2\Dto\GetICsFromOrderResponse; |
|
17
|
|
|
use Lamoda\OmsClient\V2\Extension; |
|
18
|
|
|
use Lamoda\OmsClient\V2\OmsApi; |
|
19
|
|
|
use PHPUnit\Framework\MockObject\MockObject; |
|
20
|
|
|
use PHPUnit\Framework\TestCase; |
|
21
|
|
|
use Psr\Http\Message\RequestInterface; |
|
22
|
|
|
use function GuzzleHttp\Psr7\stream_for; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @covers \Lamoda\OmsClient\V2\OmsApi |
|
26
|
|
|
*/ |
|
27
|
|
|
final class OmsApiTest extends TestCase |
|
28
|
|
|
{ |
|
29
|
|
|
private const TOKEN = 'abcdefg12345678'; |
|
30
|
|
|
private const API_RESPONSE = '{stub_result}'; |
|
31
|
|
|
private const OMS_ID = '123456'; |
|
32
|
|
|
private const ORDER_ID = 'af7a55ae-83de-470b-a1bd-6bbf657106ef'; |
|
33
|
|
|
private const GTIN = '046000012345'; |
|
34
|
|
|
private const MARKING_CODE = "010467003301005321gJk6o54AQBJfX\u{001d}91ffd0\u{001d}92LGYcm3FRQrRdNOO+8t0pz78QTyxxBmYKhLXaAS03jKV7oy+DWGy1SeU+BZ8o7B8+hs9LvPdNA7B6NPGjrCm34A=="; |
|
35
|
|
|
private const LAST_BLOCK_ID = '123456'; |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @var ClientInterface | MockObject |
|
39
|
|
|
*/ |
|
40
|
|
|
private $client; |
|
41
|
|
|
/** |
|
42
|
|
|
* @var SerializerInterface | MockObject |
|
43
|
|
|
*/ |
|
44
|
|
|
private $serializer; |
|
45
|
|
|
/** |
|
46
|
|
|
* @var OmsApi |
|
47
|
|
|
*/ |
|
48
|
|
|
private $api; |
|
49
|
|
|
|
|
50
|
|
|
protected function setUp() |
|
51
|
|
|
{ |
|
52
|
|
|
parent::setUp(); |
|
53
|
|
|
|
|
54
|
|
|
$this->client = $this->createMock(ClientInterface::class); |
|
|
|
|
|
|
55
|
|
|
$this->serializer = $this->createMock(SerializerInterface::class); |
|
|
|
|
|
|
56
|
|
|
|
|
57
|
|
|
$this->api = new OmsApi( |
|
58
|
|
|
$this->client, |
|
|
|
|
|
|
59
|
|
|
$this->serializer |
|
|
|
|
|
|
60
|
|
|
); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
public function testExceptionWithHttpCode(): void |
|
64
|
|
|
{ |
|
65
|
|
|
$this->client |
|
|
|
|
|
|
66
|
|
|
->method('request') |
|
67
|
|
|
->willThrowException(new BadResponseException('Bad response', $this->createMock(RequestInterface::class))); |
|
|
|
|
|
|
68
|
|
|
|
|
69
|
|
|
$this->expectException(OmsRequestErrorException::class); |
|
70
|
|
|
$this->api->getICBufferStatus(Extension::light(), self::TOKEN, self::OMS_ID, self::ORDER_ID, self::GTIN); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
public function testGeneralException(): void |
|
74
|
|
|
{ |
|
75
|
|
|
$this->client |
|
|
|
|
|
|
76
|
|
|
->method('request') |
|
77
|
|
|
->willThrowException(new \RuntimeException()); |
|
78
|
|
|
|
|
79
|
|
|
$this->expectException(OmsGeneralErrorException::class); |
|
80
|
|
|
$this->api->getICBufferStatus(Extension::light(), self::TOKEN, self::OMS_ID, self::ORDER_ID, self::GTIN); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* @dataProvider dataCorrectUsageOfExtensions |
|
85
|
|
|
*/ |
|
86
|
|
|
public function testCorrectUsageOfExtensions(Extension $extension, string $extensionName): void |
|
87
|
|
|
{ |
|
88
|
|
|
$this->client->expects($this->once()) |
|
|
|
|
|
|
89
|
|
|
->method('request') |
|
90
|
|
|
->with( |
|
91
|
|
|
$this->anything(), |
|
92
|
|
|
sprintf('api/v2/%s/buffer/status', $extensionName), |
|
93
|
|
|
$this->anything() |
|
94
|
|
|
) |
|
95
|
|
|
->willReturn( |
|
96
|
|
|
(new Response()) |
|
97
|
|
|
->withBody(stream_for(self::API_RESPONSE)) |
|
98
|
|
|
); |
|
99
|
|
|
|
|
100
|
|
|
$expectedResult = new GetICBufferStatusResponse('', '', '', 0, 0, 0, [], ''); |
|
101
|
|
|
$this->serializer->expects($this->once()) |
|
|
|
|
|
|
102
|
|
|
->method('deserialize') |
|
103
|
|
|
->willReturn($expectedResult); |
|
104
|
|
|
|
|
105
|
|
|
$this->api->getICBufferStatus($extension, self::TOKEN, self::OMS_ID, self::ORDER_ID, self::GTIN); |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
public function dataCorrectUsageOfExtensions(): array |
|
109
|
|
|
{ |
|
110
|
|
|
return [ |
|
111
|
|
|
[ |
|
112
|
|
|
Extension::light(), |
|
113
|
|
|
'light', |
|
114
|
|
|
], |
|
115
|
|
|
[ |
|
116
|
|
|
Extension::pharma(), |
|
117
|
|
|
'pharma', |
|
118
|
|
|
], |
|
119
|
|
|
]; |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
public function testGetICBufferStatus(): void |
|
123
|
|
|
{ |
|
124
|
|
|
$this->client->expects($this->once()) |
|
|
|
|
|
|
125
|
|
|
->method('request') |
|
126
|
|
|
->with( |
|
127
|
|
|
'GET', |
|
128
|
|
|
'api/v2/light/buffer/status', |
|
129
|
|
|
[ |
|
130
|
|
|
RequestOptions::BODY => null, |
|
131
|
|
|
RequestOptions::HEADERS => [ |
|
132
|
|
|
'Content-Type' => 'application/json', |
|
133
|
|
|
'clientToken' => self::TOKEN, |
|
134
|
|
|
], |
|
135
|
|
|
RequestOptions::QUERY => [ |
|
136
|
|
|
'omsId' => self::OMS_ID, |
|
137
|
|
|
'orderId' => self::ORDER_ID, |
|
138
|
|
|
'gtin' => self::GTIN, |
|
139
|
|
|
], |
|
140
|
|
|
RequestOptions::HTTP_ERRORS => true, |
|
141
|
|
|
] |
|
142
|
|
|
) |
|
143
|
|
|
->willReturn( |
|
144
|
|
|
(new Response()) |
|
145
|
|
|
->withBody(stream_for(self::API_RESPONSE)) |
|
146
|
|
|
); |
|
147
|
|
|
|
|
148
|
|
|
$expectedResult = new GetICBufferStatusResponse('', '', '', 0, 0, 0, [], ''); |
|
149
|
|
|
$this->serializer->expects($this->once()) |
|
|
|
|
|
|
150
|
|
|
->method('deserialize') |
|
151
|
|
|
->with( |
|
152
|
|
|
GetICBufferStatusResponse::class, |
|
153
|
|
|
self::API_RESPONSE |
|
154
|
|
|
) |
|
155
|
|
|
->willReturn($expectedResult); |
|
156
|
|
|
|
|
157
|
|
|
$result = $this->api->getICBufferStatus(Extension::light(), self::TOKEN, self::OMS_ID, self::ORDER_ID, |
|
158
|
|
|
self::GTIN); |
|
159
|
|
|
|
|
160
|
|
|
$this->assertEquals($expectedResult, $result); |
|
161
|
|
|
} |
|
162
|
|
|
|
|
163
|
|
|
public function testGetICsFromOrder(): void |
|
164
|
|
|
{ |
|
165
|
|
|
$this->client->expects($this->once()) |
|
|
|
|
|
|
166
|
|
|
->method('request') |
|
167
|
|
|
->with( |
|
168
|
|
|
'GET', |
|
169
|
|
|
'api/v2/light/codes', |
|
170
|
|
|
[ |
|
171
|
|
|
RequestOptions::BODY => null, |
|
172
|
|
|
RequestOptions::HEADERS => [ |
|
173
|
|
|
'Content-Type' => 'application/json', |
|
174
|
|
|
'clientToken' => self::TOKEN, |
|
175
|
|
|
], |
|
176
|
|
|
RequestOptions::QUERY => [ |
|
177
|
|
|
'omsId' => self::OMS_ID, |
|
178
|
|
|
'orderId' => self::ORDER_ID, |
|
179
|
|
|
'gtin' => self::GTIN, |
|
180
|
|
|
'quantity' => 2, |
|
181
|
|
|
'lastBlockId' => '1', |
|
182
|
|
|
], |
|
183
|
|
|
RequestOptions::HTTP_ERRORS => true, |
|
184
|
|
|
] |
|
185
|
|
|
) |
|
186
|
|
|
->willReturn( |
|
187
|
|
|
(new Response()) |
|
188
|
|
|
->withBody(stream_for(self::API_RESPONSE)) |
|
189
|
|
|
); |
|
190
|
|
|
|
|
191
|
|
|
$expectedResult = new GetICsFromOrderResponse(self::OMS_ID, [self::MARKING_CODE], '2'); |
|
192
|
|
|
$this->serializer->expects($this->once()) |
|
|
|
|
|
|
193
|
|
|
->method('deserialize') |
|
194
|
|
|
->with( |
|
195
|
|
|
GetICsFromOrderResponse::class, |
|
196
|
|
|
self::API_RESPONSE |
|
197
|
|
|
) |
|
198
|
|
|
->willReturn($expectedResult); |
|
199
|
|
|
|
|
200
|
|
|
$result = $this->api->getICsFromOrder(Extension::light(), self::TOKEN, self::OMS_ID, self::ORDER_ID, self::GTIN, |
|
201
|
|
|
2, '1'); |
|
202
|
|
|
|
|
203
|
|
|
$this->assertEquals($expectedResult, $result); |
|
204
|
|
|
} |
|
205
|
|
|
|
|
206
|
|
|
public function testCloseICArray(): void |
|
207
|
|
|
{ |
|
208
|
|
|
$this->client->expects($this->once()) |
|
|
|
|
|
|
209
|
|
|
->method('request') |
|
210
|
|
|
->with( |
|
211
|
|
|
'POST', |
|
212
|
|
|
'api/v2/light/buffer/close', |
|
213
|
|
|
[ |
|
214
|
|
|
RequestOptions::BODY => null, |
|
215
|
|
|
RequestOptions::HEADERS => [ |
|
216
|
|
|
'Content-Type' => 'application/json', |
|
217
|
|
|
'clientToken' => self::TOKEN, |
|
218
|
|
|
], |
|
219
|
|
|
RequestOptions::QUERY => [ |
|
220
|
|
|
'omsId' => self::OMS_ID, |
|
221
|
|
|
'orderId' => self::ORDER_ID, |
|
222
|
|
|
'gtin' => self::GTIN, |
|
223
|
|
|
'lastBlockId' => self::LAST_BLOCK_ID, |
|
224
|
|
|
], |
|
225
|
|
|
RequestOptions::HTTP_ERRORS => true, |
|
226
|
|
|
] |
|
227
|
|
|
) |
|
228
|
|
|
->willReturn( |
|
229
|
|
|
(new Response()) |
|
230
|
|
|
->withBody(stream_for(self::API_RESPONSE)) |
|
231
|
|
|
); |
|
232
|
|
|
|
|
233
|
|
|
$expectedResult = new CloseICArrayResponse(self::OMS_ID); |
|
234
|
|
|
$this->serializer->expects($this->once()) |
|
|
|
|
|
|
235
|
|
|
->method('deserialize') |
|
236
|
|
|
->with( |
|
237
|
|
|
CloseICArrayResponse::class, |
|
238
|
|
|
self::API_RESPONSE |
|
239
|
|
|
) |
|
240
|
|
|
->willReturn($expectedResult); |
|
241
|
|
|
|
|
242
|
|
|
$result = $this->api->closeICArray( |
|
243
|
|
|
Extension::light(), |
|
244
|
|
|
self::TOKEN, |
|
245
|
|
|
self::OMS_ID, |
|
246
|
|
|
self::ORDER_ID, |
|
247
|
|
|
self::GTIN, |
|
248
|
|
|
self::LAST_BLOCK_ID |
|
249
|
|
|
); |
|
250
|
|
|
|
|
251
|
|
|
$this->assertEquals($expectedResult, $result); |
|
252
|
|
|
} |
|
253
|
|
|
|
|
254
|
|
|
} |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..