1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Lamoda\OmsClient\Tests\Impl\Serializer; |
6
|
|
|
|
7
|
|
|
use Lamoda\OmsClient\Impl\Serializer\SymfonySerializerAdapterFactory; |
8
|
|
|
use Lamoda\OmsClient\Serializer\SerializerInterface; |
9
|
|
|
use Lamoda\OmsClient\V2\Dto\CreateOrderForEmissionICRequestLight; |
10
|
|
|
use Lamoda\OmsClient\V2\Dto\GetICsFromOrderResponse; |
11
|
|
|
use Lamoda\OmsClient\V2\Dto\OrderProductLight; |
12
|
|
|
use PHPUnit\Framework\TestCase; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @covers \Lamoda\OmsClient\Impl\Serializer\SymfonySerializerAdapter |
16
|
|
|
*/ |
17
|
|
|
final class SymfonySerializerAdapterTest extends TestCase |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* @var SerializerInterface |
21
|
|
|
*/ |
22
|
|
|
private $serializer; |
23
|
|
|
|
24
|
|
|
protected function setUp(): void |
25
|
|
|
{ |
26
|
|
|
parent::setUp(); |
27
|
|
|
|
28
|
|
|
$this->serializer = SymfonySerializerAdapterFactory::create(); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @dataProvider dataDeserialize |
33
|
|
|
*/ |
34
|
|
|
public function testDeserialize(string $class, string $data, object $expected): void |
35
|
|
|
{ |
36
|
|
|
$result = $this->serializer->deserialize($class, $data); |
37
|
|
|
|
38
|
|
|
$this->assertEquals($expected, $result); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function dataDeserialize(): array |
42
|
|
|
{ |
43
|
|
|
return [ |
44
|
|
|
[ |
45
|
|
|
GetICsFromOrderResponse::class, |
46
|
|
|
'{ "omsId" : "CDF12109-10D3-11E6-8B6F-0050569977A1", "codes" : ["010460165303004621\\u003drxDV3M\\u001d93VXQI"], "blockId" : "20"}', |
47
|
|
|
new GetICsFromOrderResponse( |
48
|
|
|
'CDF12109-10D3-11E6-8B6F-0050569977A1', |
49
|
|
|
[ |
50
|
|
|
"010460165303004621\x3drxDV3M\x1d93VXQI", |
51
|
|
|
], |
52
|
|
|
'20' |
53
|
|
|
), |
54
|
|
|
], |
55
|
|
|
]; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @dataProvider dataSerialize |
60
|
|
|
*/ |
61
|
|
|
public function testSerialize(object $data, string $expected): void |
62
|
|
|
{ |
63
|
|
|
$result = $this->serializer->serialize($data); |
64
|
|
|
|
65
|
|
|
$this->assertJsonStringEqualsJsonString($expected, $result); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public function dataSerialize(): array |
69
|
|
|
{ |
70
|
|
|
return [ |
71
|
|
|
[ |
72
|
|
|
new CreateOrderForEmissionICRequestLight( |
73
|
|
|
'Ivan Ivanov', |
74
|
|
|
CreateOrderForEmissionICRequestLight::RELEASE_METHOD_TYPE_IMPORT, |
75
|
|
|
CreateOrderForEmissionICRequestLight::CREATE_METHOD_TYPE_SELF_MADE, |
76
|
|
|
'a1f83800-7329-4749-97f0-bbd831aaa9d1', |
77
|
|
|
'1234', |
78
|
|
|
new \DateTimeImmutable('2019-09-28'), |
79
|
|
|
[ |
80
|
|
|
new OrderProductLight( |
81
|
|
|
'0461234567', |
82
|
|
|
12, |
83
|
|
|
OrderProductLight::SERIAL_NUMBER_TYPE_OPERATOR, |
84
|
|
|
2 |
85
|
|
|
), |
86
|
|
|
] |
87
|
|
|
), |
88
|
|
|
<<<JSON |
89
|
|
|
{ |
90
|
|
|
"contactPerson": "Ivan Ivanov", |
91
|
|
|
"releaseMethodType": "IMPORT", |
92
|
|
|
"createMethodType": "SELF_MADE", |
93
|
|
|
"productionOrderId": "a1f83800-7329-4749-97f0-bbd831aaa9d1", |
94
|
|
|
"contractNumber": "1234", |
95
|
|
|
"contractDate": "2019-09-28", |
96
|
|
|
"products": [ |
97
|
|
|
{ |
98
|
|
|
"gtin": "0461234567", |
99
|
|
|
"quantity": 12, |
100
|
|
|
"serialNumberType": "OPERATOR", |
101
|
|
|
"templateId": 2, |
102
|
|
|
"serialNumbers": null |
103
|
|
|
} |
104
|
|
|
] |
105
|
|
|
} |
106
|
|
|
JSON |
107
|
|
|
], |
108
|
|
|
]; |
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
|