Completed
Pull Request — master (#10)
by
unknown
02:19
created

SymfonySerializerAdapterTest::testSerialize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
c 0
b 0
f 0
rs 10
cc 1
nc 1
nop 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Lamoda\IsmpClient\Tests\Impl\Serializer;
6
7
use Lamoda\IsmpClient\Impl\Serializer\SymfonySerializerAdapterFactory;
8
use Lamoda\IsmpClient\Serializer\SerializerInterface;
9
use Lamoda\IsmpClient\V3\Dto\AuthCertRequest;
10
use Lamoda\IsmpClient\V3\Dto\AuthCertResponse;
11
use Lamoda\IsmpClient\V3\Dto\FacadeDocListV2ItemResponse;
12
use Lamoda\IsmpClient\V3\Dto\FacadeDocListV2Response;
13
use Lamoda\IsmpClient\V3\Dto\FacadeMarkedProductsCertDoc;
14
use Lamoda\IsmpClient\V3\Dto\FacadeMarkedProductsResponse;
15
use PHPUnit\Framework\TestCase;
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
                AuthCertResponse::class,
46
                json_encode(
47
                    [
48
                        'token' => 'test_token',
49
                    ]
50
                ),
51
                new AuthCertResponse(
52
                    'test_token'
53
                ),
54
            ],
55
            [
56
                FacadeDocListV2Response::class,
57
                json_encode(
58
                    [
59
                        'total' => 25,
60
                        'results' => [
61
                            [
62
                                'number' => 'b917dfb0-523d-41e0-9e64-e8bf0052c5bd',
63
                                'docDate' => '2019-01-18T06:45:35.630Z',
64
                                'receivedAt' => '2019-01-19T06:45:35.630Z',
65
                                'type' => 'LP_INTRODUCE_GOODS',
66
                                'status' => 'CHECKED_OK',
67
                                'senderName' => 'test',
68
                            ],
69
                        ],
70
                    ]
71
                ),
72
                new FacadeDocListV2Response(
73
                    25,
74
                    [
75
                        new FacadeDocListV2ItemResponse(
76
                            'b917dfb0-523d-41e0-9e64-e8bf0052c5bd',
77
                            '2019-01-18T06:45:35.630Z',
78
                            '2019-01-19T06:45:35.630Z',
79
                            'LP_INTRODUCE_GOODS',
80
                            'CHECKED_OK',
81
                            'test'
82
                        ),
83
                    ]
84
                ),
85
            ],
86
            [
87
                FacadeMarkedProductsResponse::class,
88
                json_encode(
89
                    [
90
                        'cis' => 'eb852349-647f-468f-bb90-d26a4d975a88',
91
                        'gtin' => '04630034070029',
92
                        'tnVed' => '6401100000',
93
                        'productName' => 'Product name',
94
                        'ownerName' => 'Owner name',
95
                        'ownerInn' => '0000000000',
96
                        'producerName' => 'Producer name',
97
                        'producerInn' => '0000000000',
98
                        'status' => 'INTRODUCED',
99
                        'emissionDate' => '2019-01-18T08:14:40.344Z',
100
                        'emissionType' => 'LOCAL',
101
                        'statusExt' => 'WAIT_SHIPMENT',
102
                        'withdrawReason' => 'RETAIL',
103
                        'name' => 'Name',
104
                        'brand' => 'Brand',
105
                        'model' => 'Model',
106
                        'certDoc' => [
107
                            'type' => 'CONFORMITY_CERT',
108
                            'number' => '122',
109
                            'date' => '2019-01-02T20:00:00.000Z',
110
                        ],
111
                        'country' => 'РОССИЙСКАЯ ФЕДЕРАЦИЯ',
112
                        'productTypeDesc' => 'ТАПОЧКИ',
113
                        'color' => 'белый',
114
                        'materialDown' => 'Текстиль',
115
                        'productSize' => '52',
116
                        'materialUpper' => 'Текстиль',
117
                        'materialLining' => 'Текстиль',
118
                        'packageType' => 'BOX',
119
                        'productType' => '310000022',
120
                    ]
121
                ),
122
                new FacadeMarkedProductsResponse(
123
                    'eb852349-647f-468f-bb90-d26a4d975a88',
124
                    '04630034070029',
125
                    '6401100000',
126
                    'Product name',
127
                    'Owner name',
128
                    '0000000000',
129
                    'Producer name',
130
                    '0000000000',
131
                    'INTRODUCED',
132
                    '2019-01-18T08:14:40.344Z',
133
                    'LOCAL',
134
                    'WAIT_SHIPMENT',
135
                    'RETAIL',
136
                    'Name',
137
                    'Brand',
138
                    'Model',
139
                    new FacadeMarkedProductsCertDoc(
140
                        'CONFORMITY_CERT',
141
                        '122',
142
                        '2019-01-02T20:00:00.000Z'
143
                    ),
144
                    'РОССИЙСКАЯ ФЕДЕРАЦИЯ',
145
                    'ТАПОЧКИ',
146
                    'белый',
147
                    'Текстиль',
148
                    '52',
149
                    'Текстиль',
150
                    'Текстиль',
151
                    'BOX',
152
                    '310000022'
153
                )
154
            ],
155
        ];
156
    }
157
158
    /**
159
     * @dataProvider dataSerialize
160
     */
161
    public function testSerialize(object $data, string $expected): void
162
    {
163
        $result = $this->serializer->serialize($data);
164
165
        $this->assertJsonStringEqualsJsonString($expected, $result);
166
    }
167
168
    public function dataSerialize(): array
169
    {
170
        return [
171
            [
172
                new AuthCertRequest(
173
                    'uuid_value',
174
                    'data_value'
175
                ),
176
                <<<JSON
177
{
178
  "uuid": "uuid_value",
179
  "data": "data_value"
180
}
181
JSON
182
                ,
183
            ],
184
        ];
185
    }
186
}
187