Skip to content

Commit 6a9f447

Browse files
committed
MC-41807: Partial Catalog Product Price Indexing not removing old price date and is extremely slow if store has many products (above 200k)
1 parent 6e6fff2 commit 6a9f447

File tree

1 file changed

+42
-20
lines changed

1 file changed

+42
-20
lines changed

app/code/Magento/CatalogRule/Test/Unit/Cron/DailyCatalogUpdateTest.php

Lines changed: 42 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,49 +5,71 @@
55
*/
66
declare(strict_types=1);
77

8-
98
namespace Magento\CatalogRule\Test\Unit\Cron;
109

1110
use Magento\CatalogRule\Cron\DailyCatalogUpdate;
1211
use Magento\CatalogRule\Model\Indexer\Rule\RuleProductProcessor;
13-
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
12+
use Magento\CatalogRule\Model\ResourceModel\Rule\Collection as RuleCollection;
13+
use Magento\CatalogRule\Model\ResourceModel\Rule\CollectionFactory as RuleCollectionFactory;
1414
use PHPUnit\Framework\MockObject\MockObject;
1515
use PHPUnit\Framework\TestCase;
1616

1717
class DailyCatalogUpdateTest extends TestCase
1818
{
1919
/**
20-
* Processor
21-
*
2220
* @var RuleProductProcessor|MockObject
2321
*/
24-
protected $ruleProductProcessor;
22+
private $ruleProductProcessor;
23+
24+
/**
25+
* @var RuleCollectionFactory|MockObject
26+
*/
27+
private $ruleCollectionFactory;
2528

2629
/**
27-
* Cron object
28-
*
2930
* @var DailyCatalogUpdate
3031
*/
31-
protected $cron;
32+
private $cron;
3233

3334
protected function setUp(): void
3435
{
35-
$this->ruleProductProcessor = $this->createMock(
36-
RuleProductProcessor::class
37-
);
38-
39-
$this->cron = (new ObjectManager($this))->getObject(
40-
DailyCatalogUpdate::class,
41-
[
42-
'ruleProductProcessor' => $this->ruleProductProcessor,
43-
]
44-
);
36+
$this->ruleProductProcessor = $this->createMock(RuleProductProcessor::class);
37+
$this->ruleCollectionFactory = $this->createMock(RuleCollectionFactory::class);
38+
39+
$this->cron = new DailyCatalogUpdate($this->ruleProductProcessor, $this->ruleCollectionFactory);
4540
}
4641

47-
public function testDailyCatalogUpdate()
42+
/**
43+
* @dataProvider executeDataProvider
44+
* @param int $activeRulesCount
45+
* @param bool $isInvalidationNeeded
46+
*/
47+
public function testExecute(int $activeRulesCount, bool $isInvalidationNeeded)
4848
{
49-
$this->ruleProductProcessor->expects($this->once())->method('markIndexerAsInvalid');
49+
$ruleCollection = $this->createMock(RuleCollection::class);
50+
$this->ruleCollectionFactory->expects($this->once())
51+
->method('create')
52+
->willReturn($ruleCollection);
53+
$ruleCollection->expects($this->once())
54+
->method('addIsActiveFilter')
55+
->willReturn($ruleCollection);
56+
$ruleCollection->expects($this->once())
57+
->method('getSize')
58+
->willReturn($activeRulesCount);
59+
$this->ruleProductProcessor->expects($isInvalidationNeeded ? $this->once() : $this->never())
60+
->method('markIndexerAsInvalid');
5061

5162
$this->cron->execute();
5263
}
64+
65+
/**
66+
* @return array
67+
*/
68+
public function executeDataProvider(): array
69+
{
70+
return [
71+
[2, true],
72+
[0, false],
73+
];
74+
}
5375
}

0 commit comments

Comments
 (0)