1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Lamoda\IsmpClient\Tests\V4; |
6
|
|
|
|
7
|
|
|
use GuzzleHttp\ClientInterface; |
8
|
|
|
use GuzzleHttp\Exception\BadResponseException; |
9
|
|
|
use GuzzleHttp\Psr7\Response; |
10
|
|
|
use GuzzleHttp\Psr7\Utils; |
11
|
|
|
use GuzzleHttp\RequestOptions; |
12
|
|
|
use Lamoda\IsmpClient\Exception\IsmpGeneralErrorException; |
13
|
|
|
use Lamoda\IsmpClient\Exception\IsmpRequestErrorException; |
14
|
|
|
use Lamoda\IsmpClient\Serializer\SerializerInterface; |
15
|
|
|
use Lamoda\IsmpClient\V3\Dto\AuthCertKeyResponse; |
16
|
|
|
use Lamoda\IsmpClient\V3\Dto\AuthCertRequest; |
17
|
|
|
use Lamoda\IsmpClient\V3\Dto\AuthCertResponse; |
18
|
|
|
use Lamoda\IsmpClient\V3\Dto\DocumentCreateRequest; |
19
|
|
|
use Lamoda\IsmpClient\V4\Dto\FacadeCisListRequest; |
20
|
|
|
use Lamoda\IsmpClient\V4\Dto\FacadeCisListResponse; |
21
|
|
|
use Lamoda\IsmpClient\V4\Dto\FacadeDocBodyResponse; |
22
|
|
|
use Lamoda\IsmpClient\V3\Dto\FacadeDocListV2Query; |
23
|
|
|
use Lamoda\IsmpClient\V3\Dto\FacadeDocListV2Response; |
24
|
|
|
use Lamoda\IsmpClient\V3\Dto\ProductInfoResponse; |
25
|
|
|
use Lamoda\IsmpClient\V3\Enum\DocumentLkType; |
26
|
|
|
use Lamoda\IsmpClient\V3\Enum\ProductGroup; |
27
|
|
|
use Lamoda\IsmpClient\V4\IsmpApi; |
28
|
|
|
use PHPUnit\Framework\MockObject\MockObject; |
29
|
|
|
use PHPUnit\Framework\TestCase; |
30
|
|
|
use Psr\Http\Message\RequestInterface; |
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
|
|
|
private 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, |
|
|
|
|
61
|
|
|
$this->serializer |
|
|
|
|
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))); |
|
|
|
|
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()) |
|
|
|
|
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(Utils::streamFor(self::API_RESPONSE)) |
114
|
|
|
); |
115
|
|
|
|
116
|
|
|
$result = $this->api->authCertKey(); |
117
|
|
|
|
118
|
|
|
$this->assertEquals($expectedResult, $result); |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* @dataProvider provideTestAuthCertData |
123
|
|
|
* @param AuthCertRequest $request |
124
|
|
|
* @param string|null $connection |
125
|
|
|
* @param AuthCertResponse $expectedResult |
126
|
|
|
*/ |
127
|
|
|
public function testAuthCert( |
128
|
|
|
AuthCertRequest $request, |
129
|
|
|
?string $connection, |
130
|
|
|
AuthCertResponse $expectedResult |
131
|
|
|
): void { |
132
|
|
|
$this->serializer |
133
|
|
|
->method('serialize') |
134
|
|
|
->with($request) |
135
|
|
|
->willReturn(self::SERIALIZED_VALUE); |
136
|
|
|
|
137
|
|
|
$this->serializer |
138
|
|
|
->method('deserialize') |
139
|
|
|
->with( |
140
|
|
|
get_class($expectedResult), |
141
|
|
|
self::API_RESPONSE |
142
|
|
|
) |
143
|
|
|
->willReturn($expectedResult); |
144
|
|
|
|
145
|
|
|
$this->client->expects($this->once()) |
|
|
|
|
146
|
|
|
->method('request') |
147
|
|
|
->with( |
148
|
|
|
'POST', |
149
|
|
|
sprintf('api/v3/auth/cert/%s', $connection), |
150
|
|
|
[ |
151
|
|
|
RequestOptions::BODY => self::SERIALIZED_VALUE, |
152
|
|
|
RequestOptions::HEADERS => [ |
153
|
|
|
'Content-Type' => 'application/json', |
154
|
|
|
], |
155
|
|
|
RequestOptions::HTTP_ERRORS => true, |
156
|
|
|
RequestOptions::QUERY => null, |
157
|
|
|
] |
158
|
|
|
) |
159
|
|
|
->willReturn( |
160
|
|
|
(new Response()) |
161
|
|
|
->withBody(Utils::streamFor(self::API_RESPONSE)) |
162
|
|
|
); |
163
|
|
|
|
164
|
|
|
$result = $this->api->authCert($request, $connection); |
165
|
|
|
|
166
|
|
|
$this->assertEquals($expectedResult, $result); |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
public function provideTestAuthCertData(): iterable |
170
|
|
|
{ |
171
|
|
|
yield 'Without connection' => [ |
172
|
|
|
$request = new AuthCertRequest(self::UUID, self::RANDOM_DATA), |
173
|
|
|
null, |
174
|
|
|
$response = new AuthCertResponse('token-value') |
175
|
|
|
]; |
176
|
|
|
|
177
|
|
|
yield 'With connection' => [ |
178
|
|
|
$request, |
179
|
|
|
'connection', |
180
|
|
|
$response |
181
|
|
|
]; |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
public function testFacadeDocListV2(): void |
185
|
|
|
{ |
186
|
|
|
$query = new FacadeDocListV2Query(); |
187
|
|
|
$query->setDocumentStatus(FacadeDocListV2Query::DOCUMENT_STATUS_CHECKED_OK); |
188
|
|
|
$query->setDateFrom(new \DateTimeImmutable('2019-01-01 11:12:13', new \DateTimeZone('UTC'))); |
189
|
|
|
$expectedResult = new FacadeDocListV2Response(0); |
190
|
|
|
|
191
|
|
|
$this->serializer |
192
|
|
|
->method('deserialize') |
193
|
|
|
->with( |
194
|
|
|
get_class($expectedResult), |
195
|
|
|
self::API_RESPONSE |
196
|
|
|
) |
197
|
|
|
->willReturn($expectedResult); |
198
|
|
|
|
199
|
|
|
$this->client->expects($this->once()) |
|
|
|
|
200
|
|
|
->method('request') |
201
|
|
|
->with( |
202
|
|
|
'GET', |
203
|
|
|
'api/v3/facade/doc/listV2', |
204
|
|
|
[ |
205
|
|
|
RequestOptions::BODY => null, |
206
|
|
|
RequestOptions::HEADERS => [ |
207
|
|
|
'Content-Type' => 'application/json', |
208
|
|
|
'Authorization' => 'Bearer ' . self::TOKEN, |
209
|
|
|
], |
210
|
|
|
RequestOptions::HTTP_ERRORS => true, |
211
|
|
|
RequestOptions::QUERY => [ |
212
|
|
|
'documentStatus' => FacadeDocListV2Query::DOCUMENT_STATUS_CHECKED_OK, |
213
|
|
|
'dateFrom' => '2019-01-01T11:12:13.000+00:00', |
214
|
|
|
'limit' => $query->getLimit(), |
215
|
|
|
], |
216
|
|
|
] |
217
|
|
|
) |
218
|
|
|
->willReturn( |
219
|
|
|
(new Response()) |
220
|
|
|
->withBody(Utils::streamFor(self::API_RESPONSE)) |
221
|
|
|
); |
222
|
|
|
|
223
|
|
|
$result = $this->api->facadeDocListV2(self::TOKEN, $query); |
224
|
|
|
|
225
|
|
|
$this->assertEquals($expectedResult, $result); |
226
|
|
|
} |
227
|
|
|
|
228
|
|
|
/** |
229
|
|
|
* @dataProvider provideTestFacadeDocBodyData |
230
|
|
|
*/ |
231
|
|
|
public function testFacadeDocBody( |
232
|
|
|
?int $limitOption, |
233
|
|
|
?string $orderColumnOption, |
234
|
|
|
?string $orderedColumnValueOption, |
235
|
|
|
?string $pageDirOption, |
236
|
|
|
array $expectedOptions |
237
|
|
|
): void { |
238
|
|
|
$expectedResult = new FacadeDocBodyResponse(self::IDENTITY, '2019-01-01', 'IMPORT', 'NEW', 'Tester', 'Test'); |
239
|
|
|
$expectedResult->setCisTotal('100'); |
240
|
|
|
|
241
|
|
|
$this->serializer |
242
|
|
|
->method('deserialize') |
243
|
|
|
->with( |
244
|
|
|
get_class($expectedResult), |
245
|
|
|
self::API_RESPONSE |
246
|
|
|
) |
247
|
|
|
->willReturn($expectedResult); |
248
|
|
|
|
249
|
|
|
$this->client->expects($this->once()) |
|
|
|
|
250
|
|
|
->method('request') |
251
|
|
|
->with( |
252
|
|
|
'GET', |
253
|
|
|
sprintf('api/v4/facade/doc/%s/body', self::IDENTITY), |
254
|
|
|
$expectedOptions |
255
|
|
|
) |
256
|
|
|
->willReturn( |
257
|
|
|
(new Response()) |
258
|
|
|
->withBody(Utils::streamFor(self::API_RESPONSE)) |
259
|
|
|
); |
260
|
|
|
|
261
|
|
|
$result = $this->api->facadeDocBody( |
262
|
|
|
self::TOKEN, |
263
|
|
|
self::IDENTITY, |
264
|
|
|
$limitOption, |
265
|
|
|
$orderColumnOption, |
266
|
|
|
$orderedColumnValueOption, |
267
|
|
|
$pageDirOption |
268
|
|
|
); |
269
|
|
|
|
270
|
|
|
$this->assertEquals($expectedResult, $result); |
271
|
|
|
} |
272
|
|
|
|
273
|
|
|
public function provideTestFacadeDocBodyData(): iterable |
274
|
|
|
{ |
275
|
|
|
yield 'all nullable parameters' => [ |
276
|
|
|
null, |
277
|
|
|
null, |
278
|
|
|
null, |
279
|
|
|
null, |
280
|
|
|
[ |
281
|
|
|
RequestOptions::BODY => null, |
282
|
|
|
RequestOptions::HEADERS => [ |
283
|
|
|
'Content-Type' => 'application/json', |
284
|
|
|
'Authorization' => 'Bearer ' . self::TOKEN, |
285
|
|
|
], |
286
|
|
|
RequestOptions::HTTP_ERRORS => true, |
287
|
|
|
RequestOptions::QUERY => null, |
288
|
|
|
], |
289
|
|
|
]; |
290
|
|
|
|
291
|
|
|
yield 'only limit' => [ |
292
|
|
|
1000, |
293
|
|
|
null, |
294
|
|
|
null, |
295
|
|
|
null, |
296
|
|
|
[ |
297
|
|
|
RequestOptions::BODY => null, |
298
|
|
|
RequestOptions::HEADERS => [ |
299
|
|
|
'Content-Type' => 'application/json', |
300
|
|
|
'Authorization' => 'Bearer ' . self::TOKEN, |
301
|
|
|
], |
302
|
|
|
RequestOptions::HTTP_ERRORS => true, |
303
|
|
|
RequestOptions::QUERY => [ |
304
|
|
|
'limit' => 1000, |
305
|
|
|
], |
306
|
|
|
], |
307
|
|
|
]; |
308
|
|
|
|
309
|
|
|
yield 'only order column option' => [ |
310
|
|
|
null, |
311
|
|
|
'order-column', |
312
|
|
|
null, |
313
|
|
|
null, |
314
|
|
|
[ |
315
|
|
|
RequestOptions::BODY => null, |
316
|
|
|
RequestOptions::HEADERS => [ |
317
|
|
|
'Content-Type' => 'application/json', |
318
|
|
|
'Authorization' => 'Bearer ' . self::TOKEN, |
319
|
|
|
], |
320
|
|
|
RequestOptions::HTTP_ERRORS => true, |
321
|
|
|
RequestOptions::QUERY => [ |
322
|
|
|
'orderColumn' => 'order-column', |
323
|
|
|
], |
324
|
|
|
], |
325
|
|
|
]; |
326
|
|
|
|
327
|
|
|
yield 'only ordered column value option' => [ |
328
|
|
|
null, |
329
|
|
|
null, |
330
|
|
|
'ordered-column-value', |
331
|
|
|
null, |
332
|
|
|
[ |
333
|
|
|
RequestOptions::BODY => null, |
334
|
|
|
RequestOptions::HEADERS => [ |
335
|
|
|
'Content-Type' => 'application/json', |
336
|
|
|
'Authorization' => 'Bearer ' . self::TOKEN, |
337
|
|
|
], |
338
|
|
|
RequestOptions::HTTP_ERRORS => true, |
339
|
|
|
RequestOptions::QUERY => [ |
340
|
|
|
'orderedColumnValue' => 'ordered-column-value', |
341
|
|
|
], |
342
|
|
|
], |
343
|
|
|
]; |
344
|
|
|
|
345
|
|
|
yield 'only page dir option' => [ |
346
|
|
|
null, |
347
|
|
|
null, |
348
|
|
|
null, |
349
|
|
|
'page-dir', |
350
|
|
|
[ |
351
|
|
|
RequestOptions::BODY => null, |
352
|
|
|
RequestOptions::HEADERS => [ |
353
|
|
|
'Content-Type' => 'application/json', |
354
|
|
|
'Authorization' => 'Bearer ' . self::TOKEN, |
355
|
|
|
], |
356
|
|
|
RequestOptions::HTTP_ERRORS => true, |
357
|
|
|
RequestOptions::QUERY => [ |
358
|
|
|
'pageDir' => 'page-dir' |
359
|
|
|
], |
360
|
|
|
], |
361
|
|
|
]; |
362
|
|
|
|
363
|
|
|
|
364
|
|
|
yield 'all parameters' => [ |
365
|
|
|
1000, |
366
|
|
|
'order-column', |
367
|
|
|
'ordered-column-value', |
368
|
|
|
'page-dir', |
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
|
|
|
'limit' => 1000, |
378
|
|
|
'orderColumn' => 'order-column', |
379
|
|
|
'orderedColumnValue' => 'ordered-column-value', |
380
|
|
|
'pageDir' => 'page-dir', |
381
|
|
|
], |
382
|
|
|
], |
383
|
|
|
]; |
384
|
|
|
} |
385
|
|
|
|
386
|
|
|
public function testFacadeCisList(): void |
387
|
|
|
{ |
388
|
|
|
$request = new FacadeCisListRequest(self::IDENTITY); |
389
|
|
|
$expectedResult = new FacadeCisListResponse(); |
390
|
|
|
$requestBody = '{"cises": [' . self::IDENTITY . ']}'; |
391
|
|
|
|
392
|
|
|
$this->serializer |
393
|
|
|
->method('serialize') |
394
|
|
|
->with($request) |
395
|
|
|
->willReturn($requestBody); |
396
|
|
|
|
397
|
|
|
$this->serializer |
398
|
|
|
->method('deserialize') |
399
|
|
|
->with( |
400
|
|
|
get_class($expectedResult), |
401
|
|
|
self::API_RESPONSE |
402
|
|
|
) |
403
|
|
|
->willReturn($expectedResult); |
404
|
|
|
|
405
|
|
|
$this->client->expects($this->once()) |
|
|
|
|
406
|
|
|
->method('request') |
407
|
|
|
->with( |
408
|
|
|
'POST', |
409
|
|
|
'api/v4/facade/cis/cis_list', |
410
|
|
|
[ |
411
|
|
|
RequestOptions::BODY => $requestBody, |
412
|
|
|
RequestOptions::HEADERS => [ |
413
|
|
|
'Content-Type' => 'application/json', |
414
|
|
|
'Authorization' => 'Bearer ' . self::TOKEN, |
415
|
|
|
], |
416
|
|
|
RequestOptions::HTTP_ERRORS => true, |
417
|
|
|
RequestOptions::QUERY => null, |
418
|
|
|
] |
419
|
|
|
) |
420
|
|
|
->willReturn( |
421
|
|
|
(new Response()) |
422
|
|
|
->withBody(Utils::streamFor(self::API_RESPONSE)) |
423
|
|
|
); |
424
|
|
|
|
425
|
|
|
$result = $this->api->facadeCisList(self::TOKEN, $request); |
426
|
|
|
|
427
|
|
|
$this->assertEquals($expectedResult, $result); |
428
|
|
|
} |
429
|
|
|
|
430
|
|
|
public function testLkDocumentsCreate(): void |
431
|
|
|
{ |
432
|
|
|
$request = new DocumentCreateRequest( |
433
|
|
|
'document', |
434
|
|
|
'MANUAL', |
435
|
|
|
'signature', |
436
|
|
|
ProductGroup::SHOES, |
437
|
|
|
DocumentLkType::LP_INTRODUCE_GOODS |
438
|
|
|
); |
439
|
|
|
|
440
|
|
|
$this->serializer |
441
|
|
|
->method('serialize') |
442
|
|
|
->with($request) |
443
|
|
|
->willReturn(self::SERIALIZED_VALUE); |
444
|
|
|
|
445
|
|
|
$this->client->expects($this->once()) |
|
|
|
|
446
|
|
|
->method('request') |
447
|
|
|
->with( |
448
|
|
|
'POST', |
449
|
|
|
'api/v3/lk/documents/create', |
450
|
|
|
[ |
451
|
|
|
RequestOptions::BODY => self::SERIALIZED_VALUE, |
452
|
|
|
RequestOptions::HEADERS => [ |
453
|
|
|
'Content-Type' => 'application/json', |
454
|
|
|
'Authorization' => 'Bearer ' . self::TOKEN, |
455
|
|
|
], |
456
|
|
|
RequestOptions::HTTP_ERRORS => true, |
457
|
|
|
RequestOptions::QUERY => ['pg' => ProductGroup::SHOES], |
458
|
|
|
] |
459
|
|
|
) |
460
|
|
|
->willReturn( |
461
|
|
|
(new Response()) |
462
|
|
|
->withBody(Utils::streamFor(self::API_RESPONSE)) |
463
|
|
|
); |
464
|
|
|
|
465
|
|
|
$result = $this->api->lkDocumentsCreate(self::TOKEN, $request); |
466
|
|
|
|
467
|
|
|
$this->assertEquals(self::API_RESPONSE, $result); |
468
|
|
|
} |
469
|
|
|
|
470
|
|
|
public function testProductInfo(): void |
471
|
|
|
{ |
472
|
|
|
$request = ['aaa', 'bbb']; |
473
|
|
|
$expectedResult = new ProductInfoResponse([], 0); |
474
|
|
|
|
475
|
|
|
$this->serializer |
476
|
|
|
->method('deserialize') |
477
|
|
|
->with( |
478
|
|
|
get_class($expectedResult), |
479
|
|
|
self::API_RESPONSE |
480
|
|
|
) |
481
|
|
|
->willReturn($expectedResult); |
482
|
|
|
|
483
|
|
|
$this->client->expects($this->once()) |
|
|
|
|
484
|
|
|
->method('request') |
485
|
|
|
->with( |
486
|
|
|
'GET', |
487
|
|
|
'api/v3/product/info', |
488
|
|
|
[ |
489
|
|
|
RequestOptions::BODY => null, |
490
|
|
|
RequestOptions::HEADERS => [ |
491
|
|
|
'Content-Type' => 'application/json', |
492
|
|
|
'Authorization' => 'Bearer ' . self::TOKEN, |
493
|
|
|
], |
494
|
|
|
RequestOptions::HTTP_ERRORS => true, |
495
|
|
|
RequestOptions::QUERY => [ |
496
|
|
|
'gtins' => implode(',', $request), |
497
|
|
|
], |
498
|
|
|
] |
499
|
|
|
) |
500
|
|
|
->willReturn( |
501
|
|
|
(new Response()) |
502
|
|
|
->withBody(Utils::streamFor(self::API_RESPONSE)) |
503
|
|
|
); |
504
|
|
|
|
505
|
|
|
$result = $this->api->productInfo(self::TOKEN, $request); |
506
|
|
|
|
507
|
|
|
$this->assertEquals($expectedResult, $result); |
508
|
|
|
} |
509
|
|
|
} |
510
|
|
|
|
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: