88
99namespace Magento \Catalog \Test \Unit \Model \Indexer \Product \Flat \Action ;
1010
11+ use Magento \Catalog \Api \Data \ProductInterface ;
1112use Magento \Framework \TestFramework \Unit \Helper \ObjectManager ;
13+ use PHPUnit_Framework_MockObject_MockObject as MockObject ;
1214
1315/**
1416 * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -21,45 +23,48 @@ class RowTest extends \PHPUnit\Framework\TestCase
2123 protected $ model ;
2224
2325 /**
24- * @var \PHPUnit_Framework_MockObject_MockObject
26+ * @var MockObject
2527 */
2628 protected $ storeManager ;
2729
2830 /**
29- * @var \PHPUnit_Framework_MockObject_MockObject
31+ * @var MockObject
3032 */
3133 protected $ store ;
3234
3335 /**
34- * @var \PHPUnit_Framework_MockObject_MockObject
36+ * @var MockObject
3537 */
3638 protected $ productIndexerHelper ;
3739
3840 /**
39- * @var \PHPUnit_Framework_MockObject_MockObject
41+ * @var MockObject
4042 */
4143 protected $ resource ;
4244
4345 /**
44- * @var \PHPUnit_Framework_MockObject_MockObject
46+ * @var MockObject
4547 */
4648 protected $ connection ;
4749
4850 /**
49- * @var \PHPUnit_Framework_MockObject_MockObject
51+ * @var MockObject
5052 */
5153 protected $ flatItemWriter ;
5254
5355 /**
54- * @var \PHPUnit_Framework_MockObject_MockObject
56+ * @var MockObject
5557 */
5658 protected $ flatItemEraser ;
5759
5860 /**
59- * @var \PHPUnit_Framework_MockObject_MockObject
61+ * @var MockObject
6062 */
6163 protected $ flatTableBuilder ;
6264
65+ /**
66+ * @inheritdoc
67+ */
6368 protected function setUp ()
6469 {
6570 $ objectManager = new ObjectManager ($ this );
@@ -70,11 +75,11 @@ protected function setUp()
7075 $ this ->resource = $ this ->createMock (\Magento \Framework \App \ResourceConnection::class);
7176 $ this ->resource ->expects ($ this ->any ())->method ('getConnection ' )
7277 ->with ('default ' )
73- ->will ($ this ->returnValue ( $ this -> connection ) );
78+ ->willReturn ($ this ->connection );
7479 $ this ->storeManager = $ this ->createMock (\Magento \Store \Model \StoreManagerInterface::class);
7580 $ this ->store = $ this ->createMock (\Magento \Store \Model \Store::class);
76- $ this ->store ->expects ($ this ->any ())->method ('getId ' )->will ( $ this -> returnValue ( 'store_id_1 ' ) );
77- $ this ->storeManager ->expects ($ this ->any ())->method ('getStores ' )->will ( $ this -> returnValue ( [$ this ->store ]) );
81+ $ this ->store ->expects ($ this ->any ())->method ('getId ' )->willReturn ( 'store_id_1 ' );
82+ $ this ->storeManager ->expects ($ this ->any ())->method ('getStores ' )->willReturn ( [$ this ->store ]);
7883 $ this ->flatItemEraser = $ this ->createMock (\Magento \Catalog \Model \Indexer \Product \Flat \Action \Eraser::class);
7984 $ this ->flatItemWriter = $ this ->createMock (\Magento \Catalog \Model \Indexer \Product \Flat \Action \Indexer::class);
8085 $ this ->flatTableBuilder = $ this ->createMock (\Magento \Catalog \Model \Indexer \Product \Flat \FlatTableBuilder::class);
@@ -89,9 +94,7 @@ protected function setUp()
8994 ->disableOriginalConstructor ()
9095 ->getMock ();
9196 $ backendMock ->expects ($ this ->any ())->method ('getTable ' )->willReturn ($ attributeTable );
92- $ statusAttributeMock ->expects ($ this ->any ())->method ('getBackend ' )->willReturn (
93- $ backendMock
94- );
97+ $ statusAttributeMock ->expects ($ this ->any ())->method ('getBackend ' )->willReturn ($ backendMock );
9598 $ statusAttributeMock ->expects ($ this ->any ())->method ('getId ' )->willReturn ($ statusId );
9699 $ selectMock = $ this ->getMockBuilder (\Magento \Framework \DB \Select::class)
97100 ->disableOriginalConstructor ()
@@ -102,19 +105,30 @@ protected function setUp()
102105 ['value ' ]
103106 )->willReturnSelf ();
104107 $ selectMock ->expects ($ this ->any ())->method ('where ' )->willReturnSelf ();
108+ $ selectMock ->expects ($ this ->any ())->method ('order ' )->willReturnSelf ();
109+ $ selectMock ->expects ($ this ->any ())->method ('limit ' )->willReturnSelf ();
105110 $ 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 ]));
111+ $ this ->connection ->expects ($ this ->any ())->method ('query ' )->with ($ selectMock )->willReturn ($ pdoMock );
112+ $ pdoMock ->expects ($ this ->any ())->method ('fetchColumn ' )->willReturn ('1 ' );
113+
114+ $ metadataPool = $ this ->createMock (\Magento \Framework \EntityManager \MetadataPool::class);
115+ $ productMetadata = $ this ->getMockBuilder (\Magento \Framework \EntityManager \EntityMetadataInterface::class)
116+ ->getMockForAbstractClass ();
117+ $ metadataPool ->expects ($ this ->any ())->method ('getMetadata ' )->with (ProductInterface::class)
118+ ->willReturn ($ productMetadata );
119+ $ productMetadata ->expects ($ this ->any ())->method ('getLinkField ' )->willReturn ('entity_id ' );
108120
109121 $ this ->model = $ objectManager ->getObject (
110122 \Magento \Catalog \Model \Indexer \Product \Flat \Action \Row::class, [
111- 'resource ' => $ this ->resource ,
112- 'storeManager ' => $ this ->storeManager ,
113- 'productHelper ' => $ this ->productIndexerHelper ,
114- 'flatItemEraser ' => $ this ->flatItemEraser ,
115- 'flatItemWriter ' => $ this ->flatItemWriter ,
123+ 'resource ' => $ this ->resource ,
124+ 'storeManager ' => $ this ->storeManager ,
125+ 'productHelper ' => $ this ->productIndexerHelper ,
126+ 'flatItemEraser ' => $ this ->flatItemEraser ,
127+ 'flatItemWriter ' => $ this ->flatItemWriter ,
116128 'flatTableBuilder ' => $ this ->flatTableBuilder ,
117129 ]);
130+
131+ $ objectManager ->setBackwardCompatibleProperty ($ this ->model , 'metadataPool ' , $ metadataPool );
118132 }
119133
120134 /**
@@ -129,9 +143,9 @@ public function testExecuteWithEmptyId()
129143 public function testExecuteWithNonExistingFlatTablesCreatesTables ()
130144 {
131145 $ this ->productIndexerHelper ->expects ($ this ->any ())->method ('getFlatTableName ' )
132- ->will ( $ this -> returnValue ( 'store_flat_table ' ) );
146+ ->willReturn ( 'store_flat_table ' );
133147 $ this ->connection ->expects ($ this ->any ())->method ('isTableExists ' )->with ('store_flat_table ' )
134- ->will ( $ this -> returnValue ( false ) );
148+ ->willReturn ( false );
135149 $ this ->flatItemEraser ->expects ($ this ->never ())->method ('removeDeletedProducts ' );
136150 $ this ->flatTableBuilder ->expects ($ this ->once ())->method ('build ' )->with ('store_id_1 ' , ['product_id_1 ' ]);
137151 $ this ->flatItemWriter ->expects ($ this ->once ())->method ('write ' )->with ('store_id_1 ' , 'product_id_1 ' );
@@ -141,12 +155,11 @@ public function testExecuteWithNonExistingFlatTablesCreatesTables()
141155 public function testExecuteWithExistingFlatTablesCreatesTables ()
142156 {
143157 $ this ->productIndexerHelper ->expects ($ this ->any ())->method ('getFlatTableName ' )
144- ->will ( $ this -> returnValue ( 'store_flat_table ' ) );
158+ ->willReturn ( 'store_flat_table ' );
145159 $ this ->connection ->expects ($ this ->any ())->method ('isTableExists ' )->with ('store_flat_table ' )
146- ->will ( $ this -> returnValue ( true ) );
160+ ->willReturn ( true );
147161 $ this ->flatItemEraser ->expects ($ this ->once ())->method ('removeDeletedProducts ' );
148162 $ this ->flatTableBuilder ->expects ($ this ->never ())->method ('build ' )->with ('store_id_1 ' , ['product_id_1 ' ]);
149163 $ this ->model ->execute ('product_id_1 ' );
150164 }
151165}
152-
0 commit comments