Skip to content

Commit f6c0ae7

Browse files
committed
ACP2E-1401: catalog_product_price index getting stuck
1 parent d54a055 commit f6c0ae7

File tree

1 file changed

+196
-0
lines changed

1 file changed

+196
-0
lines changed
Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Catalog\Test\Unit\Model\Indexer\Product\Price\Action;
9+
10+
use Magento\Framework\Exception\InputException;
11+
use Magento\Framework\Exception\LocalizedException;
12+
use Magento\Framework\Search\Request\Dimension;
13+
use Magento\Store\Model\StoreManagerInterface;
14+
use Magento\Directory\Model\CurrencyFactory;
15+
use Magento\Catalog\Model\Product\Type;
16+
use Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\Factory;
17+
use Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\DefaultPrice;
18+
use Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\TierPrice;
19+
use Magento\Catalog\Model\Indexer\Product\Price\DimensionCollectionFactory;
20+
use Magento\Catalog\Model\Indexer\Product\Price\TableMaintainer;
21+
use Magento\Catalog\Model\Indexer\Product\Price\Action\Row;
22+
use Magento\Framework\App\Config\ScopeConfigInterface;
23+
use Magento\Framework\Stdlib\DateTime;
24+
use Magento\Framework\Stdlib\DateTime\TimezoneInterface;
25+
use Magento\Framework\DB\Adapter\AdapterInterface;
26+
use Magento\Framework\DB\Select;
27+
use Magento\Framework\Indexer\MultiDimensionProvider;
28+
use PHPUnit\Framework\TestCase;
29+
use PHPUnit\Framework\MockObject\MockObject;
30+
31+
class RowDefaultPriceIndexerTest extends TestCase
32+
{
33+
/**
34+
* @var Row
35+
*/
36+
private $actionRow;
37+
38+
/**
39+
* @var ScopeConfigInterface|MockObject
40+
*/
41+
private $config;
42+
43+
/**
44+
* @var StoreManagerInterface|MockObject
45+
*/
46+
private $storeManager;
47+
48+
/**
49+
* @var CurrencyFactory|MockObject
50+
*/
51+
private $currencyFactory;
52+
53+
/**
54+
* @var TimezoneInterface|MockObject
55+
*/
56+
private $localeDate;
57+
58+
/**
59+
* @var DateTime|MockObject
60+
*/
61+
private $dateTime;
62+
63+
/**
64+
* @var Type|MockObject
65+
*/
66+
private $catalogProductType;
67+
68+
/**
69+
* @var Factory|MockObject
70+
*/
71+
private $indexerPriceFactory;
72+
73+
/**
74+
* @var DefaultPrice|MockObject
75+
*/
76+
private $defaultIndexerResource;
77+
78+
/**
79+
* @var TierPrice|MockObject
80+
*/
81+
private $tierPriceIndexResource;
82+
83+
/**
84+
* @var DimensionCollectionFactory|MockObject
85+
*/
86+
private $dimensionCollectionFactory;
87+
88+
/**
89+
* @var TableMaintainer|MockObject
90+
*/
91+
private $tableMaintainer;
92+
93+
protected function setUp(): void
94+
{
95+
$this->config = $this->createMock(ScopeConfigInterface::class);
96+
$this->storeManager = $this->createMock(StoreManagerInterface::class);
97+
$this->currencyFactory = $this->createMock(CurrencyFactory::class);
98+
$this->localeDate = $this->createMock(TimezoneInterface::class);
99+
$this->dateTime = $this->createMock(DateTime::class);
100+
$this->catalogProductType = $this->createMock(Type::class);
101+
$this->indexerPriceFactory = $this->createMock(Factory::class);
102+
$this->defaultIndexerResource = $this->createMock(DefaultPrice::class);
103+
$this->tierPriceIndexResource = $this->createMock(TierPrice::class);
104+
$this->dimensionCollectionFactory = $this->createMock(DimensionCollectionFactory::class);
105+
$this->tableMaintainer = $this->createMock(TableMaintainer::class);
106+
107+
$this->actionRow = new Row(
108+
$this->config,
109+
$this->storeManager,
110+
$this->currencyFactory,
111+
$this->localeDate,
112+
$this->dateTime,
113+
$this->catalogProductType,
114+
$this->indexerPriceFactory,
115+
$this->defaultIndexerResource,
116+
$this->tierPriceIndexResource,
117+
$this->dimensionCollectionFactory,
118+
$this->tableMaintainer
119+
);
120+
}
121+
122+
/**
123+
* Test that the price indexer will be able to perform the indexation with DefaultPrice indexer
124+
*
125+
* @return void
126+
* @throws InputException
127+
* @throws LocalizedException
128+
*/
129+
public function testRowDefaultPriceIndexer()
130+
{
131+
$select = $this->createMock(Select::class);
132+
$select->method('from')->willReturnSelf();
133+
$select->method('joinLeft')->willReturnSelf();
134+
$select->method('where')->willReturnSelf();
135+
$select->method('join')->willReturnSelf();
136+
137+
$adapter = $this->createMock(AdapterInterface::class);
138+
$adapter->method('select')->willReturn($select);
139+
$adapter->method('describeTable')->willReturn([]);
140+
141+
$adapter->expects($this->exactly(1))
142+
->method('describeTable');
143+
144+
$this->tableMaintainer->expects($this->exactly(3))->method('getMainTableByDimensions');
145+
146+
$this->defaultIndexerResource->method('getConnection')->willReturn($adapter);
147+
$adapter->method('fetchAll')->with($select)->willReturn([]);
148+
149+
$adapter->expects($this->any())
150+
->method('fetchPairs')
151+
->with($select)
152+
->willReturn(
153+
[1 => 'simple'],
154+
[]
155+
);
156+
157+
$multiDimensionProvider = $this->createMock(MultiDimensionProvider::class);
158+
$this->dimensionCollectionFactory->expects($this->exactly(2))
159+
->method('create')
160+
->willReturn($multiDimensionProvider);
161+
$dimension = $this->createMock(Dimension::class);
162+
$dimension->method('getName')->willReturn('default');
163+
$dimension->method('getValue')->willReturn('0');
164+
$iterator = new \ArrayIterator([[$dimension]]);
165+
$multiDimensionProvider->expects($this->exactly(2))
166+
->method('getIterator')
167+
->willReturn($iterator);
168+
$this->catalogProductType->expects($this->once())
169+
->method('getTypesByPriority')
170+
->willReturn(
171+
[
172+
'simple' => ['price_indexer' => '\Price\Indexer']
173+
]
174+
);
175+
$this->indexerPriceFactory->expects($this->exactly(1))
176+
->method('create')
177+
->with('\Price\Indexer', ['fullReindexAction' => false])
178+
->willReturn($this->defaultIndexerResource);
179+
$this->defaultIndexerResource->expects($this->exactly(1))
180+
->method('reindexEntity');
181+
$this->defaultIndexerResource->expects($this->any())->method('setTypeId')->willReturnSelf();
182+
$this->defaultIndexerResource->expects($this->any())->method('setIsComposite');
183+
$select->expects($this->exactly(1))
184+
->method('deleteFromSelect')
185+
->with('index_price')
186+
->willReturn('');
187+
$adapter->expects($this->exactly(2))
188+
->method('getIndexList')
189+
->willReturn(['entity_id'=>['COLUMNS_LIST'=>['test']]]);
190+
$adapter->expects($this->exactly(2))
191+
->method('getPrimaryKeyName')
192+
->willReturn('entity_id');
193+
194+
$this->actionRow->execute(1);
195+
}
196+
}

0 commit comments

Comments
 (0)