IsmpApiTest::testLkReceiptSend()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 33

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 33
rs 9.392
c 0
b 0
f 0
cc 1
nc 1
nop 0
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,
0 ignored issues
show
Documentation introduced by
$this->client is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<GuzzleHttp\ClientInterface>.

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...
65
            $this->serializer
0 ignored issues
show
Documentation introduced by
$this->serializer is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Lamoda\IsmpClient...er\SerializerInterface>.

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...
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)));
0 ignored issues
show
Documentation introduced by
$this->createMock(\Psr\H...equestInterface::class) is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Psr\Http\Message\RequestInterface>.

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...
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())
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit\Framework\MockObject\MockObject, but not in GuzzleHttp\ClientInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
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))
0 ignored issues
show
Deprecated Code introduced by
The function GuzzleHttp\Psr7\stream_for() has been deprecated with message: stream_for will be removed in guzzlehttp/psr7:2.0. Use Utils::streamFor instead.

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
118
            );
119
120
        $result = $this->api->authCertKey();
121
122
        $this->assertEquals($expectedResult, $result);
123
    }
124
125
    /**
126
     * @dataProvider provideTestAuthCertData
127
     * @param AuthCertRequest $request
128
     * @param string|null $connection
129
     * @param AuthCertResponse $expectedResult
130
     */
131
    public function testAuthCert(
132
        AuthCertRequest $request,
133
        ?string $connection,
134
        AuthCertResponse $expectedResult
135
    ): void {
136
        $this->serializer
137
            ->method('serialize')
138
            ->with($request)
139
            ->willReturn(self::SERIALIZED_VALUE);
140
141
        $this->serializer
142
            ->method('deserialize')
143
            ->with(
144
                get_class($expectedResult),
145
                self::API_RESPONSE
146
            )
147
            ->willReturn($expectedResult);
148
149
        $this->client->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit\Framework\MockObject\MockObject, but not in GuzzleHttp\ClientInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
150
            ->method('request')
151
            ->with(
152
                'POST',
153
                sprintf('api/v3/auth/cert/%s', $connection),
154
                [
155
                    RequestOptions::BODY => self::SERIALIZED_VALUE,
156
                    RequestOptions::HEADERS => [
157
                        'Content-Type' => 'application/json',
158
                    ],
159
                    RequestOptions::HTTP_ERRORS => true,
160
                    RequestOptions::QUERY => null,
161
                ]
162
            )
163
            ->willReturn(
164
                (new Response())
165
                    ->withBody(stream_for(self::API_RESPONSE))
0 ignored issues
show
Deprecated Code introduced by
The function GuzzleHttp\Psr7\stream_for() has been deprecated with message: stream_for will be removed in guzzlehttp/psr7:2.0. Use Utils::streamFor instead.

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
166
            );
167
168
        $result = $this->api->authCert($request, $connection);
169
170
        $this->assertEquals($expectedResult, $result);
171
    }
172
173
    public function provideTestAuthCertData(): iterable
174
    {
175
        yield 'Without connection' => [
176
            $request = new AuthCertRequest(self::UUID, self::RANDOM_DATA),
177
            null,
178
            $response = new AuthCertResponse('token-value')
179
        ];
180
181
        yield 'With connection' => [
182
            $request,
183
            'connection',
184
            $response
185
        ];
186
    }
187
188
    public function testFacadeOrder(): void
189
    {
190
        $request = new FacadeOrderRequest('document', 'MANUAL', 'signature');
191
        $expectedResult = new FacadeOrderResponse('orderId', 'status');
192
193
        $this->serializer
194
            ->method('serialize')
195
            ->with($request)
196
            ->willReturn(self::SERIALIZED_VALUE);
197
198
        $this->serializer
199
            ->method('deserialize')
200
            ->with(
201
                get_class($expectedResult),
202
                self::API_RESPONSE
203
            )
204
            ->willReturn($expectedResult);
205
206
        $this->client->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit\Framework\MockObject\MockObject, but not in GuzzleHttp\ClientInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
207
            ->method('request')
208
            ->with(
209
                'POST',
210
                'api/v3/facade/order/',
211
                [
212
                    RequestOptions::BODY => self::SERIALIZED_VALUE,
213
                    RequestOptions::HEADERS => [
214
                        'Content-Type' => 'application/json',
215
                        'Authorization' => 'Bearer ' . self::TOKEN,
216
                    ],
217
                    RequestOptions::HTTP_ERRORS => true,
218
                    RequestOptions::QUERY => null,
219
                ]
220
            )
221
            ->willReturn(
222
                (new Response())
223
                    ->withBody(stream_for(self::API_RESPONSE))
0 ignored issues
show
Deprecated Code introduced by
The function GuzzleHttp\Psr7\stream_for() has been deprecated with message: stream_for will be removed in guzzlehttp/psr7:2.0. Use Utils::streamFor instead.

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
224
            );
225
226
        $result = $this->api->facadeOrder(self::TOKEN, $request);
227
228
        $this->assertEquals($expectedResult, $result);
229
    }
230
231
    public function testFacadeOrderDetails(): void
232
    {
233
        $expectedResult = new FacadeOrderDetailsResponse(self::IDENTITY, 'MANUAL', 123456);
234
235
        $this->serializer
236
            ->method('deserialize')
237
            ->with(
238
                get_class($expectedResult),
239
                self::API_RESPONSE
240
            )
241
            ->willReturn($expectedResult);
242
243
        $this->client->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit\Framework\MockObject\MockObject, but not in GuzzleHttp\ClientInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
244
            ->method('request')
245
            ->with(
246
                'GET',
247
                sprintf('api/v3/facade/order/%s/details', self::IDENTITY),
248
                [
249
                    RequestOptions::BODY => null,
250
                    RequestOptions::HEADERS => [
251
                        'Content-Type' => 'application/json',
252
                        'Authorization' => 'Bearer ' . self::TOKEN,
253
                    ],
254
                    RequestOptions::HTTP_ERRORS => true,
255
                    RequestOptions::QUERY => null,
256
                ]
257
            )
258
            ->willReturn(
259
                (new Response())
260
                    ->withBody(stream_for(self::API_RESPONSE))
0 ignored issues
show
Deprecated Code introduced by
The function GuzzleHttp\Psr7\stream_for() has been deprecated with message: stream_for will be removed in guzzlehttp/psr7:2.0. Use Utils::streamFor instead.

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
261
            );
262
263
        $result = $this->api->facadeOrderDetails(self::TOKEN, self::IDENTITY);
264
265
        $this->assertEquals($expectedResult, $result);
266
    }
267
268
    public function testFacadeDocListV2(): void
269
    {
270
        $query = new FacadeDocListV2Query();
271
        $query->setDocumentStatus(FacadeDocListV2Query::DOCUMENT_STATUS_CHECKED_OK);
272
        $query->setDateFrom(new \DateTimeImmutable('2019-01-01 11:12:13', new \DateTimeZone('UTC')));
273
        $expectedResult = new FacadeDocListV2Response(0);
274
275
        $this->serializer
276
            ->method('deserialize')
277
            ->with(
278
                get_class($expectedResult),
279
                self::API_RESPONSE
280
            )
281
            ->willReturn($expectedResult);
282
283
        $this->client->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit\Framework\MockObject\MockObject, but not in GuzzleHttp\ClientInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
284
            ->method('request')
285
            ->with(
286
                'GET',
287
                'api/v3/facade/doc/listV2',
288
                [
289
                    RequestOptions::BODY => null,
290
                    RequestOptions::HEADERS => [
291
                        'Content-Type' => 'application/json',
292
                        'Authorization' => 'Bearer ' . self::TOKEN,
293
                    ],
294
                    RequestOptions::HTTP_ERRORS => true,
295
                    RequestOptions::QUERY => [
296
                        'documentStatus' => FacadeDocListV2Query::DOCUMENT_STATUS_CHECKED_OK,
297
                        'dateFrom' => '2019-01-01T11:12:13.000+00:00',
298
                        'limit' => $query->getLimit(),
299
                    ],
300
                ]
301
            )
302
            ->willReturn(
303
                (new Response())
304
                    ->withBody(stream_for(self::API_RESPONSE))
0 ignored issues
show
Deprecated Code introduced by
The function GuzzleHttp\Psr7\stream_for() has been deprecated with message: stream_for will be removed in guzzlehttp/psr7:2.0. Use Utils::streamFor instead.

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
305
            );
306
307
        $result = $this->api->facadeDocListV2(self::TOKEN, $query);
308
309
        $this->assertEquals($expectedResult, $result);
310
    }
311
312
    /**
313
     * @dataProvider provideTestFacadeDocBodyData
314
     */
315
    public function testFacadeDocBody(
316
        ?int $limitOption,
317
        ?string $orderColumnOption,
318
        ?string $orderedColumnValueOption,
319
        ?string $pageDirOption,
320
        array $expectedOptions
321
    ): void {
322
        $expectedResult = new FacadeDocBodyResponse(self::IDENTITY, '2019-01-01', 'IMPORT', 'NEW', 'Tester', 'Test');
323
        $expectedResult->setCisTotal('100');
324
325
        $this->serializer
326
            ->method('deserialize')
327
            ->with(
328
                get_class($expectedResult),
329
                self::API_RESPONSE
330
            )
331
            ->willReturn($expectedResult);
332
333
        $this->client->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit\Framework\MockObject\MockObject, but not in GuzzleHttp\ClientInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
334
            ->method('request')
335
            ->with(
336
                'GET',
337
                sprintf('api/v3/facade/doc/%s/body', self::IDENTITY),
338
                $expectedOptions
339
            )
340
            ->willReturn(
341
                (new Response())
342
                    ->withBody(stream_for(self::API_RESPONSE))
0 ignored issues
show
Deprecated Code introduced by
The function GuzzleHttp\Psr7\stream_for() has been deprecated with message: stream_for will be removed in guzzlehttp/psr7:2.0. Use Utils::streamFor instead.

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
343
            );
344
345
        $result = $this->api->facadeDocBody(
346
            self::TOKEN,
347
            self::IDENTITY,
348
            $limitOption,
349
            $orderColumnOption,
350
            $orderedColumnValueOption,
351
            $pageDirOption
352
        );
353
354
        $this->assertEquals($expectedResult, $result);
355
    }
356
357
    public function provideTestFacadeDocBodyData(): iterable
358
    {
359
        yield 'all nullable parameters' => [
360
            null,
361
            null,
362
            null,
363
            null,
364
            [
365
                RequestOptions::BODY => null,
366
                RequestOptions::HEADERS => [
367
                    'Content-Type' => 'application/json',
368
                    'Authorization' => 'Bearer ' . self::TOKEN,
369
                ],
370
                RequestOptions::HTTP_ERRORS => true,
371
                RequestOptions::QUERY => null,
372
            ],
373
        ];
374
375
        yield 'only limit' => [
376
            1000,
377
            null,
378
            null,
379
            null,
380
            [
381
                RequestOptions::BODY => null,
382
                RequestOptions::HEADERS => [
383
                    'Content-Type' => 'application/json',
384
                    'Authorization' => 'Bearer ' . self::TOKEN,
385
                ],
386
                RequestOptions::HTTP_ERRORS => true,
387
                RequestOptions::QUERY => [
388
                    'limit' => 1000,
389
                ],
390
            ],
391
        ];
392
393
        yield 'only order column option' => [
394
            null,
395
            'order-column',
396
            null,
397
            null,
398
            [
399
                RequestOptions::BODY => null,
400
                RequestOptions::HEADERS => [
401
                    'Content-Type' => 'application/json',
402
                    'Authorization' => 'Bearer ' . self::TOKEN,
403
                ],
404
                RequestOptions::HTTP_ERRORS => true,
405
                RequestOptions::QUERY => [
406
                    'orderColumn' => 'order-column',
407
                ],
408
            ],
409
        ];
410
411
        yield 'only ordered column value option' => [
412
            null,
413
            null,
414
            'ordered-column-value',
415
            null,
416
            [
417
                RequestOptions::BODY => null,
418
                RequestOptions::HEADERS => [
419
                    'Content-Type' => 'application/json',
420
                    'Authorization' => 'Bearer ' . self::TOKEN,
421
                ],
422
                RequestOptions::HTTP_ERRORS => true,
423
                RequestOptions::QUERY => [
424
                    'orderedColumnValue' => 'ordered-column-value',
425
                ],
426
            ],
427
        ];
428
429
        yield 'only page dir option' => [
430
            null,
431
            null,
432
            null,
433
            'page-dir',
434
            [
435
                RequestOptions::BODY => null,
436
                RequestOptions::HEADERS => [
437
                    'Content-Type' => 'application/json',
438
                    'Authorization' => 'Bearer ' . self::TOKEN,
439
                ],
440
                RequestOptions::HTTP_ERRORS => true,
441
                RequestOptions::QUERY => [
442
                    'pageDir' => 'page-dir'
443
                ],
444
            ],
445
        ];
446
447
448
        yield 'all parameters' => [
449
            1000,
450
            'order-column',
451
            'ordered-column-value',
452
            'page-dir',
453
            [
454
                RequestOptions::BODY => null,
455
                RequestOptions::HEADERS => [
456
                    'Content-Type' => 'application/json',
457
                    'Authorization' => 'Bearer ' . self::TOKEN,
458
                ],
459
                RequestOptions::HTTP_ERRORS => true,
460
                RequestOptions::QUERY => [
461
                    'limit' => 1000,
462
                    'orderColumn' => 'order-column',
463
                    'orderedColumnValue' => 'ordered-column-value',
464
                    'pageDir' => 'page-dir',
465
                ],
466
            ],
467
        ];
468
    }
469
470
    public function testFacadeCisList(): void
471
    {
472
        $request = new FacadeCisListRequest(self::IDENTITY);
473
        $expectedResult = new FacadeCisListResponse();
474
        $requestBody = '{"cises": [' . self::IDENTITY . ']}';
475
476
        $this->serializer
477
            ->method('serialize')
478
            ->with($request)
479
            ->willReturn($requestBody);
480
481
        $this->serializer
482
            ->method('deserialize')
483
            ->with(
484
                get_class($expectedResult),
485
                self::API_RESPONSE
486
            )
487
            ->willReturn($expectedResult);
488
489
        $this->client->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit\Framework\MockObject\MockObject, but not in GuzzleHttp\ClientInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
490
            ->method('request')
491
            ->with(
492
                'POST',
493
                'api/v3/facade/cis/cis_list',
494
                [
495
                    RequestOptions::BODY => $requestBody,
496
                    RequestOptions::HEADERS => [
497
                        'Content-Type' => 'application/json',
498
                        'Authorization' => 'Bearer ' . self::TOKEN,
499
                    ],
500
                    RequestOptions::HTTP_ERRORS => true,
501
                    RequestOptions::QUERY => null,
502
                ]
503
            )
504
            ->willReturn(
505
                (new Response())
506
                    ->withBody(stream_for(self::API_RESPONSE))
0 ignored issues
show
Deprecated Code introduced by
The function GuzzleHttp\Psr7\stream_for() has been deprecated with message: stream_for will be removed in guzzlehttp/psr7:2.0. Use Utils::streamFor instead.

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
507
            );
508
509
        $result = $this->api->facadeCisList(self::TOKEN, $request);
510
511
        $this->assertEquals($expectedResult, $result);
512
    }
513
514
    public function testLkDocumentsCreate(): void
515
    {
516
        $request = new DocumentCreateRequest(
517
            'document',
518
            'MANUAL',
519
            'signature',
520
            ProductGroup::SHOES,
521
            DocumentLkType::LP_INTRODUCE_GOODS
522
        );
523
524
        $this->serializer
525
            ->method('serialize')
526
            ->with($request)
527
            ->willReturn(self::SERIALIZED_VALUE);
528
529
        $this->client->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit\Framework\MockObject\MockObject, but not in GuzzleHttp\ClientInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
530
            ->method('request')
531
            ->with(
532
                'POST',
533
                'api/v3/lk/documents/create',
534
                [
535
                    RequestOptions::BODY => self::SERIALIZED_VALUE,
536
                    RequestOptions::HEADERS => [
537
                        'Content-Type' => 'application/json',
538
                        'Authorization' => 'Bearer ' . self::TOKEN,
539
                    ],
540
                    RequestOptions::HTTP_ERRORS => true,
541
                    RequestOptions::QUERY => ['pg' => ProductGroup::SHOES],
542
                ]
543
            )
544
            ->willReturn(
545
                (new Response())
546
                    ->withBody(stream_for(self::API_RESPONSE))
0 ignored issues
show
Deprecated Code introduced by
The function GuzzleHttp\Psr7\stream_for() has been deprecated with message: stream_for will be removed in guzzlehttp/psr7:2.0. Use Utils::streamFor instead.

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
547
            );
548
549
        $result = $this->api->lkDocumentsCreate(self::TOKEN, $request);
550
551
        $this->assertEquals(self::API_RESPONSE, $result);
552
    }
553
554
    public function testLkImportSend(): void
555
    {
556
        $request = new DocumentCreateRequest('document', 'MANUAL', 'signature');
557
558
        $this->serializer
559
            ->method('serialize')
560
            ->with($request)
561
            ->willReturn(self::SERIALIZED_VALUE);
562
563
        $this->client->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit\Framework\MockObject\MockObject, but not in GuzzleHttp\ClientInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
564
            ->method('request')
565
            ->with(
566
                'POST',
567
                'api/v3/lk/import/send',
568
                [
569
                    RequestOptions::BODY => self::SERIALIZED_VALUE,
570
                    RequestOptions::HEADERS => [
571
                        'Content-Type' => 'application/json',
572
                        'Authorization' => 'Bearer ' . self::TOKEN,
573
                    ],
574
                    RequestOptions::HTTP_ERRORS => true,
575
                    RequestOptions::QUERY => null,
576
                ]
577
            )
578
            ->willReturn(
579
                (new Response())
580
                    ->withBody(stream_for(self::API_RESPONSE))
0 ignored issues
show
Deprecated Code introduced by
The function GuzzleHttp\Psr7\stream_for() has been deprecated with message: stream_for will be removed in guzzlehttp/psr7:2.0. Use Utils::streamFor instead.

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
581
            );
582
583
        $result = $this->api->lkImportSend(self::TOKEN, $request);
584
585
        $this->assertEquals(self::API_RESPONSE, $result);
586
    }
587
588
    public function testLkReceiptSend(): void
589
    {
590
        $request = new DocumentCreateRequest('document', 'MANUAL', 'signature');
591
592
        $this->serializer
593
            ->method('serialize')
594
            ->with($request)
595
            ->willReturn(self::SERIALIZED_VALUE);
596
597
        $this->client->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit\Framework\MockObject\MockObject, but not in GuzzleHttp\ClientInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
598
            ->method('request')
599
            ->with(
600
                'POST',
601
                'api/v3/lk/receipt/send',
602
                [
603
                    RequestOptions::BODY => self::SERIALIZED_VALUE,
604
                    RequestOptions::HEADERS => [
605
                        'Content-Type' => 'application/json',
606
                        'Authorization' => 'Bearer ' . self::TOKEN,
607
                    ],
608
                    RequestOptions::HTTP_ERRORS => true,
609
                    RequestOptions::QUERY => null,
610
                ]
611
            )
612
            ->willReturn(
613
                (new Response())
614
                    ->withBody(stream_for(self::API_RESPONSE))
0 ignored issues
show
Deprecated Code introduced by
The function GuzzleHttp\Psr7\stream_for() has been deprecated with message: stream_for will be removed in guzzlehttp/psr7:2.0. Use Utils::streamFor instead.

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
615
            );
616
617
        $result = $this->api->lkReceiptSend(self::TOKEN, $request);
618
619
        $this->assertEquals(self::API_RESPONSE, $result);
620
    }
621
622
    public function testLkDocumentsShipmentCreate(): void
623
    {
624
        $request = new DocumentCreateRequest('document', 'MANUAL', 'signature');
625
626
        $this->serializer
627
            ->method('serialize')
628
            ->with($request)
629
            ->willReturn(self::SERIALIZED_VALUE);
630
631
        $this->client->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit\Framework\MockObject\MockObject, but not in GuzzleHttp\ClientInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
632
            ->method('request')
633
            ->with(
634
                'POST',
635
                'api/v3/lk/documents/shipment/create',
636
                [
637
                    RequestOptions::BODY => self::SERIALIZED_VALUE,
638
                    RequestOptions::HEADERS => [
639
                        'Content-Type' => 'application/json',
640
                        'Authorization' => 'Bearer ' . self::TOKEN,
641
                    ],
642
                    RequestOptions::HTTP_ERRORS => true,
643
                    RequestOptions::QUERY => null,
644
                ]
645
            )
646
            ->willReturn(
647
                (new Response())
648
                    ->withBody(stream_for(self::API_RESPONSE))
0 ignored issues
show
Deprecated Code introduced by
The function GuzzleHttp\Psr7\stream_for() has been deprecated with message: stream_for will be removed in guzzlehttp/psr7:2.0. Use Utils::streamFor instead.

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
649
            );
650
651
        $result = $this->api->lkDocumentsShipmentCreate(self::TOKEN, $request);
652
653
        $this->assertEquals(self::API_RESPONSE, $result);
654
    }
655
656
    public function testLkDocumentsAcceptanceCreate(): void
657
    {
658
        $request = new DocumentCreateRequest('document', 'MANUAL', 'signature');
659
660
        $this->serializer
661
            ->method('serialize')
662
            ->with($request)
663
            ->willReturn(self::SERIALIZED_VALUE);
664
665
        $this->client->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit\Framework\MockObject\MockObject, but not in GuzzleHttp\ClientInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
666
            ->method('request')
667
            ->with(
668
                'POST',
669
                'api/v3/lk/documents/acceptance/create',
670
                [
671
                    RequestOptions::BODY => self::SERIALIZED_VALUE,
672
                    RequestOptions::HEADERS => [
673
                        'Content-Type' => 'application/json',
674
                        'Authorization' => 'Bearer ' . self::TOKEN,
675
                    ],
676
                    RequestOptions::HTTP_ERRORS => true,
677
                    RequestOptions::QUERY => null,
678
                ]
679
            )
680
            ->willReturn(
681
                (new Response())
682
                    ->withBody(stream_for(self::API_RESPONSE))
0 ignored issues
show
Deprecated Code introduced by
The function GuzzleHttp\Psr7\stream_for() has been deprecated with message: stream_for will be removed in guzzlehttp/psr7:2.0. Use Utils::streamFor instead.

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
683
            );
684
685
        $result = $this->api->lkDocumentsAcceptanceCreate(self::TOKEN, $request);
686
687
        $this->assertEquals(self::API_RESPONSE, $result);
688
    }
689
690
    public function testProductInfo(): void
691
    {
692
        $request = ['aaa', 'bbb'];
693
        $expectedResult = new ProductInfoResponse([], 0);
694
695
        $this->serializer
696
            ->method('deserialize')
697
            ->with(
698
                get_class($expectedResult),
699
                self::API_RESPONSE
700
            )
701
            ->willReturn($expectedResult);
702
703
        $this->client->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit\Framework\MockObject\MockObject, but not in GuzzleHttp\ClientInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
704
            ->method('request')
705
            ->with(
706
                'GET',
707
                'api/v3/product/info',
708
                [
709
                    RequestOptions::BODY => null,
710
                    RequestOptions::HEADERS => [
711
                        'Content-Type' => 'application/json',
712
                        'Authorization' => 'Bearer ' . self::TOKEN,
713
                    ],
714
                    RequestOptions::HTTP_ERRORS => true,
715
                    RequestOptions::QUERY => [
716
                        'gtins' => implode(',', $request),
717
                    ],
718
                ]
719
            )
720
            ->willReturn(
721
                (new Response())
722
                    ->withBody(stream_for(self::API_RESPONSE))
0 ignored issues
show
Deprecated Code introduced by
The function GuzzleHttp\Psr7\stream_for() has been deprecated with message: stream_for will be removed in guzzlehttp/psr7:2.0. Use Utils::streamFor instead.

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
723
            );
724
725
        $result = $this->api->productInfo(self::TOKEN, $request);
726
727
        $this->assertEquals($expectedResult, $result);
728
    }
729
}
730