Issues (3641)

Facade/RemovePriceProductScheduleListTest.php (4 issues)

1
<?php
2
3
/**
4
 * Copyright © 2016-present Spryker Systems GmbH. All rights reserved.
5
 * Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
6
 */
7
8
namespace SprykerTest\Zed\PriceProductSchedule\Business\Facade;
9
10
use Codeception\Test\Unit;
11
use DateTime;
12
use Generated\Shared\Transfer\CurrencyTransfer;
13
use Generated\Shared\Transfer\MoneyValueTransfer;
14
use Generated\Shared\Transfer\PriceProductScheduleListTransfer;
15
use Generated\Shared\Transfer\PriceProductScheduleTransfer;
16
use Generated\Shared\Transfer\PriceProductTransfer;
17
use Generated\Shared\Transfer\PriceTypeTransfer;
18
use Generated\Shared\Transfer\StoreTransfer;
19
use Spryker\Zed\PriceProductSchedule\Business\PriceProductSchedule\Applier\AbstractProductPriceProductScheduleApplier;
20
use Spryker\Zed\PriceProductSchedule\Business\PriceProductSchedule\Applier\ConcreteProductPriceProductScheduleApplier;
21
use Spryker\Zed\PriceProductSchedule\Business\PriceProductScheduleBusinessFactory;
22
use Spryker\Zed\PriceProductSchedule\Business\PriceProductScheduleFacadeInterface;
23
use Spryker\Zed\PriceProductSchedule\Dependency\Facade\PriceProductScheduleToPriceProductFacadeBridge;
24
use Spryker\Zed\PriceProductSchedule\Dependency\Facade\PriceProductScheduleToStoreFacadeBridge;
25
use Spryker\Zed\PriceProductSchedule\Persistence\PriceProductScheduleEntityManager;
26
use Spryker\Zed\PriceProductSchedule\Persistence\PriceProductScheduleRepository;
27
use Spryker\Zed\PriceProductSchedule\PriceProductScheduleConfig;
28
29
/**
30
 * Auto-generated group annotations
31
 *
32
 * @group SprykerTest
33
 * @group Zed
34
 * @group PriceProductSchedule
35
 * @group Business
36
 * @group Facade
37
 * @group RemovePriceProductScheduleListTest
38
 * Add your own group annotations below this line
39
 */
40
class RemovePriceProductScheduleListTest extends Unit
41
{
42
    /**
43
     * @var string
44
     */
45
    protected const STORE_NAME_DE = 'DE';
46
47
    /**
48
     * @var \SprykerTest\Zed\PriceProductSchedule\PriceProductScheduleBusinessTester
49
     */
50
    protected $tester;
51
52
    /**
53
     * @return void
54
     */
55
    public function setUp(): void
56
    {
57
        parent::setUp();
58
        $this->tester->ensureDatabaseTableIsEmpty();
59
    }
60
61
    /**
62
     * @return void
63
     */
64
    public function testRemovePriceProductScheduleListWithActiveAbstractPricesShouldExecuteApply(): void
65
    {
66
        // Assign
67
        $productConcreteTransfer = $this->tester->haveProduct();
68
        $defaultPriceTypeTransfer = $this->tester->havePriceType();
69
        $storeTransfer = $this->tester->haveStore([StoreTransfer::NAME => static::STORE_NAME_DE]);
70
71
        $currencyTransfer = $this->tester->haveCurrencyTransfer([CurrencyTransfer::CODE => 'test1']);
72
73
        $this->tester->havePriceProduct([
74
            PriceProductTransfer::SKU_PRODUCT_ABSTRACT => $productConcreteTransfer->getAbstractSku(),
75
            PriceProductTransfer::PRICE_TYPE => $defaultPriceTypeTransfer,
76
            PriceProductTransfer::MONEY_VALUE => [
77
                MoneyValueTransfer::NET_AMOUNT => 100,
78
                MoneyValueTransfer::GROSS_AMOUNT => 100,
79
                MoneyValueTransfer::CURRENCY => $currencyTransfer,
80
            ],
81
        ]);
82
83
        $fallbackPriceTypeTransfer = $this->tester->havePriceType();
84
85
        $this->tester->havePriceProduct([
86
            PriceProductTransfer::SKU_PRODUCT_ABSTRACT => $productConcreteTransfer->getAbstractSku(),
87
            PriceProductTransfer::PRICE_TYPE => $fallbackPriceTypeTransfer,
88
            PriceProductTransfer::MONEY_VALUE => [
89
                MoneyValueTransfer::NET_AMOUNT => 200,
90
                MoneyValueTransfer::GROSS_AMOUNT => 200,
91
                MoneyValueTransfer::CURRENCY => $currencyTransfer,
92
            ],
93
        ]);
94
        $priceProductScheduleList = $this->tester->havePriceProductScheduleList([
95
            PriceProductScheduleListTransfer::IS_ACTIVE => true,
96
        ]);
97
98
        $this->tester->havePriceProductSchedule([
99
            PriceProductScheduleTransfer::ACTIVE_FROM => (new DateTime('-4 days')),
100
            PriceProductScheduleTransfer::ACTIVE_TO => (new DateTime('+1 hour')),
101
            PriceProductScheduleTransfer::IS_CURRENT => true,
102
            PriceProductScheduleTransfer::PRICE_PRODUCT_SCHEDULE_LIST => $priceProductScheduleList,
103
            PriceProductScheduleTransfer::PRICE_PRODUCT => [
104
                PriceProductTransfer::ID_PRODUCT_ABSTRACT => $productConcreteTransfer->getFkProductAbstract(),
105
                PriceProductTransfer::PRICE_TYPE => [
106
                    PriceTypeTransfer::NAME => $defaultPriceTypeTransfer->getName(),
107
                    PriceTypeTransfer::ID_PRICE_TYPE => $defaultPriceTypeTransfer->getIdPriceType(),
108
                ],
109
                PriceProductTransfer::MONEY_VALUE => [
110
                    MoneyValueTransfer::FK_STORE => $storeTransfer->getIdStore(),
111
                    MoneyValueTransfer::FK_CURRENCY => $currencyTransfer->getIdCurrency(),
112
                    MoneyValueTransfer::CURRENCY => $currencyTransfer,
113
                    MoneyValueTransfer::NET_AMOUNT => 100,
114
                    MoneyValueTransfer::GROSS_AMOUNT => 100,
115
                ],
116
            ],
117
        ]);
118
119
        $this->tester->havePriceProductSchedule([
120
            PriceProductScheduleTransfer::ACTIVE_FROM => (new DateTime('-4 days')),
121
            PriceProductScheduleTransfer::ACTIVE_TO => (new DateTime('+1 hour')),
122
            PriceProductScheduleTransfer::IS_CURRENT => false,
123
            PriceProductScheduleTransfer::PRICE_PRODUCT_SCHEDULE_LIST => $priceProductScheduleList,
124
            PriceProductScheduleTransfer::PRICE_PRODUCT => [
125
                PriceProductTransfer::ID_PRODUCT_ABSTRACT => $productConcreteTransfer->getFkProductAbstract(),
126
                PriceProductTransfer::PRICE_TYPE => [
127
                    PriceTypeTransfer::NAME => $defaultPriceTypeTransfer->getName(),
128
                    PriceTypeTransfer::ID_PRICE_TYPE => $defaultPriceTypeTransfer->getIdPriceType(),
129
                ],
130
                PriceProductTransfer::MONEY_VALUE => [
131
                    MoneyValueTransfer::FK_STORE => $storeTransfer->getIdStore(),
132
                    MoneyValueTransfer::FK_CURRENCY => $currencyTransfer->getIdCurrency(),
133
                    MoneyValueTransfer::CURRENCY => $currencyTransfer,
134
                    MoneyValueTransfer::NET_AMOUNT => 100,
135
                    MoneyValueTransfer::GROSS_AMOUNT => 100,
136
                ],
137
            ],
138
        ]);
139
140
        /** @var \Spryker\Zed\PriceProductSchedule\Business\PriceProductSchedule\Applier\AbstractProductPriceProductScheduleApplier|\PHPUnit\Framework\MockObject\MockObject $applierMock */
141
        $applierMock = $this->getMockBuilder(AbstractProductPriceProductScheduleApplier::class)
142
            ->disableOriginalConstructor()
143
            ->setMethods(['applyScheduledPrices'])
144
            ->getMock();
145
146
        $applierMock->expects($this->once())->method('applyScheduledPrices');
0 ignored issues
show
The method expects() does not exist on Spryker\Zed\PriceProduct...eProductScheduleApplier. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

146
        $applierMock->/** @scrutinizer ignore-call */ 
147
                      expects($this->once())->method('applyScheduledPrices');

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
147
        $priceProductScheduleFacade = $this->getFacadeMockForAbstractPrices($applierMock);
148
149
        // Act
150
        $priceProductScheduleFacade
151
            ->removePriceProductScheduleList($priceProductScheduleList->getIdPriceProductScheduleList());
152
153
        $priceProductScheduleListCollection = $this->tester
154
            ->getPriceProductScheduleListQuery()
155
            ->filterByIdPriceProductScheduleList($priceProductScheduleList->getIdPriceProductScheduleList())
156
            ->find()
157
            ->getData();
158
159
        // Assert
160
        $this->assertCount(
161
            0,
162
            $priceProductScheduleListCollection,
163
            'Count of scheduled price lists does not match expected value',
164
        );
165
    }
166
167
    /**
168
     * @return void
169
     */
170
    public function testRemovePriceProductScheduleListWithActiveConcretePricesShouldExecuteApply(): void
171
    {
172
        // Assign
173
        $productConcreteTransfer = $this->tester->haveProduct();
174
        $defaultPriceTypeTransfer = $this->tester->havePriceType();
175
        $storeTransfer = $this->tester->haveStore([StoreTransfer::NAME => static::STORE_NAME_DE]);
176
177
        $currencyTransfer = $this->tester->haveCurrencyTransfer([CurrencyTransfer::CODE => 'test1']);
178
179
        $this->tester->havePriceProduct([
180
            PriceProductTransfer::SKU_PRODUCT_ABSTRACT => $productConcreteTransfer->getAbstractSku(),
181
            PriceProductTransfer::SKU_PRODUCT => $productConcreteTransfer->getSku(),
182
            PriceProductTransfer::PRICE_TYPE => $defaultPriceTypeTransfer,
183
            PriceProductTransfer::MONEY_VALUE => [
184
                MoneyValueTransfer::NET_AMOUNT => 100,
185
                MoneyValueTransfer::GROSS_AMOUNT => 100,
186
                MoneyValueTransfer::CURRENCY => $currencyTransfer,
187
            ],
188
        ]);
189
190
        $fallbackPriceTypeTransfer = $this->tester->havePriceType();
191
192
        $this->tester->havePriceProduct([
193
            PriceProductTransfer::SKU_PRODUCT_ABSTRACT => $productConcreteTransfer->getAbstractSku(),
194
            PriceProductTransfer::SKU_PRODUCT => $productConcreteTransfer->getSku(),
195
            PriceProductTransfer::PRICE_TYPE => $fallbackPriceTypeTransfer,
196
            PriceProductTransfer::MONEY_VALUE => [
197
                MoneyValueTransfer::NET_AMOUNT => 200,
198
                MoneyValueTransfer::GROSS_AMOUNT => 200,
199
                MoneyValueTransfer::CURRENCY => $currencyTransfer,
200
            ],
201
        ]);
202
        $priceProductScheduleList = $this->tester->havePriceProductScheduleList([
203
            PriceProductScheduleListTransfer::IS_ACTIVE => true,
204
        ]);
205
206
        $this->tester->havePriceProductSchedule([
207
            PriceProductScheduleTransfer::ACTIVE_FROM => (new DateTime('-4 days')),
208
            PriceProductScheduleTransfer::ACTIVE_TO => (new DateTime('+1 hour')),
209
            PriceProductScheduleTransfer::IS_CURRENT => true,
210
            PriceProductScheduleTransfer::PRICE_PRODUCT_SCHEDULE_LIST => $priceProductScheduleList,
211
            PriceProductScheduleTransfer::PRICE_PRODUCT => [
212
                PriceProductTransfer::ID_PRODUCT => $productConcreteTransfer->getIdProductConcrete(),
213
                PriceProductTransfer::PRICE_TYPE => [
214
                    PriceTypeTransfer::NAME => $defaultPriceTypeTransfer->getName(),
215
                    PriceTypeTransfer::ID_PRICE_TYPE => $defaultPriceTypeTransfer->getIdPriceType(),
216
                ],
217
                PriceProductTransfer::MONEY_VALUE => [
218
                    MoneyValueTransfer::FK_STORE => $storeTransfer->getIdStore(),
219
                    MoneyValueTransfer::FK_CURRENCY => $currencyTransfer->getIdCurrency(),
220
                    MoneyValueTransfer::CURRENCY => $currencyTransfer,
221
                    MoneyValueTransfer::NET_AMOUNT => 100,
222
                    MoneyValueTransfer::GROSS_AMOUNT => 100,
223
                ],
224
            ],
225
        ]);
226
227
        $this->tester->havePriceProductSchedule([
228
            PriceProductScheduleTransfer::ACTIVE_FROM => (new DateTime('-4 days')),
229
            PriceProductScheduleTransfer::ACTIVE_TO => (new DateTime('+1 hour')),
230
            PriceProductScheduleTransfer::IS_CURRENT => false,
231
            PriceProductScheduleTransfer::PRICE_PRODUCT_SCHEDULE_LIST => $priceProductScheduleList,
232
            PriceProductScheduleTransfer::PRICE_PRODUCT => [
233
                PriceProductTransfer::ID_PRODUCT => $productConcreteTransfer->getIdProductConcrete(),
234
                PriceProductTransfer::PRICE_TYPE => [
235
                    PriceTypeTransfer::NAME => $defaultPriceTypeTransfer->getName(),
236
                    PriceTypeTransfer::ID_PRICE_TYPE => $defaultPriceTypeTransfer->getIdPriceType(),
237
                ],
238
                PriceProductTransfer::MONEY_VALUE => [
239
                    MoneyValueTransfer::FK_STORE => $storeTransfer->getIdStore(),
240
                    MoneyValueTransfer::FK_CURRENCY => $currencyTransfer->getIdCurrency(),
241
                    MoneyValueTransfer::CURRENCY => $currencyTransfer,
242
                    MoneyValueTransfer::NET_AMOUNT => 100,
243
                    MoneyValueTransfer::GROSS_AMOUNT => 100,
244
                ],
245
            ],
246
        ]);
247
248
        $applierMock = $this->getMockBuilder(ConcreteProductPriceProductScheduleApplier::class)
249
            ->disableOriginalConstructor()
250
            ->setMethods(['applyScheduledPrices'])
251
            ->getMock();
252
253
        $applierMock->expects($this->once())->method('applyScheduledPrices');
254
        $priceProductScheduleFacade = $this->getFacadeMockForConcretePrices($applierMock);
255
256
        // Act
257
        $priceProductScheduleFacade
258
            ->removePriceProductScheduleList($priceProductScheduleList->getIdPriceProductScheduleList());
259
260
        $priceProductScheduleListCollection = $this->tester
261
            ->getPriceProductScheduleListQuery()
262
            ->filterByIdPriceProductScheduleList($priceProductScheduleList->getIdPriceProductScheduleList())
263
            ->find()
264
            ->getData();
265
266
        // Assert
267
        $this->assertCount(
268
            0,
269
            $priceProductScheduleListCollection,
270
            'Count of scheduled price lists does not match expected value',
271
        );
272
    }
273
274
    /**
275
     * @return void
276
     */
277
    public function testRemovePriceProductScheduleListInactiveListWithActiveConcretePricesShouldExecuteApply(): void
278
    {
279
        // Assign
280
        $productConcreteTransfer = $this->tester->haveProduct();
281
        $defaultPriceTypeTransfer = $this->tester->havePriceType();
282
        $storeTransfer = $this->tester->haveStore([StoreTransfer::NAME => static::STORE_NAME_DE]);
283
284
        $currencyTransfer = $this->tester->haveCurrencyTransfer([CurrencyTransfer::CODE => 'test1']);
285
286
        $this->tester->havePriceProduct([
287
            PriceProductTransfer::SKU_PRODUCT_ABSTRACT => $productConcreteTransfer->getAbstractSku(),
288
            PriceProductTransfer::SKU_PRODUCT => $productConcreteTransfer->getSku(),
289
            PriceProductTransfer::PRICE_TYPE => $defaultPriceTypeTransfer,
290
            PriceProductTransfer::MONEY_VALUE => [
291
                MoneyValueTransfer::NET_AMOUNT => 100,
292
                MoneyValueTransfer::GROSS_AMOUNT => 100,
293
                MoneyValueTransfer::CURRENCY => $currencyTransfer,
294
            ],
295
        ]);
296
297
        $fallbackPriceTypeTransfer = $this->tester->havePriceType();
298
299
        $this->tester->havePriceProduct([
300
            PriceProductTransfer::SKU_PRODUCT_ABSTRACT => $productConcreteTransfer->getAbstractSku(),
301
            PriceProductTransfer::SKU_PRODUCT => $productConcreteTransfer->getSku(),
302
            PriceProductTransfer::PRICE_TYPE => $fallbackPriceTypeTransfer,
303
            PriceProductTransfer::MONEY_VALUE => [
304
                MoneyValueTransfer::NET_AMOUNT => 200,
305
                MoneyValueTransfer::GROSS_AMOUNT => 200,
306
                MoneyValueTransfer::CURRENCY => $currencyTransfer,
307
            ],
308
        ]);
309
        $priceProductScheduleList = $this->tester->havePriceProductScheduleList([
310
            PriceProductScheduleListTransfer::IS_ACTIVE => false,
311
        ]);
312
313
        $this->tester->havePriceProductSchedule([
314
            PriceProductScheduleTransfer::ACTIVE_FROM => (new DateTime('-4 days')),
315
            PriceProductScheduleTransfer::ACTIVE_TO => (new DateTime('+1 hour')),
316
            PriceProductScheduleTransfer::IS_CURRENT => true,
317
            PriceProductScheduleTransfer::PRICE_PRODUCT_SCHEDULE_LIST => $priceProductScheduleList,
318
            PriceProductScheduleTransfer::PRICE_PRODUCT => [
319
                PriceProductTransfer::ID_PRODUCT => $productConcreteTransfer->getIdProductConcrete(),
320
                PriceProductTransfer::PRICE_TYPE => [
321
                    PriceTypeTransfer::NAME => $defaultPriceTypeTransfer->getName(),
322
                    PriceTypeTransfer::ID_PRICE_TYPE => $defaultPriceTypeTransfer->getIdPriceType(),
323
                ],
324
                PriceProductTransfer::MONEY_VALUE => [
325
                    MoneyValueTransfer::FK_STORE => $storeTransfer->getIdStore(),
326
                    MoneyValueTransfer::FK_CURRENCY => $currencyTransfer->getIdCurrency(),
327
                    MoneyValueTransfer::CURRENCY => $currencyTransfer,
328
                    MoneyValueTransfer::NET_AMOUNT => 100,
329
                    MoneyValueTransfer::GROSS_AMOUNT => 100,
330
                ],
331
            ],
332
        ]);
333
334
        $this->tester->havePriceProductSchedule([
335
            PriceProductScheduleTransfer::ACTIVE_FROM => (new DateTime('-4 days')),
336
            PriceProductScheduleTransfer::ACTIVE_TO => (new DateTime('+1 hour')),
337
            PriceProductScheduleTransfer::IS_CURRENT => false,
338
            PriceProductScheduleTransfer::PRICE_PRODUCT_SCHEDULE_LIST => $priceProductScheduleList,
339
            PriceProductScheduleTransfer::PRICE_PRODUCT => [
340
                PriceProductTransfer::ID_PRODUCT => $productConcreteTransfer->getIdProductConcrete(),
341
                PriceProductTransfer::PRICE_TYPE => [
342
                    PriceTypeTransfer::NAME => $defaultPriceTypeTransfer->getName(),
343
                    PriceTypeTransfer::ID_PRICE_TYPE => $defaultPriceTypeTransfer->getIdPriceType(),
344
                ],
345
                PriceProductTransfer::MONEY_VALUE => [
346
                    MoneyValueTransfer::FK_STORE => $storeTransfer->getIdStore(),
347
                    MoneyValueTransfer::FK_CURRENCY => $currencyTransfer->getIdCurrency(),
348
                    MoneyValueTransfer::CURRENCY => $currencyTransfer,
349
                    MoneyValueTransfer::NET_AMOUNT => 100,
350
                    MoneyValueTransfer::GROSS_AMOUNT => 100,
351
                ],
352
            ],
353
        ]);
354
355
        $applierMock = $this->getMockBuilder(ConcreteProductPriceProductScheduleApplier::class)
356
            ->disableOriginalConstructor()
357
            ->setMethods(['applyScheduledPrices'])
358
            ->getMock();
359
360
        $applierMock->expects($this->once())->method('applyScheduledPrices');
361
        $priceProductScheduleFacade = $this->getFacadeMockForConcretePrices($applierMock);
362
363
        // Act
364
        $priceProductScheduleFacade
365
            ->removePriceProductScheduleList($priceProductScheduleList->getIdPriceProductScheduleList());
366
367
        $priceProductScheduleListCollection = $this->tester
368
            ->getPriceProductScheduleListQuery()
369
            ->filterByIdPriceProductScheduleList($priceProductScheduleList->getIdPriceProductScheduleList())
370
            ->find()
371
            ->getData();
372
373
        // Assert
374
        $this->assertCount(
375
            0,
376
            $priceProductScheduleListCollection,
377
            'Count of scheduled price lists does not match expected value',
378
        );
379
    }
380
381
    /**
382
     * @return void
383
     */
384
    public function testRemovePriceProductScheduleListWithInActiveAbstractPricesShouldNotExecuteApply(): void
385
    {
386
        // Assign
387
        $productConcreteTransfer = $this->tester->haveProduct();
388
        $defaultPriceTypeTransfer = $this->tester->havePriceType();
389
        $storeTransfer = $this->tester->haveStore([StoreTransfer::NAME => static::STORE_NAME_DE]);
390
391
        $currencyTransfer = $this->tester->haveCurrencyTransfer([CurrencyTransfer::CODE => 'test1']);
392
393
        $this->tester->havePriceProduct([
394
            PriceProductTransfer::SKU_PRODUCT_ABSTRACT => $productConcreteTransfer->getAbstractSku(),
395
            PriceProductTransfer::PRICE_TYPE => $defaultPriceTypeTransfer,
396
            PriceProductTransfer::MONEY_VALUE => [
397
                MoneyValueTransfer::NET_AMOUNT => 100,
398
                MoneyValueTransfer::GROSS_AMOUNT => 100,
399
                MoneyValueTransfer::CURRENCY => $currencyTransfer,
400
            ],
401
        ]);
402
403
        $fallbackPriceTypeTransfer = $this->tester->havePriceType();
404
405
        $this->tester->havePriceProduct([
406
            PriceProductTransfer::SKU_PRODUCT_ABSTRACT => $productConcreteTransfer->getAbstractSku(),
407
            PriceProductTransfer::PRICE_TYPE => $fallbackPriceTypeTransfer,
408
            PriceProductTransfer::MONEY_VALUE => [
409
                MoneyValueTransfer::NET_AMOUNT => 200,
410
                MoneyValueTransfer::GROSS_AMOUNT => 200,
411
                MoneyValueTransfer::CURRENCY => $currencyTransfer,
412
            ],
413
        ]);
414
        $priceProductScheduleList = $this->tester->havePriceProductScheduleList([
415
            PriceProductScheduleListTransfer::IS_ACTIVE => true,
416
        ]);
417
418
        $this->tester->havePriceProductSchedule([
419
            PriceProductScheduleTransfer::ACTIVE_FROM => (new DateTime('-4 days')),
420
            PriceProductScheduleTransfer::ACTIVE_TO => (new DateTime('+1 hour')),
421
            PriceProductScheduleTransfer::IS_CURRENT => false,
422
            PriceProductScheduleTransfer::PRICE_PRODUCT_SCHEDULE_LIST => $priceProductScheduleList,
423
            PriceProductScheduleTransfer::PRICE_PRODUCT => [
424
                PriceProductTransfer::ID_PRODUCT_ABSTRACT => $productConcreteTransfer->getFkProductAbstract(),
425
                PriceProductTransfer::PRICE_TYPE => [
426
                    PriceTypeTransfer::NAME => $defaultPriceTypeTransfer->getName(),
427
                    PriceTypeTransfer::ID_PRICE_TYPE => $defaultPriceTypeTransfer->getIdPriceType(),
428
                ],
429
                PriceProductTransfer::MONEY_VALUE => [
430
                    MoneyValueTransfer::FK_STORE => $storeTransfer->getIdStore(),
431
                    MoneyValueTransfer::FK_CURRENCY => $currencyTransfer->getIdCurrency(),
432
                    MoneyValueTransfer::CURRENCY => $currencyTransfer,
433
                    MoneyValueTransfer::NET_AMOUNT => 100,
434
                    MoneyValueTransfer::GROSS_AMOUNT => 100,
435
                ],
436
            ],
437
        ]);
438
439
        $this->tester->havePriceProductSchedule([
440
            PriceProductScheduleTransfer::ACTIVE_FROM => (new DateTime('-4 days')),
441
            PriceProductScheduleTransfer::ACTIVE_TO => (new DateTime('+1 hour')),
442
            PriceProductScheduleTransfer::IS_CURRENT => false,
443
            PriceProductScheduleTransfer::PRICE_PRODUCT_SCHEDULE_LIST => $priceProductScheduleList,
444
            PriceProductScheduleTransfer::PRICE_PRODUCT => [
445
                PriceProductTransfer::ID_PRODUCT_ABSTRACT => $productConcreteTransfer->getFkProductAbstract(),
446
                PriceProductTransfer::PRICE_TYPE => [
447
                    PriceTypeTransfer::NAME => $defaultPriceTypeTransfer->getName(),
448
                    PriceTypeTransfer::ID_PRICE_TYPE => $defaultPriceTypeTransfer->getIdPriceType(),
449
                ],
450
                PriceProductTransfer::MONEY_VALUE => [
451
                    MoneyValueTransfer::FK_STORE => $storeTransfer->getIdStore(),
452
                    MoneyValueTransfer::FK_CURRENCY => $currencyTransfer->getIdCurrency(),
453
                    MoneyValueTransfer::CURRENCY => $currencyTransfer,
454
                    MoneyValueTransfer::NET_AMOUNT => 100,
455
                    MoneyValueTransfer::GROSS_AMOUNT => 100,
456
                ],
457
            ],
458
        ]);
459
460
        $applierMock = $this->getMockBuilder(AbstractProductPriceProductScheduleApplier::class)
461
            ->disableOriginalConstructor()
462
            ->setMethods(['applyScheduledPrices'])
463
            ->getMock();
464
465
        $applierMock->expects($this->never())->method('applyScheduledPrices');
466
        $priceProductScheduleFacade = $this->getFacadeMockForAbstractPrices($applierMock);
467
468
        // Act
469
        $priceProductScheduleFacade
470
            ->removePriceProductScheduleList($priceProductScheduleList->getIdPriceProductScheduleList());
471
472
        $priceProductScheduleListCollection = $this->tester
473
            ->getPriceProductScheduleListQuery()
474
            ->filterByIdPriceProductScheduleList($priceProductScheduleList->getIdPriceProductScheduleList())
475
            ->find()
476
            ->getData();
477
478
        // Assert
479
        $this->assertCount(
480
            0,
481
            $priceProductScheduleListCollection,
482
            'Count of scheduled price lists does not match expected value',
483
        );
484
    }
485
486
    /**
487
     * @return void
488
     */
489
    public function testRemovePriceProductScheduleListWithInActiveConcretePricesShouldNotExecuteApply(): void
490
    {
491
        // Assign
492
        $productConcreteTransfer = $this->tester->haveProduct();
493
        $defaultPriceTypeTransfer = $this->tester->havePriceType();
494
        $storeTransfer = $this->tester->haveStore([StoreTransfer::NAME => static::STORE_NAME_DE]);
495
496
        $currencyTransfer = $this->tester->haveCurrencyTransfer([CurrencyTransfer::CODE => 'test1']);
497
498
        $this->tester->havePriceProduct([
499
            PriceProductTransfer::SKU_PRODUCT_ABSTRACT => $productConcreteTransfer->getAbstractSku(),
500
            PriceProductTransfer::SKU_PRODUCT => $productConcreteTransfer->getSku(),
501
            PriceProductTransfer::PRICE_TYPE => $defaultPriceTypeTransfer,
502
            PriceProductTransfer::MONEY_VALUE => [
503
                MoneyValueTransfer::NET_AMOUNT => 100,
504
                MoneyValueTransfer::GROSS_AMOUNT => 100,
505
                MoneyValueTransfer::CURRENCY => $currencyTransfer,
506
            ],
507
        ]);
508
509
        $fallbackPriceTypeTransfer = $this->tester->havePriceType();
510
511
        $this->tester->havePriceProduct([
512
            PriceProductTransfer::SKU_PRODUCT_ABSTRACT => $productConcreteTransfer->getAbstractSku(),
513
            PriceProductTransfer::SKU_PRODUCT => $productConcreteTransfer->getSku(),
514
            PriceProductTransfer::PRICE_TYPE => $fallbackPriceTypeTransfer,
515
            PriceProductTransfer::MONEY_VALUE => [
516
                MoneyValueTransfer::NET_AMOUNT => 200,
517
                MoneyValueTransfer::GROSS_AMOUNT => 200,
518
                MoneyValueTransfer::CURRENCY => $currencyTransfer,
519
            ],
520
        ]);
521
        $priceProductScheduleList = $this->tester->havePriceProductScheduleList([
522
            PriceProductScheduleListTransfer::IS_ACTIVE => true,
523
        ]);
524
525
        $this->tester->havePriceProductSchedule([
526
            PriceProductScheduleTransfer::ACTIVE_FROM => (new DateTime('-4 days')),
527
            PriceProductScheduleTransfer::ACTIVE_TO => (new DateTime('+1 hour')),
528
            PriceProductScheduleTransfer::IS_CURRENT => false,
529
            PriceProductScheduleTransfer::PRICE_PRODUCT_SCHEDULE_LIST => $priceProductScheduleList,
530
            PriceProductScheduleTransfer::PRICE_PRODUCT => [
531
                PriceProductTransfer::ID_PRODUCT => $productConcreteTransfer->getIdProductConcrete(),
532
                PriceProductTransfer::PRICE_TYPE => [
533
                    PriceTypeTransfer::NAME => $defaultPriceTypeTransfer->getName(),
534
                    PriceTypeTransfer::ID_PRICE_TYPE => $defaultPriceTypeTransfer->getIdPriceType(),
535
                ],
536
                PriceProductTransfer::MONEY_VALUE => [
537
                    MoneyValueTransfer::FK_STORE => $storeTransfer->getIdStore(),
538
                    MoneyValueTransfer::FK_CURRENCY => $currencyTransfer->getIdCurrency(),
539
                    MoneyValueTransfer::CURRENCY => $currencyTransfer,
540
                    MoneyValueTransfer::NET_AMOUNT => 100,
541
                    MoneyValueTransfer::GROSS_AMOUNT => 100,
542
                ],
543
            ],
544
        ]);
545
546
        $this->tester->havePriceProductSchedule([
547
            PriceProductScheduleTransfer::ACTIVE_FROM => (new DateTime('-4 days')),
548
            PriceProductScheduleTransfer::ACTIVE_TO => (new DateTime('+1 hour')),
549
            PriceProductScheduleTransfer::IS_CURRENT => false,
550
            PriceProductScheduleTransfer::PRICE_PRODUCT_SCHEDULE_LIST => $priceProductScheduleList,
551
            PriceProductScheduleTransfer::PRICE_PRODUCT => [
552
                PriceProductTransfer::ID_PRODUCT => $productConcreteTransfer->getIdProductConcrete(),
553
                PriceProductTransfer::PRICE_TYPE => [
554
                    PriceTypeTransfer::NAME => $defaultPriceTypeTransfer->getName(),
555
                    PriceTypeTransfer::ID_PRICE_TYPE => $defaultPriceTypeTransfer->getIdPriceType(),
556
                ],
557
                PriceProductTransfer::MONEY_VALUE => [
558
                    MoneyValueTransfer::FK_STORE => $storeTransfer->getIdStore(),
559
                    MoneyValueTransfer::FK_CURRENCY => $currencyTransfer->getIdCurrency(),
560
                    MoneyValueTransfer::CURRENCY => $currencyTransfer,
561
                    MoneyValueTransfer::NET_AMOUNT => 100,
562
                    MoneyValueTransfer::GROSS_AMOUNT => 100,
563
                ],
564
            ],
565
        ]);
566
567
        $applierMock = $this->getMockBuilder(ConcreteProductPriceProductScheduleApplier::class)
568
            ->disableOriginalConstructor()
569
            ->setMethods(['applyScheduledPrices'])
570
            ->getMock();
571
572
        $applierMock->expects($this->never())->method('applyScheduledPrices');
573
        $priceProductScheduleFacade = $this->getFacadeMockForConcretePrices($applierMock);
574
575
        // Act
576
        $priceProductScheduleFacade
577
            ->removePriceProductScheduleList($priceProductScheduleList->getIdPriceProductScheduleList());
578
579
        $priceProductScheduleListCollection = $this->tester
580
            ->getPriceProductScheduleListQuery()
581
            ->filterByIdPriceProductScheduleList($priceProductScheduleList->getIdPriceProductScheduleList())
582
            ->find()
583
            ->getData();
584
585
        // Assert
586
        $this->assertCount(
587
            0,
588
            $priceProductScheduleListCollection,
589
            'Count of scheduled price lists does not match expected value',
590
        );
591
    }
592
593
    /**
594
     * @param string $priceTypeName
595
     * @param string $fallbackPriceTypeName
596
     *
597
     * @return \PHPUnit\Framework\MockObject\MockObject|\Spryker\Zed\PriceProductSchedule\PriceProductScheduleConfig
598
     */
599
    protected function getConfigMock(string $priceTypeName, string $fallbackPriceTypeName): PriceProductScheduleConfig
600
    {
601
        $configMock = $this->getMockBuilder(PriceProductScheduleConfig::class)
602
            ->setMethods(['getFallbackPriceTypeList'])
603
            ->getMock();
604
605
        $configMock->method('getFallbackPriceTypeList')
606
            ->willReturn([$priceTypeName => $fallbackPriceTypeName]);
607
608
        return $configMock;
609
    }
610
611
    /**
612
     * @param \Spryker\Zed\PriceProductSchedule\Business\PriceProductSchedule\Applier\AbstractProductPriceProductScheduleApplier|\PHPUnit\Framework\MockObject\MockObject $applierMock
613
     *
614
     * @return \Spryker\Zed\PriceProductSchedule\Business\PriceProductScheduleFacadeInterface
615
     */
616
    protected function getFacadeMockForAbstractPrices(AbstractProductPriceProductScheduleApplier $applierMock): PriceProductScheduleFacadeInterface
617
    {
618
        $priceProductScheduleFacade = $this->tester->getFacade();
619
        $priceProductScheduleBusinessFactory = $this->getFactoryMock($applierMock, 'createAbstractProductPriceProductScheduleApplier');
620
        $priceProductScheduleFacade->setFactory($priceProductScheduleBusinessFactory);
0 ignored issues
show
The method setFactory() does not exist on Spryker\Zed\PriceProduct...ScheduleFacadeInterface. Since it exists in all sub-types, consider adding an abstract or default implementation to Spryker\Zed\PriceProduct...ScheduleFacadeInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

620
        $priceProductScheduleFacade->/** @scrutinizer ignore-call */ 
621
                                     setFactory($priceProductScheduleBusinessFactory);
Loading history...
621
622
        return $priceProductScheduleFacade;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $priceProductScheduleFacade could return the type Spryker\Zed\Kernel\Business\AbstractFacade which is incompatible with the type-hinted return Spryker\Zed\PriceProduct...ScheduleFacadeInterface. Consider adding an additional type-check to rule them out.
Loading history...
623
    }
624
625
    /**
626
     * @param \Spryker\Zed\PriceProductSchedule\Business\PriceProductSchedule\Applier\ConcreteProductPriceProductScheduleApplier|\PHPUnit\Framework\MockObject\MockObject $applierMock
627
     *
628
     * @return \Spryker\Zed\PriceProductSchedule\Business\PriceProductScheduleFacadeInterface
629
     */
630
    protected function getFacadeMockForConcretePrices(ConcreteProductPriceProductScheduleApplier $applierMock): PriceProductScheduleFacadeInterface
631
    {
632
        $priceProductScheduleFacade = $this->tester->getFacade();
633
        $priceProductScheduleBusinessFactory = $this->getFactoryMock($applierMock, 'createConcreteProductPriceProductScheduleApplier');
634
        $priceProductScheduleFacade->setFactory($priceProductScheduleBusinessFactory);
635
636
        return $priceProductScheduleFacade;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $priceProductScheduleFacade could return the type Spryker\Zed\Kernel\Business\AbstractFacade which is incompatible with the type-hinted return Spryker\Zed\PriceProduct...ScheduleFacadeInterface. Consider adding an additional type-check to rule them out.
Loading history...
637
    }
638
639
    /**
640
     * @param \Spryker\Zed\PriceProductSchedule\Business\PriceProductSchedule\Applier\ConcreteProductPriceProductScheduleApplier|\Spryker\Zed\PriceProductSchedule\Business\PriceProductSchedule\Applier\AbstractProductPriceProductScheduleApplier|\PHPUnit\Framework\MockObject\MockObject $applierMock
641
     * @param string $mockFactoryMethod
642
     *
643
     * @return \Spryker\Zed\PriceProductSchedule\Business\PriceProductScheduleBusinessFactory|\PHPUnit\Framework\MockObject\MockObject
644
     */
645
    protected function getFactoryMock($applierMock, string $mockFactoryMethod): PriceProductScheduleBusinessFactory
646
    {
647
        $priceProductScheduleBusinessFactory = $this->getMockBuilder(PriceProductScheduleBusinessFactory::class)
648
            ->setMethods([
649
                $mockFactoryMethod,
650
                'getRepository',
651
                'getEntityManager',
652
                'getProvidedDependency',
653
                'getStoreFacade',
654
                'getConfig',
655
                'getPriceProductFacade',
656
            ])
657
            ->getMock();
658
        $storeFacade = new PriceProductScheduleToStoreFacadeBridge(
659
            $this->tester->getLocator()->store()->facade(),
660
        );
661
        $priceProductFacade = new PriceProductScheduleToPriceProductFacadeBridge(
662
            $this->tester->getLocator()->priceProduct()->facade(),
663
        );
664
        $priceProductScheduleConfig = new PriceProductScheduleConfig();
665
        $priceProductScheduleBusinessFactory->method('getStoreFacade')
666
            ->willReturn($storeFacade);
667
        $priceProductScheduleBusinessFactory->method('getConfig')
668
            ->willReturn($priceProductScheduleConfig);
669
        $priceProductScheduleBusinessFactory->method('getPriceProductFacade')
670
            ->willReturn($priceProductFacade);
671
        $priceProductScheduleBusinessFactory->method('getEntityManager')
672
            ->willReturn(new PriceProductScheduleEntityManager());
673
        $priceProductScheduleBusinessFactory->method('getRepository')
674
            ->willReturn(new PriceProductScheduleRepository());
675
676
        $priceProductScheduleBusinessFactory
677
            ->method($mockFactoryMethod)
678
            ->willReturn($applierMock);
679
680
        return $priceProductScheduleBusinessFactory;
681
    }
682
}
683