Passed
Push — master ( db0ae1...f66061 )
by Agaletskiy
01:56
created

IsmpApiTest::testLkImportSend()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 33

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 33
c 0
b 0
f 0
rs 9.392
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
    /**
290
     * @dataProvider dataFacadeDocBody
291
     */
292
    public function testFacadeDocBody(?int $limitOption, array $expectedOptions): void
293
    {
294
        $expectedResult = new FacadeDocBodyResponse(self::IDENTITY, '2019-01-01', 'IMPORT', 'NEW', 'Tester', 'Test');
295
296
        $this->serializer
297
            ->method('deserialize')
298
            ->with(
299
                get_class($expectedResult),
300
                self::API_RESPONSE
301
            )
302
            ->willReturn($expectedResult);
303
304
        $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...
305
            ->method('request')
306
            ->with(
307
                'GET',
308
                sprintf('api/v3/facade/doc/%s/body', self::IDENTITY),
309
                $expectedOptions
310
            )
311
            ->willReturn(
312
                (new Response())
313
                    ->withBody(stream_for(self::API_RESPONSE))
314
            );
315
316
        $result = $this->api->facadeDocBody(self::TOKEN, self::IDENTITY, $limitOption);
317
318
        $this->assertEquals($expectedResult, $result);
319
    }
320
321
    public function dataFacadeDocBody(): iterable
322
    {
323
        yield 'null as a limit' => [
324
            null,
325
            [
326
                RequestOptions::BODY => null,
327
                RequestOptions::HEADERS => [
328
                    'Content-Type' => 'application/json',
329
                    'Authorization' => 'Bearer ' . self::TOKEN
330
                ],
331
                RequestOptions::HTTP_ERRORS => true,
332
                RequestOptions::QUERY => null,
333
            ]
334
        ];
335
336
        yield 'number as a limit' => [
337
            1000,
338
            [
339
                RequestOptions::BODY => null,
340
                RequestOptions::HEADERS => [
341
                    'Content-Type' => 'application/json',
342
                    'Authorization' => 'Bearer ' . self::TOKEN
343
                ],
344
                RequestOptions::HTTP_ERRORS => true,
345
                RequestOptions::QUERY => [
346
                    'limit' => 1000
347
                ],
348
            ]
349
        ];
350
    }
351
352
    public function testFacadeCisList(): void
353
    {
354
        $expectedResult = new FacadeCisListResponse();
355
356
        $this->serializer
357
            ->method('deserialize')
358
            ->with(
359
                get_class($expectedResult),
360
                self::API_RESPONSE
361
            )
362
            ->willReturn($expectedResult);
363
364
        $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...
365
            ->method('request')
366
            ->with(
367
                'GET',
368
                'api/v3/facade/cis/cis_list',
369
                [
370
                    RequestOptions::BODY => null,
371
                    RequestOptions::HEADERS => [
372
                        'Content-Type' => 'application/json',
373
                        'Authorization' => 'Bearer ' . self::TOKEN
374
                    ],
375
                    RequestOptions::HTTP_ERRORS => true,
376
                    RequestOptions::QUERY => [
377
                        'cis' => self::IDENTITY
378
                    ],
379
                ]
380
            )
381
            ->willReturn(
382
                (new Response())
383
                    ->withBody(stream_for(self::API_RESPONSE))
384
            );
385
386
        $result = $this->api->facadeCisList(self::TOKEN, self::IDENTITY);
387
388
        $this->assertEquals($expectedResult, $result);
389
    }
390
391
    public function testLkDocumentsCreate(): void
392
    {
393
        $request = new DocumentCreateRequest(
394
            'document',
395
            'MANUAL',
396
            'signature',
397
            ProductGroup::SHOES,
398
            DocumentLkType::LP_INTRODUCE_GOODS
399
        );
400
401
        $this->serializer
402
            ->method('serialize')
403
            ->with($request)
404
            ->willReturn(self::SERIALIZED_VALUE);
405
406
        $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...
407
            ->method('request')
408
            ->with(
409
                'POST',
410
                'api/v3/lk/documents/create',
411
                [
412
                    RequestOptions::BODY => self::SERIALIZED_VALUE,
413
                    RequestOptions::HEADERS => [
414
                        'Content-Type' => 'application/json',
415
                        'Authorization' => 'Bearer ' . self::TOKEN,
416
                    ],
417
                    RequestOptions::HTTP_ERRORS => true,
418
                    RequestOptions::QUERY => ['pg' => ProductGroup::SHOES],
419
                ]
420
            )
421
            ->willReturn(
422
                (new Response())
423
                    ->withBody(stream_for(self::API_RESPONSE))
424
            );
425
426
        $result = $this->api->lkDocumentsCreate(self::TOKEN, $request);
427
428
        $this->assertEquals(self::API_RESPONSE, $result);
429
    }
430
431
    public function testLkImportSend(): void
432
    {
433
        $request = new DocumentCreateRequest('document', 'MANUAL', 'signature');
434
435
        $this->serializer
436
            ->method('serialize')
437
            ->with($request)
438
            ->willReturn(self::SERIALIZED_VALUE);
439
440
        $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...
441
            ->method('request')
442
            ->with(
443
                'POST',
444
                'api/v3/lk/import/send',
445
                [
446
                    RequestOptions::BODY => self::SERIALIZED_VALUE,
447
                    RequestOptions::HEADERS => [
448
                        'Content-Type' => 'application/json',
449
                        'Authorization' => 'Bearer ' . self::TOKEN
450
                    ],
451
                    RequestOptions::HTTP_ERRORS => true,
452
                    RequestOptions::QUERY => null,
453
                ]
454
            )
455
            ->willReturn(
456
                (new Response())
457
                    ->withBody(stream_for(self::API_RESPONSE))
458
            );
459
460
        $result = $this->api->lkImportSend(self::TOKEN, $request);
461
462
        $this->assertEquals(self::API_RESPONSE, $result);
463
    }
464
465
    public function testLkReceiptSend(): void
466
    {
467
        $request = new DocumentCreateRequest('document', 'MANUAL', 'signature');
468
469
        $this->serializer
470
            ->method('serialize')
471
            ->with($request)
472
            ->willReturn(self::SERIALIZED_VALUE);
473
474
        $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...
475
            ->method('request')
476
            ->with(
477
                'POST',
478
                'api/v3/lk/receipt/send',
479
                [
480
                    RequestOptions::BODY => self::SERIALIZED_VALUE,
481
                    RequestOptions::HEADERS => [
482
                        'Content-Type' => 'application/json',
483
                        'Authorization' => 'Bearer ' . self::TOKEN
484
                    ],
485
                    RequestOptions::HTTP_ERRORS => true,
486
                    RequestOptions::QUERY => null,
487
                ]
488
            )
489
            ->willReturn(
490
                (new Response())
491
                    ->withBody(stream_for(self::API_RESPONSE))
492
            );
493
494
        $result = $this->api->lkReceiptSend(self::TOKEN, $request);
495
496
        $this->assertEquals(self::API_RESPONSE, $result);
497
    }
498
499
    public function testLkDocumentsShipmentCreate(): void
500
    {
501
        $request = new DocumentCreateRequest('document', 'MANUAL', 'signature');
502
503
        $this->serializer
504
            ->method('serialize')
505
            ->with($request)
506
            ->willReturn(self::SERIALIZED_VALUE);
507
508
        $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...
509
            ->method('request')
510
            ->with(
511
                'POST',
512
                'api/v3/lk/documents/shipment/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 => null,
521
                ]
522
            )
523
            ->willReturn(
524
                (new Response())
525
                    ->withBody(stream_for(self::API_RESPONSE))
526
            );
527
528
        $result = $this->api->lkDocumentsShipmentCreate(self::TOKEN, $request);
529
530
        $this->assertEquals(self::API_RESPONSE, $result);
531
    }
532
533
    public function testLkDocumentsAcceptanceCreate(): 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())
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...
543
            ->method('request')
544
            ->with(
545
                'POST',
546
                'api/v3/lk/documents/acceptance/create',
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->lkDocumentsAcceptanceCreate(self::TOKEN, $request);
563
564
        $this->assertEquals(self::API_RESPONSE, $result);
565
    }
566
567
    public function testProductInfo(): void
568
    {
569
        $request = ['aaa', 'bbb'];
570
        $expectedResult = new ProductInfoResponse([], 0);
571
572
        $this->serializer
573
            ->method('deserialize')
574
            ->with(
575
                get_class($expectedResult),
576
                self::API_RESPONSE
577
            )
578
            ->willReturn($expectedResult);
579
580
        $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...
581
            ->method('request')
582
            ->with(
583
                'GET',
584
                'api/v3/product/info',
585
                [
586
                    RequestOptions::BODY => null,
587
                    RequestOptions::HEADERS => [
588
                        'Content-Type' => 'application/json',
589
                        'Authorization' => 'Bearer ' . self::TOKEN
590
                    ],
591
                    RequestOptions::HTTP_ERRORS => true,
592
                    RequestOptions::QUERY => [
593
                        'gtins' => implode(',', $request)
594
                    ],
595
                ]
596
            )
597
            ->willReturn(
598
                (new Response())
599
                    ->withBody(stream_for(self::API_RESPONSE))
600
            );
601
602
        $result = $this->api->productInfo(self::TOKEN, $request);
603
604
        $this->assertEquals($expectedResult, $result);
605
    }
606
}
607