10
10
11
11
use Magento \Framework \TestFramework \Unit \Helper \ObjectManager ;
12
12
13
+ /**
14
+ * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
15
+ */
13
16
class RowTest extends \PHPUnit \Framework \TestCase
14
17
{
15
18
/**
@@ -61,6 +64,8 @@ protected function setUp()
61
64
{
62
65
$ objectManager = new ObjectManager ($ this );
63
66
67
+ $ attributeTable = 'catalog_product_entity_int ' ;
68
+ $ statusId = 22 ;
64
69
$ this ->connection = $ this ->createMock (\Magento \Framework \DB \Adapter \AdapterInterface::class);
65
70
$ this ->resource = $ this ->createMock (\Magento \Framework \App \ResourceConnection::class);
66
71
$ this ->resource ->expects ($ this ->any ())->method ('getConnection ' )
@@ -70,10 +75,36 @@ protected function setUp()
70
75
$ this ->store = $ this ->createMock (\Magento \Store \Model \Store::class);
71
76
$ this ->store ->expects ($ this ->any ())->method ('getId ' )->will ($ this ->returnValue ('store_id_1 ' ));
72
77
$ this ->storeManager ->expects ($ this ->any ())->method ('getStores ' )->will ($ this ->returnValue ([$ this ->store ]));
73
- $ this ->productIndexerHelper = $ this ->createMock (\Magento \Catalog \Helper \Product \Flat \Indexer::class);
74
78
$ this ->flatItemEraser = $ this ->createMock (\Magento \Catalog \Model \Indexer \Product \Flat \Action \Eraser::class);
75
79
$ this ->flatItemWriter = $ this ->createMock (\Magento \Catalog \Model \Indexer \Product \Flat \Action \Indexer::class);
76
80
$ 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 ]));
77
108
78
109
$ this ->model = $ objectManager ->getObject (
79
110
\Magento \Catalog \Model \Indexer \Product \Flat \Action \Row::class, [
@@ -82,7 +113,7 @@ protected function setUp()
82
113
'productHelper ' => $ this ->productIndexerHelper ,
83
114
'flatItemEraser ' => $ this ->flatItemEraser ,
84
115
'flatItemWriter ' => $ this ->flatItemWriter ,
85
- 'flatTableBuilder ' => $ this ->flatTableBuilder
116
+ 'flatTableBuilder ' => $ this ->flatTableBuilder ,
86
117
]);
87
118
}
88
119
0 commit comments