Completed
Push — master ( 2bb4c5...9b3355 )
by Agaletskiy
01:40
created

IsmpApiTest::testExceptionWithHttpCode()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
c 0
b 0
f 0
rs 9.9666
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\IsmpApi;
27
use PHPUnit\Framework\MockObject\MockObject;
28
use PHPUnit\Framework\TestCase;
29
use Psr\Http\Message\RequestInterface;
30
use function GuzzleHttp\Psr7\stream_for;
31
32
final class IsmpApiTest extends TestCase
33
{
34
    private const TOKEN = '0a893bdc-3127-4f3f-939e-f423d08d9bd6';
35
    private const UUID = '81497c0c-17ef-42a1-b1d1-d769dac7441c';
36
    private const RANDOM_DATA = '2b212c99-9955-45c7-8594-9d3aa59eae04';
37
    private const SERIALIZED_VALUE = '{"test:"value"}';
38
    private const API_RESPONSE = 'stub_api_response';
39
    const IDENTITY = 'eb852349-647f-468f-bb90-d26a4d975a88';
40
41
    /**
42
     * @var ClientInterface|MockObject
43
     */
44
    private $client;
45
    /**
46
     * @var SerializerInterface|MockObject
47
     */
48
    private $serializer;
49
    /**
50
     * @var IsmpApi
51
     */
52
    private $api;
53
54
    protected function setUp(): void
55
    {
56
        $this->client = $this->createMock(ClientInterface::class);
57
        $this->serializer = $this->createMock(SerializerInterface::class);
58
59
        $this->api = new IsmpApi(
60
            $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...
61
            $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...
62
        );
63
    }
64
65
    public function testExceptionWithHttpCode(): void
66
    {
67
        $this->client
68
            ->method('request')
69
            ->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...
70
71
        $this->expectException(IsmpRequestErrorException::class);
72
        $this->api->authCertKey();
73
    }
74
75
    public function testGeneralException(): void
76
    {
77
        $this->client
78
            ->method('request')
79
            ->willThrowException(new \RuntimeException());
80
81
        $this->expectException(IsmpGeneralErrorException::class);
82
        $this->api->authCertKey();
83
    }
84
85
    public function testAuthCertKey(): void
86
    {
87
        $expectedResult = new AuthCertKeyResponse(self::UUID, self::RANDOM_DATA);
88
89
        $this->serializer
90
            ->method('deserialize')
91
            ->with(
92
                get_class($expectedResult),
93
                self::API_RESPONSE
94
            )
95
            ->willReturn($expectedResult);
96
97
        $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...
98
            ->method('request')
99
            ->with(
100
                'GET',
101
                'api/v3/auth/cert/key',
102
                [
103
                    RequestOptions::BODY => null,
104
                    RequestOptions::HEADERS => [
105
                        'Content-Type' => 'application/json',
106
                    ],
107
                    RequestOptions::HTTP_ERRORS => true,
108
                    RequestOptions::QUERY => null,
109
                ]
110
            )
111
            ->willReturn(
112
                (new Response())
113
                    ->withBody(stream_for(self::API_RESPONSE))
114
            );
115
116
        $result = $this->api->authCertKey();
117
118
        $this->assertEquals($expectedResult, $result);
119
    }
120
121
    public function testAuthCert(): void
122
    {
123
        $request = new AuthCertRequest(self::UUID, self::RANDOM_DATA);
124
        $expectedResult = new AuthCertResponse('token-value');
125
126
        $this->serializer
127
            ->method('serialize')
128
            ->with($request)
129
            ->willReturn(self::SERIALIZED_VALUE);
130
131
        $this->serializer
132
            ->method('deserialize')
133
            ->with(
134
                get_class($expectedResult),
135
                self::API_RESPONSE
136
            )
137
            ->willReturn($expectedResult);
138
139
        $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...
140
            ->method('request')
141
            ->with(
142
                'POST',
143
                'api/v3/auth/cert/',
144
                [
145
                    RequestOptions::BODY => self::SERIALIZED_VALUE,
146
                    RequestOptions::HEADERS => [
147
                        'Content-Type' => 'application/json',
148
                    ],
149
                    RequestOptions::HTTP_ERRORS => true,
150
                    RequestOptions::QUERY => null,
151
                ]
152
            )
153
            ->willReturn(
154
                (new Response())
155
                    ->withBody(stream_for(self::API_RESPONSE))
156
            );
157
158
        $result = $this->api->authCert($request);
159
160
        $this->assertEquals($expectedResult, $result);
161
    }
162
163
    public function testFacadeOrder(): void
164
    {
165
        $request = new FacadeOrderRequest('document', 'MANUAL', 'signature');
166
        $expectedResult = new FacadeOrderResponse('orderId', 'status');
167
168
        $this->serializer
169
            ->method('serialize')
170
            ->with($request)
171
            ->willReturn(self::SERIALIZED_VALUE);
172
173
        $this->serializer
174
            ->method('deserialize')
175
            ->with(
176
                get_class($expectedResult),
177
                self::API_RESPONSE
178
            )
179
            ->willReturn($expectedResult);
180
181
        $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...
182
            ->method('request')
183
            ->with(
184
                'POST',
185
                'api/v3/facade/order/',
186
                [
187
                    RequestOptions::BODY => self::SERIALIZED_VALUE,
188
                    RequestOptions::HEADERS => [
189
                        'Content-Type' => 'application/json',
190
                        'Authorization' => 'Bearer ' . self::TOKEN
191
                    ],
192
                    RequestOptions::HTTP_ERRORS => true,
193
                    RequestOptions::QUERY => null,
194
                ]
195
            )
196
            ->willReturn(
197
                (new Response())
198
                    ->withBody(stream_for(self::API_RESPONSE))
199
            );
200
201
        $result = $this->api->facadeOrder(self::TOKEN, $request);
202
203
        $this->assertEquals($expectedResult, $result);
204
    }
205
206
    public function testFacadeOrderDetails(): void
207
    {
208
        $expectedResult = new FacadeOrderDetailsResponse(self::IDENTITY, 'MANUAL', 123456);
209
210
        $this->serializer
211
            ->method('deserialize')
212
            ->with(
213
                get_class($expectedResult),
214
                self::API_RESPONSE
215
            )
216
            ->willReturn($expectedResult);
217
218
        $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...
219
            ->method('request')
220
            ->with(
221
                'GET',
222
                sprintf('api/v3/facade/order/%s/details', self::IDENTITY),
223
                [
224
                    RequestOptions::BODY => null,
225
                    RequestOptions::HEADERS => [
226
                        'Content-Type' => 'application/json',
227
                        'Authorization' => 'Bearer ' . self::TOKEN
228
                    ],
229
                    RequestOptions::HTTP_ERRORS => true,
230
                    RequestOptions::QUERY => null,
231
                ]
232
            )
233
            ->willReturn(
234
                (new Response())
235
                    ->withBody(stream_for(self::API_RESPONSE))
236
            );
237
238
        $result = $this->api->facadeOrderDetails(self::TOKEN, self::IDENTITY);
239
240
        $this->assertEquals($expectedResult, $result);
241
    }
242
243
    public function testFacadeDocListV2(): void
244
    {
245
        $query = new FacadeDocListV2Query();
246
        $query->setDocumentStatus(FacadeDocListV2Query::DOCUMENT_STATUS_CHECKED_OK);
247
        $query->setDateFrom(new \DateTimeImmutable('2019-01-01 11:12:13'));
248
        $expectedResult = new FacadeDocListV2Response();
249
250
        $this->serializer
251
            ->method('deserialize')
252
            ->with(
253
                get_class($expectedResult),
254
                self::API_RESPONSE
255
            )
256
            ->willReturn($expectedResult);
257
258
        $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...
259
            ->method('request')
260
            ->with(
261
                'GET',
262
                'api/v3/facade/doc/listV2',
263
                [
264
                    RequestOptions::BODY => null,
265
                    RequestOptions::HEADERS => [
266
                        'Content-Type' => 'application/json',
267
                        'Authorization' => 'Bearer ' . self::TOKEN
268
                    ],
269
                    RequestOptions::HTTP_ERRORS => true,
270
                    RequestOptions::QUERY => [
271
                        'documentStatus' => FacadeDocListV2Query::DOCUMENT_STATUS_CHECKED_OK,
272
                        'dateFrom' => '2019-01-01T11:12:13.000Z',
273
                        'limit' => $query->getLimit()
274
                    ],
275
                ]
276
            )
277
            ->willReturn(
278
                (new Response())
279
                    ->withBody(stream_for(self::API_RESPONSE))
280
            );
281
282
        $result = $this->api->facadeDocListV2(self::TOKEN, $query);
283
284
        $this->assertEquals($expectedResult, $result);
285
    }
286
287
    public function testFacadeDocBody(): void
288
    {
289
        $expectedResult = new FacadeDocBodyResponse(self::IDENTITY, '2019-01-01', 'IMPORT', 'NEW', 'Tester', 'Test');
290
291
        $this->serializer
292
            ->method('deserialize')
293
            ->with(
294
                get_class($expectedResult),
295
                self::API_RESPONSE
296
            )
297
            ->willReturn($expectedResult);
298
299
        $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...
300
            ->method('request')
301
            ->with(
302
                'GET',
303
                sprintf('api/v3/facade/doc/%s/body', self::IDENTITY),
304
                [
305
                    RequestOptions::BODY => null,
306
                    RequestOptions::HEADERS => [
307
                        'Content-Type' => 'application/json',
308
                        'Authorization' => 'Bearer ' . self::TOKEN
309
                    ],
310
                    RequestOptions::HTTP_ERRORS => true,
311
                    RequestOptions::QUERY => null,
312
                ]
313
            )
314
            ->willReturn(
315
                (new Response())
316
                    ->withBody(stream_for(self::API_RESPONSE))
317
            );
318
319
        $result = $this->api->facadeDocBody(self::TOKEN, self::IDENTITY);
320
321
        $this->assertEquals($expectedResult, $result);
322
    }
323
324
    public function testFacadeCisList(): void
325
    {
326
        $expectedResult = new FacadeCisListResponse();
327
328
        $this->serializer
329
            ->method('deserialize')
330
            ->with(
331
                get_class($expectedResult),
332
                self::API_RESPONSE
333
            )
334
            ->willReturn($expectedResult);
335
336
        $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...
337
            ->method('request')
338
            ->with(
339
                'GET',
340
                'api/v3/facade/cis/cis_list',
341
                [
342
                    RequestOptions::BODY => null,
343
                    RequestOptions::HEADERS => [
344
                        'Content-Type' => 'application/json',
345
                        'Authorization' => 'Bearer ' . self::TOKEN
346
                    ],
347
                    RequestOptions::HTTP_ERRORS => true,
348
                    RequestOptions::QUERY => [
349
                        'cis' => self::IDENTITY
350
                    ],
351
                ]
352
            )
353
            ->willReturn(
354
                (new Response())
355
                    ->withBody(stream_for(self::API_RESPONSE))
356
            );
357
358
        $result = $this->api->facadeCisList(self::TOKEN, self::IDENTITY);
359
360
        $this->assertEquals($expectedResult, $result);
361
    }
362
363
    public function testLkImportSend(): void
364
    {
365
        $request = new DocumentCreateRequest('document', 'MANUAL', 'signature');
366
367
        $this->serializer
368
            ->method('serialize')
369
            ->with($request)
370
            ->willReturn(self::SERIALIZED_VALUE);
371
372
        $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...
373
            ->method('request')
374
            ->with(
375
                'POST',
376
                'api/v3/lk/import/send',
377
                [
378
                    RequestOptions::BODY => self::SERIALIZED_VALUE,
379
                    RequestOptions::HEADERS => [
380
                        'Content-Type' => 'application/json',
381
                        'Authorization' => 'Bearer ' . self::TOKEN
382
                    ],
383
                    RequestOptions::HTTP_ERRORS => true,
384
                    RequestOptions::QUERY => null,
385
                ]
386
            )
387
            ->willReturn(
388
                (new Response())
389
                    ->withBody(stream_for(self::API_RESPONSE))
390
            );
391
392
        $result = $this->api->lkImportSend(self::TOKEN, $request);
393
394
        $this->assertEquals(self::API_RESPONSE, $result);
395
    }
396
397
    public function testLkDocumentsShipmentCreate(): void
398
    {
399
        $request = new DocumentCreateRequest('document', 'MANUAL', 'signature');
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/shipment/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 => null,
419
                ]
420
            )
421
            ->willReturn(
422
                (new Response())
423
                    ->withBody(stream_for(self::API_RESPONSE))
424
            );
425
426
        $result = $this->api->lkDocumentsShipmentCreate(self::TOKEN, $request);
427
428
        $this->assertEquals(self::API_RESPONSE, $result);
429
    }
430
431
    public function testLkDocumentsAcceptanceCreate(): 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/documents/acceptance/create',
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->lkDocumentsAcceptanceCreate(self::TOKEN, $request);
461
462
        $this->assertEquals(self::API_RESPONSE, $result);
463
    }
464
465
    public function testProductInfo(): void
466
    {
467
        $request = ['aaa', 'bbb'];
468
        $expectedResult = new ProductInfoResponse([], 0);
469
470
        $this->serializer
471
            ->method('deserialize')
472
            ->with(
473
                get_class($expectedResult),
474
                self::API_RESPONSE
475
            )
476
            ->willReturn($expectedResult);
477
478
        $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...
479
            ->method('request')
480
            ->with(
481
                'GET',
482
                'api/v3/product/info',
483
                [
484
                    RequestOptions::BODY => null,
485
                    RequestOptions::HEADERS => [
486
                        'Content-Type' => 'application/json',
487
                        'Authorization' => 'Bearer ' . self::TOKEN
488
                    ],
489
                    RequestOptions::HTTP_ERRORS => true,
490
                    RequestOptions::QUERY => [
491
                        'gtins' => implode(',', $request)
492
                    ],
493
                ]
494
            )
495
            ->willReturn(
496
                (new Response())
497
                    ->withBody(stream_for(self::API_RESPONSE))
498
            );
499
500
        $result = $this->api->productInfo(self::TOKEN, $request);
501
502
        $this->assertEquals($expectedResult, $result);
503
    }
504
}
505