1 | <?php |
||
2 | |||
3 | /** |
||
4 | * MIT License |
||
5 | * For full license information, please view the LICENSE file that was distributed with this source code. |
||
6 | */ |
||
7 | |||
8 | namespace SprykerTest\Zed\ProductOfferShipmentTypeDataImport\Communication\Plugin\DataImport; |
||
9 | |||
10 | use Codeception\Test\Unit; |
||
11 | use Generated\Shared\Transfer\DataImporterConfigurationTransfer; |
||
12 | use Generated\Shared\Transfer\DataImporterReaderConfigurationTransfer; |
||
13 | use Generated\Shared\Transfer\ProductConcreteTransfer; |
||
14 | use Generated\Shared\Transfer\ProductOfferTransfer; |
||
15 | use Generated\Shared\Transfer\ShipmentTypeTransfer; |
||
16 | use SprykerTest\Zed\ProductOfferShipmentTypeDataImport\ProductOfferShipmentTypeDataImportCommunicationTester; |
||
17 | |||
18 | /** |
||
19 | * Auto-generated group annotations |
||
20 | * |
||
21 | * @group SprykerTest |
||
22 | * @group Zed |
||
23 | * @group ProductOfferShipmentTypeDataImport |
||
24 | * @group Communication |
||
25 | * @group Plugin |
||
26 | * @group DataImport |
||
27 | * @group ProductOfferShipmentTypeDataImportPluginTest |
||
28 | * Add your own group annotations below this line |
||
29 | */ |
||
30 | class ProductOfferShipmentTypeDataImportPluginTest extends Unit |
||
31 | { |
||
32 | /** |
||
33 | * @var string |
||
34 | */ |
||
35 | protected const SHIPMENT_TYPE_KEY_1 = 'shipment_type_key_1'; |
||
36 | |||
37 | /** |
||
38 | * @var string |
||
39 | */ |
||
40 | protected const SHIPMENT_TYPE_KEY_2 = 'shipment_type_key_2'; |
||
41 | |||
42 | /** |
||
43 | * @var string |
||
44 | */ |
||
45 | protected const NOT_EXISTING_SHIPMENT_TYPE_KEY = 'not_existing_shipment_type_key'; |
||
46 | |||
47 | /** |
||
48 | * @var string |
||
49 | */ |
||
50 | protected const PRODUCT_OFFER_REFERENCE_1 = 'product_offer_reference_1'; |
||
51 | |||
52 | /** |
||
53 | * @var string |
||
54 | */ |
||
55 | protected const PRODUCT_OFFER_REFERENCE_2 = 'product_offer_reference_2'; |
||
56 | |||
57 | /** |
||
58 | * @var string |
||
59 | */ |
||
60 | protected const NOT_EXISTING_PRODUCT_OFFER_REFERENCE = 'not_existing_product_offer_reference'; |
||
61 | |||
62 | /** |
||
63 | * @uses \Spryker\Zed\ProductOfferShipmentTypeDataImport\ProductOfferShipmentTypeDataImportConfig::IMPORT_TYPE_PRODUCT_OFFER_SHIPMENT_TYPE |
||
64 | * |
||
65 | * @var string |
||
66 | */ |
||
67 | protected const IMPORT_TYPE_PRODUCT_OFFER_SHIPMENT_TYPE = 'product-offer-shipment-type'; |
||
68 | |||
69 | /** |
||
70 | * @var \SprykerTest\Zed\ProductOfferShipmentTypeDataImport\ProductOfferShipmentTypeDataImportCommunicationTester |
||
71 | */ |
||
72 | protected ProductOfferShipmentTypeDataImportCommunicationTester $tester; |
||
73 | |||
74 | /** |
||
75 | * @var \Generated\Shared\Transfer\ProductConcreteTransfer |
||
76 | */ |
||
77 | protected ProductConcreteTransfer $productConcreteTransfer; |
||
78 | |||
79 | /** |
||
80 | * @return void |
||
81 | */ |
||
82 | protected function setUp(): void |
||
83 | { |
||
84 | parent::setUp(); |
||
85 | |||
86 | $this->tester->cleanUpData(); |
||
87 | $this->productConcreteTransfer = $this->tester->haveProduct(); |
||
88 | } |
||
89 | |||
90 | /** |
||
91 | * @return void |
||
92 | */ |
||
93 | protected function tearDown(): void |
||
94 | { |
||
95 | parent::tearDown(); |
||
96 | |||
97 | $this->tester->cleanUpStaticCacheData(); |
||
98 | $this->tester->cleanUpData(); |
||
99 | } |
||
100 | |||
101 | /** |
||
102 | * @return void |
||
103 | */ |
||
104 | public function testImportImportsValidProductOfferShipmentTypeDataSet(): void |
||
105 | { |
||
106 | // Arrange |
||
107 | $shipmentTypeTransfer1 = $this->tester->haveShipmentType([ |
||
108 | ShipmentTypeTransfer::KEY => static::SHIPMENT_TYPE_KEY_1, |
||
109 | ]); |
||
110 | $shipmentTypeTransfer2 = $this->tester->haveShipmentType([ |
||
111 | ShipmentTypeTransfer::KEY => static::SHIPMENT_TYPE_KEY_2, |
||
112 | ]); |
||
113 | $this->tester->haveProductOffer([ |
||
114 | ProductOfferTransfer::PRODUCT_OFFER_REFERENCE => static::PRODUCT_OFFER_REFERENCE_1, |
||
115 | ProductOfferTransfer::CONCRETE_SKU => $this->productConcreteTransfer->getSku(), |
||
116 | ]); |
||
117 | |||
118 | $this->tester->haveProductOffer([ |
||
119 | ProductOfferTransfer::PRODUCT_OFFER_REFERENCE => static::PRODUCT_OFFER_REFERENCE_2, |
||
120 | ]); |
||
121 | |||
122 | $dataImportConfigurationTransfer = $this->createDataImporterConfigurationTransfer( |
||
123 | 'valid_data_set.csv', |
||
124 | ); |
||
125 | |||
126 | // Act |
||
127 | $dataImporterReportTransfer = $this->tester->createProductOfferShipmentTypeDataImportPlugin() |
||
128 | ->import($dataImportConfigurationTransfer); |
||
129 | |||
130 | $productOfferShipmentTypeEntitiesCount = $this->tester->getProductOfferShipmentTypeEntitiesByShipmentTypeKeysCount([ |
||
131 | $shipmentTypeTransfer1->getKey(), |
||
132 | $shipmentTypeTransfer2->getKey(), |
||
133 | ]); |
||
134 | |||
135 | // Assert |
||
136 | $this->assertTrue($dataImporterReportTransfer->getIsSuccess()); |
||
137 | $this->assertSame(4, $dataImporterReportTransfer->getImportedDataSetCount()); |
||
138 | $this->assertSame(4, $productOfferShipmentTypeEntitiesCount); |
||
139 | } |
||
140 | |||
141 | /** |
||
142 | * @group test |
||
143 | * @return void |
||
144 | */ |
||
145 | public function testImportDoesntImportDataWithAnEmptyProductOfferReference(): void |
||
146 | { |
||
147 | // Arrange |
||
148 | $shipmentTypeTransfer1 = $this->tester->haveShipmentType([ |
||
149 | ShipmentTypeTransfer::KEY => static::SHIPMENT_TYPE_KEY_1, |
||
150 | ]); |
||
151 | $shipmentTypeTransfer2 = $this->tester->haveShipmentType([ |
||
152 | ShipmentTypeTransfer::KEY => static::SHIPMENT_TYPE_KEY_2, |
||
153 | ]); |
||
154 | $this->tester->haveProductOffer([ |
||
155 | ProductOfferTransfer::PRODUCT_OFFER_REFERENCE => static::PRODUCT_OFFER_REFERENCE_1, |
||
156 | ProductOfferTransfer::CONCRETE_SKU => $this->productConcreteTransfer->getSku(), |
||
157 | ]); |
||
158 | $dataImportConfigurationTransfer = $this->createDataImporterConfigurationTransfer( |
||
159 | 'empty_product_offer_reference.csv', |
||
160 | ); |
||
161 | |||
162 | // Act |
||
163 | $dataImporterReportTransfer = $this->tester->createProductOfferShipmentTypeDataImportPlugin() |
||
164 | ->import($dataImportConfigurationTransfer); |
||
165 | |||
166 | $productOfferShipmentTypeEntitiesCount = $this->tester->getProductOfferShipmentTypeEntitiesByShipmentTypeKeysCount([ |
||
167 | $shipmentTypeTransfer1->getKey(), |
||
168 | $shipmentTypeTransfer2->getKey(), |
||
169 | ]); |
||
170 | |||
171 | // Assert |
||
172 | $this->assertFalse($dataImporterReportTransfer->getIsSuccess()); |
||
173 | $this->assertSame(2, $dataImporterReportTransfer->getExpectedImportableDataSetCount()); |
||
174 | $this->assertSame(1, $dataImporterReportTransfer->getImportedDataSetCount()); |
||
175 | $this->assertSame(1, $productOfferShipmentTypeEntitiesCount); |
||
176 | $this->assertCount(1, $dataImporterReportTransfer->getMessages()); |
||
177 | $this->assertStringContainsString( |
||
178 | 'Missing required "product_offer_reference" field.', |
||
179 | $dataImporterReportTransfer->getMessages()->getIterator()->current()->getMessage(), |
||
180 | ); |
||
181 | } |
||
182 | |||
183 | /** |
||
184 | * @return void |
||
185 | */ |
||
186 | public function testImportDoesntImportDataWithAnEmptyShipmentTypeKey(): void |
||
187 | { |
||
188 | // Arrange |
||
189 | $shipmentTypeTransfer = $this->tester->haveShipmentType([ |
||
190 | ShipmentTypeTransfer::KEY => static::SHIPMENT_TYPE_KEY_1, |
||
191 | ]); |
||
192 | $this->tester->haveProductOffer([ |
||
193 | ProductOfferTransfer::PRODUCT_OFFER_REFERENCE => static::PRODUCT_OFFER_REFERENCE_1, |
||
194 | ProductOfferTransfer::CONCRETE_SKU => $this->productConcreteTransfer->getSku(), |
||
195 | ]); |
||
196 | $this->tester->haveProductOffer([ |
||
197 | ProductOfferTransfer::PRODUCT_OFFER_REFERENCE => static::PRODUCT_OFFER_REFERENCE_2, |
||
198 | ProductOfferTransfer::CONCRETE_SKU => $this->productConcreteTransfer->getSku(), |
||
199 | ]); |
||
200 | $dataImportConfigurationTransfer = $this->createDataImporterConfigurationTransfer( |
||
201 | 'empty_shipment_type_key.csv', |
||
202 | ); |
||
203 | |||
204 | // Act |
||
205 | $dataImporterReportTransfer = $this->tester->createProductOfferShipmentTypeDataImportPlugin() |
||
206 | ->import($dataImportConfigurationTransfer); |
||
207 | |||
208 | $productOfferShipmentTypeEntitiesCount = $this->tester->getProductOfferShipmentTypeEntitiesByShipmentTypeKeysCount([ |
||
209 | $shipmentTypeTransfer->getKey(), |
||
210 | ]); |
||
211 | |||
212 | // Assert |
||
213 | $this->assertFalse($dataImporterReportTransfer->getIsSuccess()); |
||
214 | $this->assertSame(2, $dataImporterReportTransfer->getExpectedImportableDataSetCount()); |
||
215 | $this->assertSame(1, $dataImporterReportTransfer->getImportedDataSetCount()); |
||
216 | $this->assertSame(1, $productOfferShipmentTypeEntitiesCount); |
||
217 | $this->assertCount(1, $dataImporterReportTransfer->getMessages()); |
||
218 | $this->assertStringContainsString( |
||
219 | 'Missing required "shipment_type_key" field.', |
||
220 | $dataImporterReportTransfer->getMessages()->getIterator()->current()->getMessage(), |
||
221 | ); |
||
222 | } |
||
223 | |||
224 | /** |
||
225 | * @return void |
||
226 | */ |
||
227 | public function testImportDoesntImportDataWithNotExistingProductOfferReference(): void |
||
228 | { |
||
229 | // Arrange |
||
230 | $shipmentTypeTransfer1 = $this->tester->haveShipmentType([ |
||
231 | ShipmentTypeTransfer::KEY => static::SHIPMENT_TYPE_KEY_1, |
||
232 | ]); |
||
233 | $shipmentTypeTransfer2 = $this->tester->haveShipmentType([ |
||
234 | ShipmentTypeTransfer::KEY => static::SHIPMENT_TYPE_KEY_2, |
||
235 | ]); |
||
236 | |||
237 | $this->tester->haveProductOffer([ |
||
238 | ProductOfferTransfer::PRODUCT_OFFER_REFERENCE => static::PRODUCT_OFFER_REFERENCE_1, |
||
239 | ProductOfferTransfer::CONCRETE_SKU => $this->productConcreteTransfer->getSku(), |
||
240 | ]); |
||
241 | $dataImportConfigurationTransfer = $this->createDataImporterConfigurationTransfer( |
||
242 | 'not_existing_product_offer_reference.csv', |
||
243 | ); |
||
244 | |||
245 | // Act |
||
246 | $dataImporterReportTransfer = $this->tester->createProductOfferShipmentTypeDataImportPlugin() |
||
247 | ->import($dataImportConfigurationTransfer); |
||
248 | |||
249 | $productOfferShipmentTypeEntitiesCount = $this->tester->getProductOfferShipmentTypeEntitiesByShipmentTypeKeysCount([ |
||
250 | $shipmentTypeTransfer1->getKey(), |
||
251 | $shipmentTypeTransfer2->getKey(), |
||
252 | ]); |
||
253 | |||
254 | // Assert |
||
255 | $this->assertFalse($dataImporterReportTransfer->getIsSuccess()); |
||
256 | $this->assertSame(2, $dataImporterReportTransfer->getExpectedImportableDataSetCount()); |
||
257 | $this->assertSame(1, $dataImporterReportTransfer->getImportedDataSetCount()); |
||
258 | $this->assertSame(1, $productOfferShipmentTypeEntitiesCount); |
||
259 | $this->assertCount(1, $dataImporterReportTransfer->getMessages()); |
||
260 | $this->assertStringContainsString( |
||
261 | 'Could not find product offer by product offer reference "' . static::NOT_EXISTING_PRODUCT_OFFER_REFERENCE . '"', |
||
262 | $dataImporterReportTransfer->getMessages()->getIterator()->current()->getMessage(), |
||
263 | ); |
||
264 | } |
||
265 | |||
266 | /** |
||
267 | * @return void |
||
268 | */ |
||
269 | public function testImportDoesntImportDataWithNotExistingShipmentTypeKey(): void |
||
270 | { |
||
271 | // Arrange |
||
272 | $shipmentTypeTransfer1 = $this->tester->haveShipmentType([ |
||
273 | ShipmentTypeTransfer::KEY => static::SHIPMENT_TYPE_KEY_1, |
||
274 | ]); |
||
275 | $this->tester->haveProductOffer([ |
||
276 | ProductOfferTransfer::PRODUCT_OFFER_REFERENCE => static::PRODUCT_OFFER_REFERENCE_1, |
||
277 | ProductOfferTransfer::CONCRETE_SKU => $this->productConcreteTransfer->getSku(), |
||
278 | ]); |
||
279 | $this->tester->haveProductOffer([ |
||
280 | ProductOfferTransfer::PRODUCT_OFFER_REFERENCE => static::PRODUCT_OFFER_REFERENCE_2, |
||
281 | ProductOfferTransfer::CONCRETE_SKU => $this->productConcreteTransfer->getSku(), |
||
282 | ]); |
||
283 | $dataImportConfigurationTransfer = $this->createDataImporterConfigurationTransfer( |
||
284 | 'not_existing_shipment_type_key.csv', |
||
285 | ); |
||
286 | |||
287 | // Act |
||
288 | $dataImporterReportTransfer = $this->tester->createProductOfferShipmentTypeDataImportPlugin() |
||
289 | ->import($dataImportConfigurationTransfer); |
||
290 | |||
291 | $productOfferShipmentTypeEntitiesCount = $this->tester->getProductOfferShipmentTypeEntitiesByShipmentTypeKeysCount([ |
||
292 | static::NOT_EXISTING_SHIPMENT_TYPE_KEY, |
||
293 | $shipmentTypeTransfer1->getKey(), |
||
294 | ]); |
||
295 | |||
296 | // Assert |
||
297 | $this->assertFalse($dataImporterReportTransfer->getIsSuccess()); |
||
298 | $this->assertSame(2, $dataImporterReportTransfer->getExpectedImportableDataSetCount()); |
||
299 | $this->assertSame(1, $dataImporterReportTransfer->getImportedDataSetCount()); |
||
300 | $this->assertSame(1, $productOfferShipmentTypeEntitiesCount); |
||
301 | $this->assertCount(1, $dataImporterReportTransfer->getMessages()); |
||
302 | $this->assertStringContainsString( |
||
303 | 'Could not find shipment type by key "' . static::NOT_EXISTING_SHIPMENT_TYPE_KEY . '"', |
||
304 | $dataImporterReportTransfer->getMessages()->getIterator()->current()->getMessage(), |
||
305 | ); |
||
306 | } |
||
307 | |||
308 | /** |
||
309 | * @return void |
||
310 | */ |
||
311 | public function testGetImportTypeReturnsExpectedType(): void |
||
312 | { |
||
313 | // Act |
||
314 | $importType = $this->tester->createProductOfferShipmentTypeDataImportPlugin()->getImportType(); |
||
315 | |||
316 | // Assert |
||
317 | $this->assertSame(static::IMPORT_TYPE_PRODUCT_OFFER_SHIPMENT_TYPE, $importType); |
||
318 | } |
||
319 | |||
320 | /** |
||
321 | * @param string $importFileName |
||
322 | * |
||
323 | * @return \Generated\Shared\Transfer\DataImporterConfigurationTransfer |
||
324 | */ |
||
325 | protected function createDataImporterConfigurationTransfer(string $importFileName): DataImporterConfigurationTransfer |
||
326 | { |
||
327 | return (new DataImporterConfigurationTransfer()) |
||
328 | ->setReaderConfiguration( |
||
329 | (new DataImporterReaderConfigurationTransfer()) |
||
330 | ->setFileName(codecept_data_dir() . 'import/product-offer-shipment-type/' . $importFileName), |
||
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
331 | ); |
||
332 | } |
||
333 | } |
||
334 |