7
7
8
8
namespace Magento \Elasticsearch \Test \Unit \Model \Indexer ;
9
9
10
+ use Magento \CatalogSearch \Model \Indexer \Fulltext \Processor ;
10
11
use Magento \AdvancedSearch \Model \Client \ClientInterface ;
11
12
use Magento \Elasticsearch \Model \Adapter \Elasticsearch ;
12
13
use Magento \Elasticsearch \Model \Adapter \Index \IndexNameResolver ;
13
14
use Magento \Elasticsearch \Model \Indexer \IndexerHandler ;
14
15
use Magento \Framework \App \ScopeInterface ;
15
16
use Magento \Framework \App \ScopeResolverInterface ;
17
+ use Magento \Framework \Indexer \IndexerInterface ;
16
18
use Magento \Framework \Indexer \IndexStructureInterface ;
17
19
use Magento \Framework \Indexer \SaveHandler \Batch ;
18
20
use Magento \Framework \Search \Request \Dimension ;
19
21
use Magento \Framework \TestFramework \Unit \Helper \ObjectManager as ObjectManagerHelper ;
20
22
use PHPUnit \Framework \MockObject \MockObject ;
21
23
use PHPUnit \Framework \TestCase ;
24
+ use Magento \Framework \App \DeploymentConfig ;
25
+ use Magento \Framework \Indexer \CacheContext ;
22
26
23
27
/**
24
28
* Test for \Magento\Elasticsearch\Model\Indexer\IndexerHandler
@@ -71,6 +75,26 @@ class IndexerHandlerTest extends TestCase
71
75
*/
72
76
private $ scopeInterface ;
73
77
78
+ /**
79
+ * @var Processor|MockObject
80
+ */
81
+ private $ processor ;
82
+
83
+ /**
84
+ * @var IndexerInterface|MockObject
85
+ */
86
+ private $ indexer ;
87
+
88
+ /**
89
+ * @var CacheContext|MockObject
90
+ */
91
+ private $ cacheContext ;
92
+
93
+ /**
94
+ * @var DeploymentConfig|MockObject
95
+ */
96
+ private $ deploymentConfig ;
97
+
74
98
/**
75
99
* Set up test environment.
76
100
*
@@ -117,26 +141,42 @@ protected function setUp(): void
117
141
false
118
142
);
119
143
144
+ $ this ->processor = $ this ->getMockBuilder (Processor::class)
145
+ ->disableOriginalConstructor ()
146
+ ->getMock ();
147
+ $ this ->indexer = $ this ->getMockBuilder (IndexerInterface::class)
148
+ ->disableOriginalConstructor ()
149
+ ->getMockForAbstractClass ();
150
+ $ this ->processor ->expects ($ this ->any ())
151
+ ->method ('getIndexer ' )
152
+ ->willReturn ($ this ->indexer );
153
+
154
+ $ this ->deploymentConfig = $ this ->getMockBuilder (DeploymentConfig::class)
155
+ ->disableOriginalConstructor ()
156
+ ->getMock ();
157
+
158
+ $ this ->cacheContext = $ this ->getMockBuilder (CacheContext::class)
159
+ ->disableOriginalConstructor ()
160
+ ->getMock ();
161
+
120
162
$ this ->scopeInterface = $ this ->getMockForAbstractClass (
121
163
ScopeInterface::class,
122
164
[],
123
165
'' ,
124
166
false
125
167
);
126
168
127
- $ objectManager = new ObjectManagerHelper ($ this );
128
-
129
- $ this ->model = $ objectManager ->getObject (
130
- IndexerHandler::class,
131
- [
132
- 'indexStructure ' => $ this ->indexStructure ,
133
- 'adapter ' => $ this ->adapter ,
134
- 'indexNameResolver ' => $ this ->indexNameResolver ,
135
- 'batch ' => $ this ->batch ,
136
- 'data ' => ['indexer_id ' => 'catalogsearch_fulltext ' ],
137
- 500 ,
138
- 'scopeResolver ' => $ this ->scopeResolver
139
- ]
169
+ $ this ->model = new IndexerHandler (
170
+ $ this ->indexStructure ,
171
+ $ this ->adapter ,
172
+ $ this ->indexNameResolver ,
173
+ $ this ->batch ,
174
+ $ this ->scopeResolver ,
175
+ ['indexer_id ' => 'catalogsearch_fulltext ' ],
176
+ 500 ,
177
+ $ this ->deploymentConfig ,
178
+ $ this ->cacheContext ,
179
+ $ this ->processor
140
180
);
141
181
}
142
182
@@ -182,7 +222,8 @@ public function testSaveIndex()
182
222
{
183
223
$ dimensionValue = 3 ;
184
224
$ documentId = 123 ;
185
- $ documents = new \ArrayIterator ([$ documentId ]);
225
+ $ document = ['entity_id ' => $ documentId , 'category_ids ' => [1 , 2 ]];
226
+ $ documents = new \ArrayIterator ([$ document ]);
186
227
187
228
$ dimension = $ this ->getMockBuilder (Dimension::class)
188
229
->disableOriginalConstructor ()
@@ -199,17 +240,23 @@ public function testSaveIndex()
199
240
$ this ->adapter ->expects ($ this ->once ())
200
241
->method ('prepareDocsPerStore ' )
201
242
->with ([], $ dimensionValue )
202
- ->willReturn ([$ documentId ]);
243
+ ->willReturn ([$ document ]);
203
244
$ this ->adapter ->expects ($ this ->once ())
204
245
->method ('addDocs ' )
205
- ->with ([$ documentId ]);
246
+ ->with ([$ document ]);
206
247
$ this ->scopeResolver ->expects ($ this ->once ())
207
248
->method ('getScope ' )
208
249
->willReturn ($ this ->scopeInterface );
209
250
$ this ->scopeInterface ->expects ($ this ->once ())
210
251
->method ('getId ' )
211
252
->willReturn ($ dimensionValue );
212
253
254
+ $ this ->indexer ->expects ($ this ->once ())
255
+ ->method ('isScheduled ' )
256
+ ->willReturn (true );
257
+ $ this ->cacheContext ->expects ($ this ->once ())
258
+ ->method ('registerEntities ' );
259
+
213
260
$ result = $ this ->model ->saveIndex ([$ dimension ], $ documents );
214
261
215
262
$ this ->assertEquals ($ this ->model , $ result );
0 commit comments