88
99use Magento \Framework \TestFramework \Unit \Helper \ObjectManager ;
1010
11+
12+ /**
13+ * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
14+ */
1115class RowTest extends \PHPUnit \Framework \TestCase
1216{
1317 /**
@@ -59,6 +63,8 @@ protected function setUp()
5963 {
6064 $ objectManager = new ObjectManager ($ this );
6165
66+ $ attributeTable = 'catalog_product_entity_int ' ;
67+ $ statusId = 22 ;
6268 $ this ->connection = $ this ->createMock (\Magento \Framework \DB \Adapter \AdapterInterface::class);
6369 $ this ->resource = $ this ->createMock (\Magento \Framework \App \ResourceConnection::class);
6470 $ this ->resource ->expects ($ this ->any ())->method ('getConnection ' )
@@ -68,12 +74,38 @@ protected function setUp()
6874 $ this ->store = $ this ->createMock (\Magento \Store \Model \Store::class);
6975 $ this ->store ->expects ($ this ->any ())->method ('getId ' )->will ($ this ->returnValue ('store_id_1 ' ));
7076 $ this ->storeManager ->expects ($ this ->any ())->method ('getStores ' )->will ($ this ->returnValue ([$ this ->store ]));
71- $ this ->productIndexerHelper = $ this ->createMock (\Magento \Catalog \Helper \Product \Flat \Indexer::class);
7277 $ this ->flatItemEraser = $ this ->createMock (\Magento \Catalog \Model \Indexer \Product \Flat \Action \Eraser::class);
7378 $ this ->flatItemWriter = $ this ->createMock (\Magento \Catalog \Model \Indexer \Product \Flat \Action \Indexer::class);
7479 $ this ->flatTableBuilder = $ this ->createMock (
7580 \Magento \Catalog \Model \Indexer \Product \Flat \FlatTableBuilder::class
7681 );
82+ $ this ->productIndexerHelper = $ this ->createMock (\Magento \Catalog \Helper \Product \Flat \Indexer::class);
83+ $ statusAttributeMock = $ this ->getMockBuilder (\Magento \Eav \Model \Entity \Attribute::class)
84+ ->disableOriginalConstructor ()
85+ ->getMock ();
86+ $ this ->productIndexerHelper ->expects ($ this ->any ())->method ('getAttribute ' )
87+ ->with ('status ' )
88+ ->willReturn ($ statusAttributeMock );
89+ $ backendMock = $ this ->getMockBuilder (\Magento \Eav \Model \Entity \Attribute \Backend \AbstractBackend::class)
90+ ->disableOriginalConstructor ()
91+ ->getMock ();
92+ $ backendMock ->expects ($ this ->any ())->method ('getTable ' )->willReturn ($ attributeTable );
93+ $ statusAttributeMock ->expects ($ this ->any ())->method ('getBackend ' )->willReturn (
94+ $ backendMock
95+ );
96+ $ statusAttributeMock ->expects ($ this ->any ())->method ('getId ' )->willReturn ($ statusId );
97+ $ selectMock = $ this ->getMockBuilder (\Magento \Framework \DB \Select::class)
98+ ->disableOriginalConstructor ()
99+ ->getMock ();
100+ $ this ->connection ->expects ($ this ->any ())->method ('select ' )->willReturn ($ selectMock );
101+ $ selectMock ->expects ($ this ->any ())->method ('from ' )->with (
102+ $ attributeTable ,
103+ ['value ' ]
104+ )->willReturnSelf ();
105+ $ selectMock ->expects ($ this ->any ())->method ('where ' )->willReturnSelf ();
106+ $ pdoMock = $ this ->createMock (\Zend_Db_Statement_Pdo::class);
107+ $ this ->connection ->expects ($ this ->any ())->method ('query ' )->with ($ selectMock )->will ($ this ->returnValue ($ pdoMock ));
108+ $ pdoMock ->expects ($ this ->any ())->method ('fetch ' )->will ($ this ->returnValue (['value ' => 1 ]));
77109
78110 $ this ->model = $ objectManager ->getObject (
79111 \Magento \Catalog \Model \Indexer \Product \Flat \Action \Row::class,
@@ -83,7 +115,7 @@ protected function setUp()
83115 'productHelper ' => $ this ->productIndexerHelper ,
84116 'flatItemEraser ' => $ this ->flatItemEraser ,
85117 'flatItemWriter ' => $ this ->flatItemWriter ,
86- 'flatTableBuilder ' => $ this ->flatTableBuilder
118+ 'flatTableBuilder ' => $ this ->flatTableBuilder ,
87119 ]
88120 );
89121 }
0 commit comments