5
5
*/
6
6
namespace Magento \CatalogSearch \Test \Unit \Model \Indexer ;
7
7
8
- use Magento \Framework \DB \Adapter \Pdo \Mysql ;
9
- use Magento \Framework \EntityManager \EntityMetadata ;
10
8
use Magento \Framework \Search \Request \Dimension ;
11
9
use Magento \Framework \Search \Request \DimensionFactory ;
12
10
use Magento \Framework \TestFramework \Unit \Helper \ObjectManager as ObjectManagerHelper ;
@@ -56,13 +54,6 @@ class FulltextTest extends \PHPUnit_Framework_TestCase
56
54
*/
57
55
private $ indexSwitcher ;
58
56
59
- /**
60
- * Holder for MetadataPool mock instance.
61
- *
62
- * @var \Magento\Framework\EntityManager\MetadataPool|\PHPUnit_Framework_MockObject_MockObject
63
- */
64
- private $ metadataPool ;
65
-
66
57
protected function setUp ()
67
58
{
68
59
$ this ->fullAction = $ this ->getClassMock (\Magento \CatalogSearch \Model \Indexer \Fulltext \Action \Full::class);
@@ -104,10 +95,6 @@ protected function setUp()
104
95
->setMethods (['switchIndex ' ])
105
96
->getMock ();
106
97
107
- $ this ->metadataPool = $ this ->getMockBuilder (\Magento \Framework \EntityManager \MetadataPool::class)
108
- ->disableOriginalConstructor ()
109
- ->getMock ();
110
-
111
98
$ objectManagerHelper = new ObjectManagerHelper ($ this );
112
99
$ this ->model = $ objectManagerHelper ->getObject (
113
100
\Magento \CatalogSearch \Model \Indexer \Fulltext::class,
@@ -122,7 +109,6 @@ protected function setUp()
122
109
'indexSwitcher ' => $ this ->indexSwitcher ,
123
110
]
124
111
);
125
- $ objectManagerHelper ->setBackwardCompatibleProperty ($ this ->model , 'metadataPool ' , $ this ->metadataPool );
126
112
}
127
113
128
114
/**
@@ -139,13 +125,15 @@ public function testExecute()
139
125
$ ids = [1 , 2 , 3 ];
140
126
$ stores = [0 => 'Store 1 ' , 1 => 'Store 2 ' ];
141
127
$ indexData = new \ArrayObject ([]);
128
+ $ this ->fulltextResource ->expects ($ this ->exactly (2 ))
129
+ ->method ('getRelationsByChild ' )
130
+ ->willReturn ($ ids );
142
131
$ this ->storeManager ->expects ($ this ->once ())->method ('getStores ' )->willReturn ($ stores );
143
132
$ this ->saveHandler ->expects ($ this ->exactly (count ($ stores )))->method ('deleteIndex ' );
144
133
$ this ->saveHandler ->expects ($ this ->exactly (2 ))->method ('saveIndex ' );
145
134
$ this ->fullAction ->expects ($ this ->exactly (2 ))
146
135
->method ('rebuildStoreIndex ' )
147
136
->willReturn (new \ArrayObject ([$ indexData , $ indexData ]));
148
- $ this ->mockGetRelationsByChild ($ ids );
149
137
150
138
$ this ->model ->execute ($ ids );
151
139
}
@@ -196,13 +184,15 @@ public function testExecuteList()
196
184
$ ids = [1 , 2 , 3 ];
197
185
$ stores = [0 => 'Store 1 ' , 1 => 'Store 2 ' ];
198
186
$ indexData = new \ArrayObject ([]);
187
+ $ this ->fulltextResource ->expects ($ this ->exactly (2 ))
188
+ ->method ('getRelationsByChild ' )
189
+ ->willReturn ($ ids );
199
190
$ this ->storeManager ->expects ($ this ->once ())->method ('getStores ' )->willReturn ($ stores );
200
191
$ this ->saveHandler ->expects ($ this ->exactly (count ($ stores )))->method ('deleteIndex ' );
201
192
$ this ->saveHandler ->expects ($ this ->exactly (2 ))->method ('saveIndex ' );
202
193
$ this ->fullAction ->expects ($ this ->exactly (2 ))
203
194
->method ('rebuildStoreIndex ' )
204
195
->willReturn (new \ArrayObject ([$ indexData , $ indexData ]));
205
- $ this ->mockGetRelationsByChild ($ ids );
206
196
207
197
$ this ->model ->executeList ($ ids );
208
198
}
@@ -212,90 +202,16 @@ public function testExecuteRow()
212
202
$ id = 1 ;
213
203
$ stores = [0 => 'Store 1 ' , 1 => 'Store 2 ' ];
214
204
$ indexData = new \ArrayObject ([]);
205
+ $ this ->fulltextResource ->expects ($ this ->exactly (2 ))
206
+ ->method ('getRelationsByChild ' )
207
+ ->willReturn ([$ id ]);
215
208
$ this ->storeManager ->expects ($ this ->once ())->method ('getStores ' )->willReturn ($ stores );
216
209
$ this ->saveHandler ->expects ($ this ->exactly (count ($ stores )))->method ('deleteIndex ' );
217
210
$ this ->saveHandler ->expects ($ this ->exactly (2 ))->method ('saveIndex ' );
218
211
$ this ->fullAction ->expects ($ this ->exactly (2 ))
219
212
->method ('rebuildStoreIndex ' )
220
213
->willReturn (new \ArrayObject ([$ indexData , $ indexData ]));
221
- $ this ->mockGetRelationsByChild ([$ id ]);
222
214
223
215
$ this ->model ->executeRow ($ id );
224
216
}
225
-
226
- /**
227
- * Mock getRelationsByChild() method.
228
- *
229
- * @param array $ids
230
- * @return void
231
- */
232
- private function mockGetRelationsByChild (array $ ids )
233
- {
234
- $ testTable1 = 'testTable1 ' ;
235
- $ testTable2 = 'testTable2 ' ;
236
- $ fieldForParent = 'testLinkField ' ;
237
-
238
- $ metadata = $ this ->getMockBuilder (EntityMetadata::class)
239
- ->disableOriginalConstructor ()
240
- ->getMock ();
241
- $ metadata ->expects ($ this ->exactly (2 ))
242
- ->method ('getLinkField ' )
243
- ->willReturn ($ fieldForParent );
244
-
245
- $ select = $ this ->getMockBuilder (\Magento \Framework \DB \Select::class)
246
- ->disableOriginalConstructor ()
247
- ->getMock ();
248
- $ select ->expects ($ this ->exactly (2 ))
249
- ->method ('from ' )
250
- ->with (['relation ' => $ testTable1 ])
251
- ->willReturnSelf ();
252
- $ select ->expects ($ this ->exactly (2 ))
253
- ->method ('distinct ' )
254
- ->with (true )
255
- ->willReturnSelf ();
256
- $ select ->expects ($ this ->exactly (2 ))
257
- ->method ('where ' )
258
- ->with ('relation.child_id IN (?) ' , $ ids )
259
- ->willReturnSelf ();
260
- $ select ->expects ($ this ->exactly (2 ))
261
- ->method ('join ' )
262
- ->with (
263
- ['cpe ' => $ testTable2 ],
264
- 'cpe. ' . $ fieldForParent . ' = relation.parent_id ' ,
265
- ['cpe.entity_id ' ]
266
- )->willReturnSelf ();
267
-
268
- $ connection = $ this ->getMockBuilder (Mysql::class)
269
- ->disableOriginalConstructor ()
270
- ->getMock ();
271
- $ connection ->expects ($ this ->exactly (2 ))
272
- ->method ('select ' )
273
- ->willReturn ($ select );
274
- $ connection ->expects ($ this ->exactly (2 ))
275
- ->method ('fetchCol ' )
276
- ->with ($ select )
277
- ->willReturn ($ ids );
278
-
279
- $ this ->fulltextResource ->expects ($ this ->exactly (2 ))
280
- ->method ('getConnection ' )
281
- ->willReturn ($ connection );
282
- $ this ->fulltextResource ->expects ($ this ->exactly (4 ))
283
- ->method ('getTable ' )
284
- ->withConsecutive (
285
- ['catalog_product_relation ' ],
286
- ['catalog_product_entity ' ],
287
- ['catalog_product_relation ' ],
288
- ['catalog_product_entity ' ]
289
- )
290
- ->will ($ this ->onConsecutiveCalls (
291
- $ testTable1 ,
292
- $ testTable2 ,
293
- $ testTable1 ,
294
- $ testTable2
295
- ));
296
- $ this ->metadataPool ->expects ($ this ->exactly (2 ))
297
- ->method ('getMetadata ' )
298
- ->with (\Magento \Catalog \Api \Data \ProductInterface::class)
299
- ->willReturn ($ metadata );
300
- }
301
217
}
0 commit comments