18
18
use Magento \Indexer \Model \Config ;
19
19
use Magento \Indexer \Model \Processor \MakeSharedIndexValid ;
20
20
use PHPUnit \Framework \MockObject \MockObject ;
21
+ use Psr \Log \LoggerInterface ;
21
22
use Symfony \Component \Console \Tester \CommandTester ;
22
23
23
24
/**
@@ -58,6 +59,11 @@ class IndexerReindexCommandTest extends AbstractIndexerCommandCommonSetup
58
59
*/
59
60
private $ objectManagerHelper ;
60
61
62
+ /**
63
+ * @var LoggerInterface|MockObject
64
+ */
65
+ private $ loggerMock ;
66
+
61
67
/**
62
68
* Set up
63
69
*/
@@ -74,6 +80,7 @@ protected function setUp(): void
74
80
$ this ->dependencyInfoProviderMock = $ this ->objectManagerHelper ->getObject (DependencyInfoProvider::class, [
75
81
'config ' => $ this ->configMock ,
76
82
]);
83
+ $ this ->loggerMock = $ this ->getMockForAbstractClass (LoggerInterface::class);
77
84
parent ::setUp ();
78
85
}
79
86
@@ -93,7 +100,13 @@ protected function getObjectManagerReturnValueMap()
93
100
public function testGetOptions ()
94
101
{
95
102
$ this ->stateMock ->expects ($ this ->never ())->method ('setAreaCode ' );
96
- $ this ->command = new IndexerReindexCommand ($ this ->objectManagerFactory );
103
+ $ this ->command = new IndexerReindexCommand (
104
+ $ this ->objectManagerFactory ,
105
+ $ this ->indexerRegistryMock ,
106
+ $ this ->dependencyInfoProviderMock ,
107
+ $ this ->makeSharedValidMock ,
108
+ $ this ->loggerMock
109
+ );
97
110
$ optionsList = $ this ->command ->getInputList ();
98
111
$ this ->assertCount (1 , $ optionsList );
99
112
$ this ->assertSame ('index ' , $ optionsList [0 ]->getName ());
@@ -119,7 +132,13 @@ public function testExecuteAll()
119
132
]
120
133
);
121
134
$ this ->indexerFactory ->expects ($ this ->never ())->method ('create ' );
122
- $ this ->command = new IndexerReindexCommand ($ this ->objectManagerFactory );
135
+ $ this ->command = new IndexerReindexCommand (
136
+ $ this ->objectManagerFactory ,
137
+ $ this ->indexerRegistryMock ,
138
+ $ this ->dependencyInfoProviderMock ,
139
+ $ this ->makeSharedValidMock ,
140
+ $ this ->loggerMock
141
+ );
123
142
$ commandTester = new CommandTester ($ this ->command );
124
143
$ commandTester ->execute ([]);
125
144
$ actualValue = $ commandTester ->getDisplay ();
@@ -162,7 +181,7 @@ public function testExecuteWithIndex(
162
181
$ indexer ->method ('getState ' )
163
182
->willReturn (
164
183
$ this ->getStateMock (
165
- ['loadByIndexer ' , 'setStatus ' , ' save ' ],
184
+ ['loadByIndexer ' , 'setStatus ' ],
166
185
$ states [$ indexer ->getId ()] ?? []
167
186
)
168
187
);
@@ -181,7 +200,7 @@ public function testExecuteWithIndex(
181
200
->withConsecutive (...$ executedSharedIndexers )
182
201
->willReturn ($ emptyIndexer );
183
202
$ emptyIndexer ->method ('getState ' )
184
- ->willReturn ($ this ->getStateMock (['setStatus ' , ' save ' ]));
203
+ ->willReturn ($ this ->getStateMock (['setStatus ' ]));
185
204
186
205
$ this ->makeSharedValidMock = $ this ->objectManagerHelper ->getObject (MakeSharedIndexValid::class, [
187
206
'config ' => $ this ->configMock ,
@@ -193,7 +212,8 @@ public function testExecuteWithIndex(
193
212
$ this ->objectManagerFactory ,
194
213
$ this ->indexerRegistryMock ,
195
214
$ this ->dependencyInfoProviderMock ,
196
- $ this ->makeSharedValidMock
215
+ $ this ->makeSharedValidMock ,
216
+ $ this ->loggerMock
197
217
);
198
218
199
219
$ commandTester = new CommandTester ($ this ->command );
@@ -249,7 +269,8 @@ private function getStateMock(array $methods = null, array $data = [])
249
269
{
250
270
/** @var MockObject|StateInterface $state */
251
271
$ state = $ this ->getMockBuilder (StateInterface::class)
252
- ->setMethods ($ methods )
272
+ ->addMethods (['save ' ])
273
+ ->onlyMethods ($ methods )
253
274
->disableOriginalConstructor ()
254
275
->getMockForAbstractClass ();
255
276
$ state ->method ('getStatus ' )
@@ -261,7 +282,7 @@ private function getStateMock(array $methods = null, array $data = [])
261
282
* @return array
262
283
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
263
284
*/
264
- public function executeWithIndexDataProvider ()
285
+ public static function executeWithIndexDataProvider ()
265
286
{
266
287
return [
267
288
'Without dependencies ' => [
@@ -297,9 +318,9 @@ public function executeWithIndexDataProvider()
297
318
],
298
319
],
299
320
'expected_reindex_all_calls ' => [
300
- 'indexer_1 ' => $ this -> once (),
301
- 'indexer_2 ' => $ this -> never (),
302
- 'indexer_3 ' => $ this -> never (),
321
+ 'indexer_1 ' => self :: once (),
322
+ 'indexer_2 ' => self :: never (),
323
+ 'indexer_3 ' => self :: never (),
303
324
],
304
325
'executed_indexers ' => ['indexer_1 ' ],
305
326
'executed_shared_indexers ' => [],
@@ -355,11 +376,11 @@ public function executeWithIndexDataProvider()
355
376
],
356
377
],
357
378
'expected_reindex_all_calls ' => [
358
- 'indexer_1 ' => $ this -> once (),
359
- 'indexer_2 ' => $ this -> never (),
360
- 'indexer_3 ' => $ this -> once (),
361
- 'indexer_4 ' => $ this -> never (),
362
- 'indexer_5 ' => $ this -> once (),
379
+ 'indexer_1 ' => self :: once (),
380
+ 'indexer_2 ' => self :: never (),
381
+ 'indexer_3 ' => self :: once (),
382
+ 'indexer_4 ' => self :: never (),
383
+ 'indexer_5 ' => self :: once (),
363
384
],
364
385
'executed_indexers ' => ['indexer_3 ' , 'indexer_1 ' , 'indexer_5 ' ],
365
386
'executed_shared_indexers ' => [['indexer_2 ' ], ['indexer_3 ' ]],
@@ -413,11 +434,11 @@ public function executeWithIndexDataProvider()
413
434
],
414
435
],
415
436
'expected_reindex_all_calls ' => [
416
- 'indexer_1 ' => $ this -> once (),
417
- 'indexer_2 ' => $ this -> never (),
418
- 'indexer_3 ' => $ this -> once (),
419
- 'indexer_4 ' => $ this -> once (),
420
- 'indexer_5 ' => $ this -> once (),
437
+ 'indexer_1 ' => self :: once (),
438
+ 'indexer_2 ' => self :: never (),
439
+ 'indexer_3 ' => self :: once (),
440
+ 'indexer_4 ' => self :: once (),
441
+ 'indexer_5 ' => self :: once (),
421
442
],
422
443
'executed_indexers ' => ['indexer_1 ' , 'indexer_4 ' , 'indexer_3 ' , 'indexer_5 ' ],
423
444
'executed_shared_indexers ' => [],
@@ -436,7 +457,13 @@ public function testExecuteWithException()
436
457
->method ('reindexAll ' )
437
458
->willThrowException (new \Exception ());
438
459
$ this ->initIndexerCollectionByItems ([$ indexerOne ]);
439
- $ this ->command = new IndexerReindexCommand ($ this ->objectManagerFactory );
460
+ $ this ->command = new IndexerReindexCommand (
461
+ $ this ->objectManagerFactory ,
462
+ $ this ->indexerRegistryMock ,
463
+ $ this ->dependencyInfoProviderMock ,
464
+ $ this ->makeSharedValidMock ,
465
+ $ this ->loggerMock
466
+ );
440
467
$ commandTester = new CommandTester ($ this ->command );
441
468
$ commandTester ->execute (['index ' => ['indexer_1 ' ]]);
442
469
$ actualValue = $ commandTester ->getDisplay ();
@@ -478,7 +505,13 @@ function ($item) {
478
505
)
479
506
)
480
507
);
481
- $ this ->command = new IndexerReindexCommand ($ this ->objectManagerFactory );
508
+ $ this ->command = new IndexerReindexCommand (
509
+ $ this ->objectManagerFactory ,
510
+ $ this ->indexerRegistryMock ,
511
+ $ this ->dependencyInfoProviderMock ,
512
+ $ this ->makeSharedValidMock ,
513
+ $ this ->loggerMock
514
+ );
482
515
$ commandTester = new CommandTester ($ this ->command );
483
516
$ commandTester ->execute (['index ' => $ inputIndexers ]);
484
517
$ this ->assertSame (Cli::RETURN_FAILURE , $ commandTester ->getStatusCode ());
0 commit comments