Completed
Push — master ( d80f87...33b881 )
by Agaletskiy
01:56
created

IsmpApiTest::testLkDocumentsCreate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 39

Duplication

Lines 0
Ratio 0 %

Importance

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