Skip to content

Commit 38bd9d3

Browse files
committed
[TASK] Updated the Unit Test according to issue-14966
1 parent 2d6fb62 commit 38bd9d3

File tree

2 files changed

+31
-3
lines changed
  • app/code/Magento/Catalog
    • Model/Indexer/Product/Flat/Action
    • Test/Unit/Model/Indexer/Product/Flat/Action

2 files changed

+31
-3
lines changed

app/code/Magento/Catalog/Model/Indexer/Product/Flat/Action/Row.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public function execute($id = null)
7979

8080
/* @var $status \Magento\Eav\Model\Entity\Attribute */
8181
$status = $this->_productIndexerHelper->getAttribute('status');
82-
$statusTable = $status->getBackendTable();
82+
$statusTable = $status->getBackend()->getTable();
8383
$statusConditions = [
8484
'store_id IN(0,' . (int)$store->getId() . ')',
8585
'attribute_id = ' . (int)$status->getId(),

app/code/Magento/Catalog/Test/Unit/Model/Indexer/Product/Flat/Action/RowTest.php

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ protected function setUp()
6161
{
6262
$objectManager = new ObjectManager($this);
6363

64+
$attributeTable = 'catalog_product_entity_int';
65+
$statusId = 22;
6466
$this->connection = $this->createMock(\Magento\Framework\DB\Adapter\AdapterInterface::class);
6567
$this->resource = $this->createMock(\Magento\Framework\App\ResourceConnection::class);
6668
$this->resource->expects($this->any())->method('getConnection')
@@ -70,10 +72,36 @@ protected function setUp()
7072
$this->store = $this->createMock(\Magento\Store\Model\Store::class);
7173
$this->store->expects($this->any())->method('getId')->will($this->returnValue('store_id_1'));
7274
$this->storeManager->expects($this->any())->method('getStores')->will($this->returnValue([$this->store]));
73-
$this->productIndexerHelper = $this->createMock(\Magento\Catalog\Helper\Product\Flat\Indexer::class);
7475
$this->flatItemEraser = $this->createMock(\Magento\Catalog\Model\Indexer\Product\Flat\Action\Eraser::class);
7576
$this->flatItemWriter = $this->createMock(\Magento\Catalog\Model\Indexer\Product\Flat\Action\Indexer::class);
7677
$this->flatTableBuilder = $this->createMock(\Magento\Catalog\Model\Indexer\Product\Flat\FlatTableBuilder::class);
78+
$this->productIndexerHelper = $this->createMock(\Magento\Catalog\Helper\Product\Flat\Indexer::class);
79+
$statusAttributeMock = $this->getMockBuilder(\Magento\Eav\Model\Entity\Attribute::class)
80+
->disableOriginalConstructor()
81+
->getMock();
82+
$this->productIndexerHelper->expects($this->any())->method('getAttribute')
83+
->with('status')
84+
->willReturn($statusAttributeMock);
85+
$backendMock = $this->getMockBuilder(\Magento\Eav\Model\Entity\Attribute\Backend\AbstractBackend::class)
86+
->disableOriginalConstructor()
87+
->getMock();
88+
$backendMock->expects($this->any())->method('getTable')->willReturn($attributeTable);
89+
$statusAttributeMock->expects($this->any())->method('getBackend')->willReturn(
90+
$backendMock
91+
);
92+
$statusAttributeMock->expects($this->any())->method('getId')->willReturn($statusId);
93+
$selectMock = $this->getMockBuilder(\Magento\Framework\DB\Select::class)
94+
->disableOriginalConstructor()
95+
->getMock();
96+
$this->connection->expects($this->any())->method('select')->willReturn($selectMock);
97+
$selectMock->expects($this->any())->method('from')->with(
98+
$attributeTable,
99+
['value']
100+
)->willReturnSelf();
101+
$selectMock->expects($this->any())->method('where')->willReturnSelf();
102+
$pdoMock = $this->createMock(\Zend_Db_Statement_Pdo::class);
103+
$this->connection->expects($this->any())->method('query')->with($selectMock)->will($this->returnValue($pdoMock));
104+
$pdoMock->expects($this->any())->method('fetch')->will($this->returnValue(['value' => 1]));
77105

78106
$this->model = $objectManager->getObject(
79107
\Magento\Catalog\Model\Indexer\Product\Flat\Action\Row::class, [
@@ -82,7 +110,7 @@ protected function setUp()
82110
'productHelper' => $this->productIndexerHelper,
83111
'flatItemEraser' => $this->flatItemEraser,
84112
'flatItemWriter' => $this->flatItemWriter,
85-
'flatTableBuilder' => $this->flatTableBuilder
113+
'flatTableBuilder' => $this->flatTableBuilder,
86114
]);
87115
}
88116

0 commit comments

Comments
 (0)