1010
1111use Magento \Framework \TestFramework \Unit \Helper \ObjectManager ;
1212
13+ /**
14+ * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
15+ */
1316class RowTest extends \PHPUnit \Framework \TestCase
1417{
1518 /**
@@ -61,6 +64,8 @@ protected function setUp()
6164 {
6265 $ objectManager = new ObjectManager ($ this );
6366
67+ $ attributeTable = 'catalog_product_entity_int ' ;
68+ $ statusId = 22 ;
6469 $ this ->connection = $ this ->createMock (\Magento \Framework \DB \Adapter \AdapterInterface::class);
6570 $ this ->resource = $ this ->createMock (\Magento \Framework \App \ResourceConnection::class);
6671 $ this ->resource ->expects ($ this ->any ())->method ('getConnection ' )
@@ -70,10 +75,36 @@ protected function setUp()
7075 $ this ->store = $ this ->createMock (\Magento \Store \Model \Store::class);
7176 $ this ->store ->expects ($ this ->any ())->method ('getId ' )->will ($ this ->returnValue ('store_id_1 ' ));
7277 $ this ->storeManager ->expects ($ this ->any ())->method ('getStores ' )->will ($ this ->returnValue ([$ this ->store ]));
73- $ this ->productIndexerHelper = $ this ->createMock (\Magento \Catalog \Helper \Product \Flat \Indexer::class);
7478 $ this ->flatItemEraser = $ this ->createMock (\Magento \Catalog \Model \Indexer \Product \Flat \Action \Eraser::class);
7579 $ this ->flatItemWriter = $ this ->createMock (\Magento \Catalog \Model \Indexer \Product \Flat \Action \Indexer::class);
7680 $ this ->flatTableBuilder = $ this ->createMock (\Magento \Catalog \Model \Indexer \Product \Flat \FlatTableBuilder::class);
81+ $ this ->productIndexerHelper = $ this ->createMock (\Magento \Catalog \Helper \Product \Flat \Indexer::class);
82+ $ statusAttributeMock = $ this ->getMockBuilder (\Magento \Eav \Model \Entity \Attribute::class)
83+ ->disableOriginalConstructor ()
84+ ->getMock ();
85+ $ this ->productIndexerHelper ->expects ($ this ->any ())->method ('getAttribute ' )
86+ ->with ('status ' )
87+ ->willReturn ($ statusAttributeMock );
88+ $ backendMock = $ this ->getMockBuilder (\Magento \Eav \Model \Entity \Attribute \Backend \AbstractBackend::class)
89+ ->disableOriginalConstructor ()
90+ ->getMock ();
91+ $ backendMock ->expects ($ this ->any ())->method ('getTable ' )->willReturn ($ attributeTable );
92+ $ statusAttributeMock ->expects ($ this ->any ())->method ('getBackend ' )->willReturn (
93+ $ backendMock
94+ );
95+ $ statusAttributeMock ->expects ($ this ->any ())->method ('getId ' )->willReturn ($ statusId );
96+ $ selectMock = $ this ->getMockBuilder (\Magento \Framework \DB \Select::class)
97+ ->disableOriginalConstructor ()
98+ ->getMock ();
99+ $ this ->connection ->expects ($ this ->any ())->method ('select ' )->willReturn ($ selectMock );
100+ $ selectMock ->expects ($ this ->any ())->method ('from ' )->with (
101+ $ attributeTable ,
102+ ['value ' ]
103+ )->willReturnSelf ();
104+ $ selectMock ->expects ($ this ->any ())->method ('where ' )->willReturnSelf ();
105+ $ pdoMock = $ this ->createMock (\Zend_Db_Statement_Pdo::class);
106+ $ this ->connection ->expects ($ this ->any ())->method ('query ' )->with ($ selectMock )->will ($ this ->returnValue ($ pdoMock ));
107+ $ pdoMock ->expects ($ this ->any ())->method ('fetch ' )->will ($ this ->returnValue (['value ' => 1 ]));
77108
78109 $ this ->model = $ objectManager ->getObject (
79110 \Magento \Catalog \Model \Indexer \Product \Flat \Action \Row::class, [
@@ -82,7 +113,7 @@ protected function setUp()
82113 'productHelper ' => $ this ->productIndexerHelper ,
83114 'flatItemEraser ' => $ this ->flatItemEraser ,
84115 'flatItemWriter ' => $ this ->flatItemWriter ,
85- 'flatTableBuilder ' => $ this ->flatTableBuilder
116+ 'flatTableBuilder ' => $ this ->flatTableBuilder ,
86117 ]);
87118 }
88119
0 commit comments