1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Lamoda\IsmpClient\Tests\V3; |
6
|
|
|
|
7
|
|
|
use GuzzleHttp\ClientInterface; |
8
|
|
|
use GuzzleHttp\Exception\BadResponseException; |
9
|
|
|
use GuzzleHttp\Psr7\Response; |
10
|
|
|
use GuzzleHttp\RequestOptions; |
11
|
|
|
use Lamoda\IsmpClient\Exception\IsmpGeneralErrorException; |
12
|
|
|
use Lamoda\IsmpClient\Exception\IsmpRequestErrorException; |
13
|
|
|
use Lamoda\IsmpClient\Serializer\SerializerInterface; |
14
|
|
|
use Lamoda\IsmpClient\V3\Dto\AuthCertKeyResponse; |
15
|
|
|
use Lamoda\IsmpClient\V3\Dto\AuthCertRequest; |
16
|
|
|
use Lamoda\IsmpClient\V3\Dto\AuthCertResponse; |
17
|
|
|
use Lamoda\IsmpClient\V3\Dto\DocumentCreateRequest; |
18
|
|
|
use Lamoda\IsmpClient\V3\Dto\FacadeCisListRequest; |
19
|
|
|
use Lamoda\IsmpClient\V3\Dto\FacadeCisListResponse; |
20
|
|
|
use Lamoda\IsmpClient\V3\Dto\FacadeDocBodyResponse; |
21
|
|
|
use Lamoda\IsmpClient\V3\Dto\FacadeDocListV2Query; |
22
|
|
|
use Lamoda\IsmpClient\V3\Dto\FacadeDocListV2Response; |
23
|
|
|
use Lamoda\IsmpClient\V3\Dto\FacadeOrderDetailsResponse; |
24
|
|
|
use Lamoda\IsmpClient\V3\Dto\FacadeOrderRequest; |
25
|
|
|
use Lamoda\IsmpClient\V3\Dto\FacadeOrderResponse; |
26
|
|
|
use Lamoda\IsmpClient\V3\Dto\ProductInfoResponse; |
27
|
|
|
use Lamoda\IsmpClient\V3\Enum\DocumentLkType; |
28
|
|
|
use Lamoda\IsmpClient\V3\Enum\ProductGroup; |
29
|
|
|
use Lamoda\IsmpClient\V3\IsmpApi; |
30
|
|
|
use PHPUnit\Framework\MockObject\MockObject; |
31
|
|
|
use PHPUnit\Framework\TestCase; |
32
|
|
|
use Psr\Http\Message\RequestInterface; |
33
|
|
|
|
34
|
|
|
use function GuzzleHttp\Psr7\stream_for; |
35
|
|
|
|
36
|
|
|
final class IsmpApiTest extends TestCase |
37
|
|
|
{ |
38
|
|
|
private const TOKEN = '0a893bdc-3127-4f3f-939e-f423d08d9bd6'; |
39
|
|
|
private const UUID = '81497c0c-17ef-42a1-b1d1-d769dac7441c'; |
40
|
|
|
private const RANDOM_DATA = '2b212c99-9955-45c7-8594-9d3aa59eae04'; |
41
|
|
|
private const SERIALIZED_VALUE = '{"test:"value"}'; |
42
|
|
|
private const API_RESPONSE = 'stub_api_response'; |
43
|
|
|
private const IDENTITY = 'eb852349-647f-468f-bb90-d26a4d975a88'; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @var ClientInterface|MockObject |
47
|
|
|
*/ |
48
|
|
|
private $client; |
49
|
|
|
/** |
50
|
|
|
* @var SerializerInterface|MockObject |
51
|
|
|
*/ |
52
|
|
|
private $serializer; |
53
|
|
|
/** |
54
|
|
|
* @var IsmpApi |
55
|
|
|
*/ |
56
|
|
|
private $api; |
57
|
|
|
|
58
|
|
|
protected function setUp(): void |
59
|
|
|
{ |
60
|
|
|
$this->client = $this->createMock(ClientInterface::class); |
61
|
|
|
$this->serializer = $this->createMock(SerializerInterface::class); |
62
|
|
|
|
63
|
|
|
$this->api = new IsmpApi( |
64
|
|
|
$this->client, |
|
|
|
|
65
|
|
|
$this->serializer |
|
|
|
|
66
|
|
|
); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
public function testExceptionWithHttpCode(): void |
70
|
|
|
{ |
71
|
|
|
$this->client |
72
|
|
|
->method('request') |
73
|
|
|
->willThrowException(new BadResponseException('Bad response', $this->createMock(RequestInterface::class))); |
|
|
|
|
74
|
|
|
|
75
|
|
|
$this->expectException(IsmpRequestErrorException::class); |
76
|
|
|
$this->api->authCertKey(); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
public function testGeneralException(): void |
80
|
|
|
{ |
81
|
|
|
$this->client |
82
|
|
|
->method('request') |
83
|
|
|
->willThrowException(new \RuntimeException()); |
84
|
|
|
|
85
|
|
|
$this->expectException(IsmpGeneralErrorException::class); |
86
|
|
|
$this->api->authCertKey(); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
public function testAuthCertKey(): void |
90
|
|
|
{ |
91
|
|
|
$expectedResult = new AuthCertKeyResponse(self::UUID, self::RANDOM_DATA); |
92
|
|
|
|
93
|
|
|
$this->serializer |
94
|
|
|
->method('deserialize') |
95
|
|
|
->with( |
96
|
|
|
get_class($expectedResult), |
97
|
|
|
self::API_RESPONSE |
98
|
|
|
) |
99
|
|
|
->willReturn($expectedResult); |
100
|
|
|
|
101
|
|
|
$this->client->expects($this->once()) |
|
|
|
|
102
|
|
|
->method('request') |
103
|
|
|
->with( |
104
|
|
|
'GET', |
105
|
|
|
'api/v3/auth/cert/key', |
106
|
|
|
[ |
107
|
|
|
RequestOptions::BODY => null, |
108
|
|
|
RequestOptions::HEADERS => [ |
109
|
|
|
'Content-Type' => 'application/json', |
110
|
|
|
], |
111
|
|
|
RequestOptions::HTTP_ERRORS => true, |
112
|
|
|
RequestOptions::QUERY => null, |
113
|
|
|
] |
114
|
|
|
) |
115
|
|
|
->willReturn( |
116
|
|
|
(new Response()) |
117
|
|
|
->withBody(stream_for(self::API_RESPONSE)) |
118
|
|
|
); |
119
|
|
|
|
120
|
|
|
$result = $this->api->authCertKey(); |
121
|
|
|
|
122
|
|
|
$this->assertEquals($expectedResult, $result); |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
public function testAuthCert(): void |
126
|
|
|
{ |
127
|
|
|
$request = new AuthCertRequest(self::UUID, self::RANDOM_DATA); |
128
|
|
|
$expectedResult = new AuthCertResponse('token-value'); |
129
|
|
|
|
130
|
|
|
$this->serializer |
131
|
|
|
->method('serialize') |
132
|
|
|
->with($request) |
133
|
|
|
->willReturn(self::SERIALIZED_VALUE); |
134
|
|
|
|
135
|
|
|
$this->serializer |
136
|
|
|
->method('deserialize') |
137
|
|
|
->with( |
138
|
|
|
get_class($expectedResult), |
139
|
|
|
self::API_RESPONSE |
140
|
|
|
) |
141
|
|
|
->willReturn($expectedResult); |
142
|
|
|
|
143
|
|
|
$this->client->expects($this->once()) |
|
|
|
|
144
|
|
|
->method('request') |
145
|
|
|
->with( |
146
|
|
|
'POST', |
147
|
|
|
'api/v3/auth/cert/', |
148
|
|
|
[ |
149
|
|
|
RequestOptions::BODY => self::SERIALIZED_VALUE, |
150
|
|
|
RequestOptions::HEADERS => [ |
151
|
|
|
'Content-Type' => 'application/json', |
152
|
|
|
], |
153
|
|
|
RequestOptions::HTTP_ERRORS => true, |
154
|
|
|
RequestOptions::QUERY => null, |
155
|
|
|
] |
156
|
|
|
) |
157
|
|
|
->willReturn( |
158
|
|
|
(new Response()) |
159
|
|
|
->withBody(stream_for(self::API_RESPONSE)) |
160
|
|
|
); |
161
|
|
|
|
162
|
|
|
$result = $this->api->authCert($request); |
163
|
|
|
|
164
|
|
|
$this->assertEquals($expectedResult, $result); |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
public function testFacadeOrder(): void |
168
|
|
|
{ |
169
|
|
|
$request = new FacadeOrderRequest('document', 'MANUAL', 'signature'); |
170
|
|
|
$expectedResult = new FacadeOrderResponse('orderId', 'status'); |
171
|
|
|
|
172
|
|
|
$this->serializer |
173
|
|
|
->method('serialize') |
174
|
|
|
->with($request) |
175
|
|
|
->willReturn(self::SERIALIZED_VALUE); |
176
|
|
|
|
177
|
|
|
$this->serializer |
178
|
|
|
->method('deserialize') |
179
|
|
|
->with( |
180
|
|
|
get_class($expectedResult), |
181
|
|
|
self::API_RESPONSE |
182
|
|
|
) |
183
|
|
|
->willReturn($expectedResult); |
184
|
|
|
|
185
|
|
|
$this->client->expects($this->once()) |
|
|
|
|
186
|
|
|
->method('request') |
187
|
|
|
->with( |
188
|
|
|
'POST', |
189
|
|
|
'api/v3/facade/order/', |
190
|
|
|
[ |
191
|
|
|
RequestOptions::BODY => self::SERIALIZED_VALUE, |
192
|
|
|
RequestOptions::HEADERS => [ |
193
|
|
|
'Content-Type' => 'application/json', |
194
|
|
|
'Authorization' => 'Bearer ' . self::TOKEN, |
195
|
|
|
], |
196
|
|
|
RequestOptions::HTTP_ERRORS => true, |
197
|
|
|
RequestOptions::QUERY => null, |
198
|
|
|
] |
199
|
|
|
) |
200
|
|
|
->willReturn( |
201
|
|
|
(new Response()) |
202
|
|
|
->withBody(stream_for(self::API_RESPONSE)) |
203
|
|
|
); |
204
|
|
|
|
205
|
|
|
$result = $this->api->facadeOrder(self::TOKEN, $request); |
206
|
|
|
|
207
|
|
|
$this->assertEquals($expectedResult, $result); |
208
|
|
|
} |
209
|
|
|
|
210
|
|
|
public function testFacadeOrderDetails(): void |
211
|
|
|
{ |
212
|
|
|
$expectedResult = new FacadeOrderDetailsResponse(self::IDENTITY, 'MANUAL', 123456); |
213
|
|
|
|
214
|
|
|
$this->serializer |
215
|
|
|
->method('deserialize') |
216
|
|
|
->with( |
217
|
|
|
get_class($expectedResult), |
218
|
|
|
self::API_RESPONSE |
219
|
|
|
) |
220
|
|
|
->willReturn($expectedResult); |
221
|
|
|
|
222
|
|
|
$this->client->expects($this->once()) |
|
|
|
|
223
|
|
|
->method('request') |
224
|
|
|
->with( |
225
|
|
|
'GET', |
226
|
|
|
sprintf('api/v3/facade/order/%s/details', self::IDENTITY), |
227
|
|
|
[ |
228
|
|
|
RequestOptions::BODY => null, |
229
|
|
|
RequestOptions::HEADERS => [ |
230
|
|
|
'Content-Type' => 'application/json', |
231
|
|
|
'Authorization' => 'Bearer ' . self::TOKEN, |
232
|
|
|
], |
233
|
|
|
RequestOptions::HTTP_ERRORS => true, |
234
|
|
|
RequestOptions::QUERY => null, |
235
|
|
|
] |
236
|
|
|
) |
237
|
|
|
->willReturn( |
238
|
|
|
(new Response()) |
239
|
|
|
->withBody(stream_for(self::API_RESPONSE)) |
240
|
|
|
); |
241
|
|
|
|
242
|
|
|
$result = $this->api->facadeOrderDetails(self::TOKEN, self::IDENTITY); |
243
|
|
|
|
244
|
|
|
$this->assertEquals($expectedResult, $result); |
245
|
|
|
} |
246
|
|
|
|
247
|
|
|
public function testFacadeDocListV2(): void |
248
|
|
|
{ |
249
|
|
|
$query = new FacadeDocListV2Query(); |
250
|
|
|
$query->setDocumentStatus(FacadeDocListV2Query::DOCUMENT_STATUS_CHECKED_OK); |
251
|
|
|
$query->setDateFrom(new \DateTimeImmutable('2019-01-01 11:12:13', new \DateTimeZone('UTC'))); |
252
|
|
|
$expectedResult = new FacadeDocListV2Response(0); |
253
|
|
|
|
254
|
|
|
$this->serializer |
255
|
|
|
->method('deserialize') |
256
|
|
|
->with( |
257
|
|
|
get_class($expectedResult), |
258
|
|
|
self::API_RESPONSE |
259
|
|
|
) |
260
|
|
|
->willReturn($expectedResult); |
261
|
|
|
|
262
|
|
|
$this->client->expects($this->once()) |
|
|
|
|
263
|
|
|
->method('request') |
264
|
|
|
->with( |
265
|
|
|
'GET', |
266
|
|
|
'api/v3/facade/doc/listV2', |
267
|
|
|
[ |
268
|
|
|
RequestOptions::BODY => null, |
269
|
|
|
RequestOptions::HEADERS => [ |
270
|
|
|
'Content-Type' => 'application/json', |
271
|
|
|
'Authorization' => 'Bearer ' . self::TOKEN, |
272
|
|
|
], |
273
|
|
|
RequestOptions::HTTP_ERRORS => true, |
274
|
|
|
RequestOptions::QUERY => [ |
275
|
|
|
'documentStatus' => FacadeDocListV2Query::DOCUMENT_STATUS_CHECKED_OK, |
276
|
|
|
'dateFrom' => '2019-01-01T11:12:13.000+00:00', |
277
|
|
|
'limit' => $query->getLimit(), |
278
|
|
|
], |
279
|
|
|
] |
280
|
|
|
) |
281
|
|
|
->willReturn( |
282
|
|
|
(new Response()) |
283
|
|
|
->withBody(stream_for(self::API_RESPONSE)) |
284
|
|
|
); |
285
|
|
|
|
286
|
|
|
$result = $this->api->facadeDocListV2(self::TOKEN, $query); |
287
|
|
|
|
288
|
|
|
$this->assertEquals($expectedResult, $result); |
289
|
|
|
} |
290
|
|
|
|
291
|
|
|
/** |
292
|
|
|
* @dataProvider dataFacadeDocBody |
293
|
|
|
*/ |
294
|
|
|
public function testFacadeDocBody( |
295
|
|
|
?int $limitOption, |
296
|
|
|
?string $orderColumnOption, |
297
|
|
|
?string $orderedColumnValueOption, |
298
|
|
|
?string $pageDirOption, |
299
|
|
|
array $expectedOptions |
300
|
|
|
): void { |
301
|
|
|
$expectedResult = new FacadeDocBodyResponse(self::IDENTITY, '2019-01-01', 'IMPORT', 'NEW', 'Tester', 'Test'); |
302
|
|
|
$expectedResult->setCisTotal('100'); |
303
|
|
|
|
304
|
|
|
$this->serializer |
305
|
|
|
->method('deserialize') |
306
|
|
|
->with( |
307
|
|
|
get_class($expectedResult), |
308
|
|
|
self::API_RESPONSE |
309
|
|
|
) |
310
|
|
|
->willReturn($expectedResult); |
311
|
|
|
|
312
|
|
|
$this->client->expects($this->once()) |
|
|
|
|
313
|
|
|
->method('request') |
314
|
|
|
->with( |
315
|
|
|
'GET', |
316
|
|
|
sprintf('api/v3/facade/doc/%s/body', self::IDENTITY), |
317
|
|
|
$expectedOptions |
318
|
|
|
) |
319
|
|
|
->willReturn( |
320
|
|
|
(new Response()) |
321
|
|
|
->withBody(stream_for(self::API_RESPONSE)) |
322
|
|
|
); |
323
|
|
|
|
324
|
|
|
$result = $this->api->facadeDocBody( |
325
|
|
|
self::TOKEN, |
326
|
|
|
self::IDENTITY, |
327
|
|
|
$limitOption, |
328
|
|
|
$orderColumnOption, |
329
|
|
|
$orderedColumnValueOption, |
330
|
|
|
$pageDirOption |
331
|
|
|
); |
332
|
|
|
|
333
|
|
|
$this->assertEquals($expectedResult, $result); |
334
|
|
|
} |
335
|
|
|
|
336
|
|
|
public function dataFacadeDocBody(): iterable |
337
|
|
|
{ |
338
|
|
|
yield 'all nullable parameters' => [ |
339
|
|
|
null, |
340
|
|
|
null, |
341
|
|
|
null, |
342
|
|
|
null, |
343
|
|
|
[ |
344
|
|
|
RequestOptions::BODY => null, |
345
|
|
|
RequestOptions::HEADERS => [ |
346
|
|
|
'Content-Type' => 'application/json', |
347
|
|
|
'Authorization' => 'Bearer ' . self::TOKEN, |
348
|
|
|
], |
349
|
|
|
RequestOptions::HTTP_ERRORS => true, |
350
|
|
|
RequestOptions::QUERY => null, |
351
|
|
|
], |
352
|
|
|
]; |
353
|
|
|
|
354
|
|
|
yield 'only limit' => [ |
355
|
|
|
1000, |
356
|
|
|
null, |
357
|
|
|
null, |
358
|
|
|
null, |
359
|
|
|
[ |
360
|
|
|
RequestOptions::BODY => null, |
361
|
|
|
RequestOptions::HEADERS => [ |
362
|
|
|
'Content-Type' => 'application/json', |
363
|
|
|
'Authorization' => 'Bearer ' . self::TOKEN, |
364
|
|
|
], |
365
|
|
|
RequestOptions::HTTP_ERRORS => true, |
366
|
|
|
RequestOptions::QUERY => [ |
367
|
|
|
'limit' => 1000, |
368
|
|
|
], |
369
|
|
|
], |
370
|
|
|
]; |
371
|
|
|
|
372
|
|
|
yield 'only order column option' => [ |
373
|
|
|
null, |
374
|
|
|
'order-column', |
375
|
|
|
null, |
376
|
|
|
null, |
377
|
|
|
[ |
378
|
|
|
RequestOptions::BODY => null, |
379
|
|
|
RequestOptions::HEADERS => [ |
380
|
|
|
'Content-Type' => 'application/json', |
381
|
|
|
'Authorization' => 'Bearer ' . self::TOKEN, |
382
|
|
|
], |
383
|
|
|
RequestOptions::HTTP_ERRORS => true, |
384
|
|
|
RequestOptions::QUERY => [ |
385
|
|
|
'orderColumn' => 'order-column', |
386
|
|
|
], |
387
|
|
|
], |
388
|
|
|
]; |
389
|
|
|
|
390
|
|
|
yield 'only ordered column value option' => [ |
391
|
|
|
null, |
392
|
|
|
null, |
393
|
|
|
'ordered-column-value', |
394
|
|
|
null, |
395
|
|
|
[ |
396
|
|
|
RequestOptions::BODY => null, |
397
|
|
|
RequestOptions::HEADERS => [ |
398
|
|
|
'Content-Type' => 'application/json', |
399
|
|
|
'Authorization' => 'Bearer ' . self::TOKEN, |
400
|
|
|
], |
401
|
|
|
RequestOptions::HTTP_ERRORS => true, |
402
|
|
|
RequestOptions::QUERY => [ |
403
|
|
|
'orderedColumnValue' => 'ordered-column-value', |
404
|
|
|
], |
405
|
|
|
], |
406
|
|
|
]; |
407
|
|
|
|
408
|
|
|
yield 'only page dir option' => [ |
409
|
|
|
null, |
410
|
|
|
null, |
411
|
|
|
null, |
412
|
|
|
'page-dir', |
413
|
|
|
[ |
414
|
|
|
RequestOptions::BODY => null, |
415
|
|
|
RequestOptions::HEADERS => [ |
416
|
|
|
'Content-Type' => 'application/json', |
417
|
|
|
'Authorization' => 'Bearer ' . self::TOKEN, |
418
|
|
|
], |
419
|
|
|
RequestOptions::HTTP_ERRORS => true, |
420
|
|
|
RequestOptions::QUERY => [ |
421
|
|
|
'pageDir' => 'page-dir' |
422
|
|
|
], |
423
|
|
|
], |
424
|
|
|
]; |
425
|
|
|
|
426
|
|
|
|
427
|
|
|
yield 'all parameters' => [ |
428
|
|
|
1000, |
429
|
|
|
'order-column', |
430
|
|
|
'ordered-column-value', |
431
|
|
|
'page-dir', |
432
|
|
|
[ |
433
|
|
|
RequestOptions::BODY => null, |
434
|
|
|
RequestOptions::HEADERS => [ |
435
|
|
|
'Content-Type' => 'application/json', |
436
|
|
|
'Authorization' => 'Bearer ' . self::TOKEN, |
437
|
|
|
], |
438
|
|
|
RequestOptions::HTTP_ERRORS => true, |
439
|
|
|
RequestOptions::QUERY => [ |
440
|
|
|
'limit' => 1000, |
441
|
|
|
'orderColumn' => 'order-column', |
442
|
|
|
'orderedColumnValue' => 'ordered-column-value', |
443
|
|
|
'pageDir' => 'page-dir', |
444
|
|
|
], |
445
|
|
|
], |
446
|
|
|
]; |
447
|
|
|
} |
448
|
|
|
|
449
|
|
|
public function testFacadeCisList(): void |
450
|
|
|
{ |
451
|
|
|
$request = new FacadeCisListRequest(self::IDENTITY); |
452
|
|
|
$expectedResult = new FacadeCisListResponse(); |
453
|
|
|
$requestBody = '{"cises": [' . self::IDENTITY . ']}'; |
454
|
|
|
|
455
|
|
|
$this->serializer |
456
|
|
|
->method('serialize') |
457
|
|
|
->with($request) |
458
|
|
|
->willReturn($requestBody); |
459
|
|
|
|
460
|
|
|
$this->serializer |
461
|
|
|
->method('deserialize') |
462
|
|
|
->with( |
463
|
|
|
get_class($expectedResult), |
464
|
|
|
self::API_RESPONSE |
465
|
|
|
) |
466
|
|
|
->willReturn($expectedResult); |
467
|
|
|
|
468
|
|
|
$this->client->expects($this->once()) |
|
|
|
|
469
|
|
|
->method('request') |
470
|
|
|
->with( |
471
|
|
|
'POST', |
472
|
|
|
'api/v3/facade/cis/cis_list', |
473
|
|
|
[ |
474
|
|
|
RequestOptions::BODY => $requestBody, |
475
|
|
|
RequestOptions::HEADERS => [ |
476
|
|
|
'Content-Type' => 'application/json', |
477
|
|
|
'Authorization' => 'Bearer ' . self::TOKEN, |
478
|
|
|
], |
479
|
|
|
RequestOptions::HTTP_ERRORS => true, |
480
|
|
|
RequestOptions::QUERY => null, |
481
|
|
|
] |
482
|
|
|
) |
483
|
|
|
->willReturn( |
484
|
|
|
(new Response()) |
485
|
|
|
->withBody(stream_for(self::API_RESPONSE)) |
486
|
|
|
); |
487
|
|
|
|
488
|
|
|
$result = $this->api->facadeCisList(self::TOKEN, $request); |
489
|
|
|
|
490
|
|
|
$this->assertEquals($expectedResult, $result); |
491
|
|
|
} |
492
|
|
|
|
493
|
|
|
public function testLkDocumentsCreate(): void |
494
|
|
|
{ |
495
|
|
|
$request = new DocumentCreateRequest( |
496
|
|
|
'document', |
497
|
|
|
'MANUAL', |
498
|
|
|
'signature', |
499
|
|
|
ProductGroup::SHOES, |
500
|
|
|
DocumentLkType::LP_INTRODUCE_GOODS |
501
|
|
|
); |
502
|
|
|
|
503
|
|
|
$this->serializer |
504
|
|
|
->method('serialize') |
505
|
|
|
->with($request) |
506
|
|
|
->willReturn(self::SERIALIZED_VALUE); |
507
|
|
|
|
508
|
|
|
$this->client->expects($this->once()) |
|
|
|
|
509
|
|
|
->method('request') |
510
|
|
|
->with( |
511
|
|
|
'POST', |
512
|
|
|
'api/v3/lk/documents/create', |
513
|
|
|
[ |
514
|
|
|
RequestOptions::BODY => self::SERIALIZED_VALUE, |
515
|
|
|
RequestOptions::HEADERS => [ |
516
|
|
|
'Content-Type' => 'application/json', |
517
|
|
|
'Authorization' => 'Bearer ' . self::TOKEN, |
518
|
|
|
], |
519
|
|
|
RequestOptions::HTTP_ERRORS => true, |
520
|
|
|
RequestOptions::QUERY => ['pg' => ProductGroup::SHOES], |
521
|
|
|
] |
522
|
|
|
) |
523
|
|
|
->willReturn( |
524
|
|
|
(new Response()) |
525
|
|
|
->withBody(stream_for(self::API_RESPONSE)) |
526
|
|
|
); |
527
|
|
|
|
528
|
|
|
$result = $this->api->lkDocumentsCreate(self::TOKEN, $request); |
529
|
|
|
|
530
|
|
|
$this->assertEquals(self::API_RESPONSE, $result); |
531
|
|
|
} |
532
|
|
|
|
533
|
|
|
public function testLkImportSend(): void |
534
|
|
|
{ |
535
|
|
|
$request = new DocumentCreateRequest('document', 'MANUAL', 'signature'); |
536
|
|
|
|
537
|
|
|
$this->serializer |
538
|
|
|
->method('serialize') |
539
|
|
|
->with($request) |
540
|
|
|
->willReturn(self::SERIALIZED_VALUE); |
541
|
|
|
|
542
|
|
|
$this->client->expects($this->once()) |
|
|
|
|
543
|
|
|
->method('request') |
544
|
|
|
->with( |
545
|
|
|
'POST', |
546
|
|
|
'api/v3/lk/import/send', |
547
|
|
|
[ |
548
|
|
|
RequestOptions::BODY => self::SERIALIZED_VALUE, |
549
|
|
|
RequestOptions::HEADERS => [ |
550
|
|
|
'Content-Type' => 'application/json', |
551
|
|
|
'Authorization' => 'Bearer ' . self::TOKEN, |
552
|
|
|
], |
553
|
|
|
RequestOptions::HTTP_ERRORS => true, |
554
|
|
|
RequestOptions::QUERY => null, |
555
|
|
|
] |
556
|
|
|
) |
557
|
|
|
->willReturn( |
558
|
|
|
(new Response()) |
559
|
|
|
->withBody(stream_for(self::API_RESPONSE)) |
560
|
|
|
); |
561
|
|
|
|
562
|
|
|
$result = $this->api->lkImportSend(self::TOKEN, $request); |
563
|
|
|
|
564
|
|
|
$this->assertEquals(self::API_RESPONSE, $result); |
565
|
|
|
} |
566
|
|
|
|
567
|
|
|
public function testLkReceiptSend(): void |
568
|
|
|
{ |
569
|
|
|
$request = new DocumentCreateRequest('document', 'MANUAL', 'signature'); |
570
|
|
|
|
571
|
|
|
$this->serializer |
572
|
|
|
->method('serialize') |
573
|
|
|
->with($request) |
574
|
|
|
->willReturn(self::SERIALIZED_VALUE); |
575
|
|
|
|
576
|
|
|
$this->client->expects($this->once()) |
|
|
|
|
577
|
|
|
->method('request') |
578
|
|
|
->with( |
579
|
|
|
'POST', |
580
|
|
|
'api/v3/lk/receipt/send', |
581
|
|
|
[ |
582
|
|
|
RequestOptions::BODY => self::SERIALIZED_VALUE, |
583
|
|
|
RequestOptions::HEADERS => [ |
584
|
|
|
'Content-Type' => 'application/json', |
585
|
|
|
'Authorization' => 'Bearer ' . self::TOKEN, |
586
|
|
|
], |
587
|
|
|
RequestOptions::HTTP_ERRORS => true, |
588
|
|
|
RequestOptions::QUERY => null, |
589
|
|
|
] |
590
|
|
|
) |
591
|
|
|
->willReturn( |
592
|
|
|
(new Response()) |
593
|
|
|
->withBody(stream_for(self::API_RESPONSE)) |
594
|
|
|
); |
595
|
|
|
|
596
|
|
|
$result = $this->api->lkReceiptSend(self::TOKEN, $request); |
597
|
|
|
|
598
|
|
|
$this->assertEquals(self::API_RESPONSE, $result); |
599
|
|
|
} |
600
|
|
|
|
601
|
|
|
public function testLkDocumentsShipmentCreate(): void |
602
|
|
|
{ |
603
|
|
|
$request = new DocumentCreateRequest('document', 'MANUAL', 'signature'); |
604
|
|
|
|
605
|
|
|
$this->serializer |
606
|
|
|
->method('serialize') |
607
|
|
|
->with($request) |
608
|
|
|
->willReturn(self::SERIALIZED_VALUE); |
609
|
|
|
|
610
|
|
|
$this->client->expects($this->once()) |
|
|
|
|
611
|
|
|
->method('request') |
612
|
|
|
->with( |
613
|
|
|
'POST', |
614
|
|
|
'api/v3/lk/documents/shipment/create', |
615
|
|
|
[ |
616
|
|
|
RequestOptions::BODY => self::SERIALIZED_VALUE, |
617
|
|
|
RequestOptions::HEADERS => [ |
618
|
|
|
'Content-Type' => 'application/json', |
619
|
|
|
'Authorization' => 'Bearer ' . self::TOKEN, |
620
|
|
|
], |
621
|
|
|
RequestOptions::HTTP_ERRORS => true, |
622
|
|
|
RequestOptions::QUERY => null, |
623
|
|
|
] |
624
|
|
|
) |
625
|
|
|
->willReturn( |
626
|
|
|
(new Response()) |
627
|
|
|
->withBody(stream_for(self::API_RESPONSE)) |
628
|
|
|
); |
629
|
|
|
|
630
|
|
|
$result = $this->api->lkDocumentsShipmentCreate(self::TOKEN, $request); |
631
|
|
|
|
632
|
|
|
$this->assertEquals(self::API_RESPONSE, $result); |
633
|
|
|
} |
634
|
|
|
|
635
|
|
|
public function testLkDocumentsAcceptanceCreate(): void |
636
|
|
|
{ |
637
|
|
|
$request = new DocumentCreateRequest('document', 'MANUAL', 'signature'); |
638
|
|
|
|
639
|
|
|
$this->serializer |
640
|
|
|
->method('serialize') |
641
|
|
|
->with($request) |
642
|
|
|
->willReturn(self::SERIALIZED_VALUE); |
643
|
|
|
|
644
|
|
|
$this->client->expects($this->once()) |
|
|
|
|
645
|
|
|
->method('request') |
646
|
|
|
->with( |
647
|
|
|
'POST', |
648
|
|
|
'api/v3/lk/documents/acceptance/create', |
649
|
|
|
[ |
650
|
|
|
RequestOptions::BODY => self::SERIALIZED_VALUE, |
651
|
|
|
RequestOptions::HEADERS => [ |
652
|
|
|
'Content-Type' => 'application/json', |
653
|
|
|
'Authorization' => 'Bearer ' . self::TOKEN, |
654
|
|
|
], |
655
|
|
|
RequestOptions::HTTP_ERRORS => true, |
656
|
|
|
RequestOptions::QUERY => null, |
657
|
|
|
] |
658
|
|
|
) |
659
|
|
|
->willReturn( |
660
|
|
|
(new Response()) |
661
|
|
|
->withBody(stream_for(self::API_RESPONSE)) |
662
|
|
|
); |
663
|
|
|
|
664
|
|
|
$result = $this->api->lkDocumentsAcceptanceCreate(self::TOKEN, $request); |
665
|
|
|
|
666
|
|
|
$this->assertEquals(self::API_RESPONSE, $result); |
667
|
|
|
} |
668
|
|
|
|
669
|
|
|
public function testProductInfo(): void |
670
|
|
|
{ |
671
|
|
|
$request = ['aaa', 'bbb']; |
672
|
|
|
$expectedResult = new ProductInfoResponse([], 0); |
673
|
|
|
|
674
|
|
|
$this->serializer |
675
|
|
|
->method('deserialize') |
676
|
|
|
->with( |
677
|
|
|
get_class($expectedResult), |
678
|
|
|
self::API_RESPONSE |
679
|
|
|
) |
680
|
|
|
->willReturn($expectedResult); |
681
|
|
|
|
682
|
|
|
$this->client->expects($this->once()) |
|
|
|
|
683
|
|
|
->method('request') |
684
|
|
|
->with( |
685
|
|
|
'GET', |
686
|
|
|
'api/v3/product/info', |
687
|
|
|
[ |
688
|
|
|
RequestOptions::BODY => null, |
689
|
|
|
RequestOptions::HEADERS => [ |
690
|
|
|
'Content-Type' => 'application/json', |
691
|
|
|
'Authorization' => 'Bearer ' . self::TOKEN, |
692
|
|
|
], |
693
|
|
|
RequestOptions::HTTP_ERRORS => true, |
694
|
|
|
RequestOptions::QUERY => [ |
695
|
|
|
'gtins' => implode(',', $request), |
696
|
|
|
], |
697
|
|
|
] |
698
|
|
|
) |
699
|
|
|
->willReturn( |
700
|
|
|
(new Response()) |
701
|
|
|
->withBody(stream_for(self::API_RESPONSE)) |
702
|
|
|
); |
703
|
|
|
|
704
|
|
|
$result = $this->api->productInfo(self::TOKEN, $request); |
705
|
|
|
|
706
|
|
|
$this->assertEquals($expectedResult, $result); |
707
|
|
|
} |
708
|
|
|
} |
709
|
|
|
|
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: