8
8
9
9
namespace Magento \Catalog \Test \Unit \Model \Indexer \Product \Flat \Action ;
10
10
11
+ use Magento \Catalog \Api \Data \ProductInterface ;
11
12
use Magento \Framework \TestFramework \Unit \Helper \ObjectManager ;
13
+ use PHPUnit_Framework_MockObject_MockObject as MockObject ;
12
14
13
15
/**
14
16
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -21,45 +23,48 @@ class RowTest extends \PHPUnit\Framework\TestCase
21
23
protected $ model ;
22
24
23
25
/**
24
- * @var \PHPUnit_Framework_MockObject_MockObject
26
+ * @var MockObject
25
27
*/
26
28
protected $ storeManager ;
27
29
28
30
/**
29
- * @var \PHPUnit_Framework_MockObject_MockObject
31
+ * @var MockObject
30
32
*/
31
33
protected $ store ;
32
34
33
35
/**
34
- * @var \PHPUnit_Framework_MockObject_MockObject
36
+ * @var MockObject
35
37
*/
36
38
protected $ productIndexerHelper ;
37
39
38
40
/**
39
- * @var \PHPUnit_Framework_MockObject_MockObject
41
+ * @var MockObject
40
42
*/
41
43
protected $ resource ;
42
44
43
45
/**
44
- * @var \PHPUnit_Framework_MockObject_MockObject
46
+ * @var MockObject
45
47
*/
46
48
protected $ connection ;
47
49
48
50
/**
49
- * @var \PHPUnit_Framework_MockObject_MockObject
51
+ * @var MockObject
50
52
*/
51
53
protected $ flatItemWriter ;
52
54
53
55
/**
54
- * @var \PHPUnit_Framework_MockObject_MockObject
56
+ * @var MockObject
55
57
*/
56
58
protected $ flatItemEraser ;
57
59
58
60
/**
59
- * @var \PHPUnit_Framework_MockObject_MockObject
61
+ * @var MockObject
60
62
*/
61
63
protected $ flatTableBuilder ;
62
64
65
+ /**
66
+ * @inheritdoc
67
+ */
63
68
protected function setUp ()
64
69
{
65
70
$ objectManager = new ObjectManager ($ this );
@@ -70,11 +75,11 @@ protected function setUp()
70
75
$ this ->resource = $ this ->createMock (\Magento \Framework \App \ResourceConnection::class);
71
76
$ this ->resource ->expects ($ this ->any ())->method ('getConnection ' )
72
77
->with ('default ' )
73
- ->will ($ this ->returnValue ( $ this -> connection ) );
78
+ ->willReturn ($ this ->connection );
74
79
$ this ->storeManager = $ this ->createMock (\Magento \Store \Model \StoreManagerInterface::class);
75
80
$ 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 ]);
78
83
$ this ->flatItemEraser = $ this ->createMock (\Magento \Catalog \Model \Indexer \Product \Flat \Action \Eraser::class);
79
84
$ this ->flatItemWriter = $ this ->createMock (\Magento \Catalog \Model \Indexer \Product \Flat \Action \Indexer::class);
80
85
$ this ->flatTableBuilder = $ this ->createMock (\Magento \Catalog \Model \Indexer \Product \Flat \FlatTableBuilder::class);
@@ -89,9 +94,7 @@ protected function setUp()
89
94
->disableOriginalConstructor ()
90
95
->getMock ();
91
96
$ 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 );
95
98
$ statusAttributeMock ->expects ($ this ->any ())->method ('getId ' )->willReturn ($ statusId );
96
99
$ selectMock = $ this ->getMockBuilder (\Magento \Framework \DB \Select::class)
97
100
->disableOriginalConstructor ()
@@ -102,19 +105,30 @@ protected function setUp()
102
105
['value ' ]
103
106
)->willReturnSelf ();
104
107
$ selectMock ->expects ($ this ->any ())->method ('where ' )->willReturnSelf ();
108
+ $ selectMock ->expects ($ this ->any ())->method ('order ' )->willReturnSelf ();
109
+ $ selectMock ->expects ($ this ->any ())->method ('limit ' )->willReturnSelf ();
105
110
$ 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 ' );
108
120
109
121
$ this ->model = $ objectManager ->getObject (
110
122
\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 ,
116
128
'flatTableBuilder ' => $ this ->flatTableBuilder ,
117
129
]);
130
+
131
+ $ objectManager ->setBackwardCompatibleProperty ($ this ->model , 'metadataPool ' , $ metadataPool );
118
132
}
119
133
120
134
/**
@@ -129,9 +143,9 @@ public function testExecuteWithEmptyId()
129
143
public function testExecuteWithNonExistingFlatTablesCreatesTables ()
130
144
{
131
145
$ this ->productIndexerHelper ->expects ($ this ->any ())->method ('getFlatTableName ' )
132
- ->will ( $ this -> returnValue ( 'store_flat_table ' ) );
146
+ ->willReturn ( 'store_flat_table ' );
133
147
$ this ->connection ->expects ($ this ->any ())->method ('isTableExists ' )->with ('store_flat_table ' )
134
- ->will ( $ this -> returnValue ( false ) );
148
+ ->willReturn ( false );
135
149
$ this ->flatItemEraser ->expects ($ this ->never ())->method ('removeDeletedProducts ' );
136
150
$ this ->flatTableBuilder ->expects ($ this ->once ())->method ('build ' )->with ('store_id_1 ' , ['product_id_1 ' ]);
137
151
$ this ->flatItemWriter ->expects ($ this ->once ())->method ('write ' )->with ('store_id_1 ' , 'product_id_1 ' );
@@ -141,12 +155,11 @@ public function testExecuteWithNonExistingFlatTablesCreatesTables()
141
155
public function testExecuteWithExistingFlatTablesCreatesTables ()
142
156
{
143
157
$ this ->productIndexerHelper ->expects ($ this ->any ())->method ('getFlatTableName ' )
144
- ->will ( $ this -> returnValue ( 'store_flat_table ' ) );
158
+ ->willReturn ( 'store_flat_table ' );
145
159
$ this ->connection ->expects ($ this ->any ())->method ('isTableExists ' )->with ('store_flat_table ' )
146
- ->will ( $ this -> returnValue ( true ) );
160
+ ->willReturn ( true );
147
161
$ this ->flatItemEraser ->expects ($ this ->once ())->method ('removeDeletedProducts ' );
148
162
$ this ->flatTableBuilder ->expects ($ this ->never ())->method ('build ' )->with ('store_id_1 ' , ['product_id_1 ' ]);
149
163
$ this ->model ->execute ('product_id_1 ' );
150
164
}
151
165
}
152
-
0 commit comments