36 private $resourceConnectionMock;
41 private $scopeResolverMock;
51 private $inventoryConfigMock;
55 $this->resourceConnectionMock = $this->createMock(ResourceConnection::class);
56 $this->scopeResolverMock = $this->createMock(ScopeResolverInterface::class);
57 $this->adapterMock = $this->createMock(AdapterInterface::class);
58 $this->inventoryConfigMock = $this->createMock(CatalogInventoryConfiguration::class);
60 $this->resourceConnectionMock->expects($this->atLeastOnce())
61 ->method(
'getConnection')
62 ->willReturn($this->adapterMock);
64 $this->indexScopeResolverMock = $this->createMock(
65 \
Magento\Framework\Search\Request\IndexScopeResolverInterface::class
67 $this->dimensionMock = $this->createMock(\
Magento\Framework\Indexer\Dimension::class);
68 $this->dimensionFactoryMock = $this->createMock(\
Magento\Framework\Indexer\DimensionFactory::class);
69 $this->dimensionFactoryMock->method(
'create')->willReturn($this->dimensionMock);
70 $storeMock = $this->createMock(\
Magento\
Store\Api\Data\StoreInterface::class);
71 $storeMock->method(
'getId')->willReturn(1);
72 $storeMock->method(
'getWebsiteId')->willReturn(1);
73 $this->storeManagerMock = $this->createMock(\
Magento\
Store\Model\StoreManagerInterface::class);
74 $this->storeManagerMock->method(
'getStore')->willReturn($storeMock);
75 $this->indexScopeResolverMock->method(
'resolve')->willReturn(
'catalog_product_index_price');
78 $this->resourceConnectionMock,
79 $this->scopeResolverMock,
80 $this->inventoryConfigMock,
81 $this->indexScopeResolverMock,
82 $this->dimensionFactoryMock
90 $selectMock = $this->createMock(Select::class);
91 $attributeMock = $this->createMock(AbstractAttribute::class);
92 $storeMock = $this->createMock(Store::class);
94 $this->adapterMock->expects($this->atLeastOnce())->method(
'select')
95 ->willReturn($selectMock);
96 $selectMock->expects($this->once())->method(
'joinInner')
97 ->with([
'entities' =>
$tableName],
'main_table.entity_id = entities.entity_id', []);
98 $attributeMock->expects($this->once())->method(
'getAttributeCode')
99 ->willReturn(
'price');
100 $this->scopeResolverMock->expects($this->once())->method(
'getScope')
101 ->with($scope)->willReturn($storeMock);
102 $storeMock->expects($this->once())->method(
'getWebsiteId')->willReturn(1);
103 $selectMock->expects($this->once())->method(
'from')
104 ->with([
'main_table' =>
'catalog_product_index_price'],
null)
105 ->willReturn($selectMock);
106 $selectMock->expects($this->once())->method(
'columns')
107 ->with([
'value' =>
'main_table.min_price'])
108 ->willReturn($selectMock);
109 $selectMock->expects($this->exactly(2))->method(
'where')
111 [
'main_table.customer_group_id = ?', 1],
112 [
'main_table.website_id = ?', 1]
113 )->willReturn($selectMock);
115 $this->model->build($attributeMock,
$tableName, $scope, 1);
122 $selectMock = $this->createMock(Select::class);
123 $attributeMock = $this->createMock(AbstractAttribute::class);
124 $storeMock = $this->createMock(Store::class);
126 $this->adapterMock->expects($this->atLeastOnce())->method(
'select')
127 ->willReturn($selectMock);
128 $selectMock->expects($this->once())->method(
'joinInner')
129 ->with([
'entities' =>
$tableName],
'main_table.entity_id = entities.entity_id', []);
130 $attributeMock->expects($this->once())->method(
'getBackendType')
131 ->willReturn(
'decimal');
132 $this->scopeResolverMock->expects($this->once())->method(
'getScope')
133 ->with($scope)->willReturn($storeMock);
134 $storeMock->expects($this->once())->method(
'getId')->willReturn(1);
135 $this->resourceConnectionMock->expects($this->exactly(2))->method(
'getTableName')
137 [
'catalog_product_index_eav_decimal'],
138 [
'cataloginventory_stock_status']
139 )->willReturnOnConsecutiveCalls(
140 'catalog_product_index_eav_decimal',
141 'cataloginventory_stock_status' 144 $selectMock->expects($this->exactly(2))->method(
'from')
147 [
'main_table' =>
'catalog_product_index_eav_decimal'],
148 [
'main_table.entity_id',
'main_table.value']
150 [[
'main_table' => $selectMock], [
'main_table.value']]
152 ->willReturn($selectMock);
153 $selectMock->expects($this->once())->method(
'distinct')->willReturn($selectMock);
154 $selectMock->expects($this->once())->method(
'joinLeft')
156 [
'stock_index' =>
'cataloginventory_stock_status'],
157 'main_table.source_id = stock_index.product_id',
159 )->willReturn($selectMock);
160 $attributeMock->expects($this->once())->method(
'getAttributeId')->willReturn(3);
161 $selectMock->expects($this->exactly(3))->method(
'where')
163 [
'main_table.attribute_id = ?', 3],
164 [
'main_table.store_id = ? ', 1],
166 )->willReturn($selectMock);
167 $this->inventoryConfigMock->expects($this->once())->method(
'isShowOutOfStock')->with(1)->willReturn(
false);
169 $this->model->build($attributeMock,
$tableName, $scope, 1);
testBuildWithPriceAttributeCode()
testBuildWithNotPriceAttributeCode()