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