Skip to content

Commit 96fa0ac

Browse files
committed
Merge remote-tracking branch 'tango/MC-30569' into PR-02-03
2 parents bc35dcc + b130bbb commit 96fa0ac

File tree

4 files changed

+122
-3
lines changed

4 files changed

+122
-3
lines changed

app/code/Magento/Indexer/Console/Command/IndexerReindexCommand.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,8 @@ private function validateSharedIndex($sharedIndex)
256256
$indexer = $this->getIndexerRegistry()->get($indexerId);
257257
/** @var \Magento\Indexer\Model\Indexer\State $state */
258258
$state = $indexer->getState();
259+
$state->setStatus(StateInterface::STATUS_WORKING);
260+
$state->save();
259261
$state->setStatus(StateInterface::STATUS_VALID);
260262
$state->save();
261263
}

app/code/Magento/Indexer/Model/Processor.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
use Magento\Framework\Indexer\IndexerInterfaceFactory;
1111
use Magento\Framework\Indexer\StateInterface;
1212

13+
/**
14+
* Indexer processor
15+
*/
1316
class Processor
1417
{
1518
/**
@@ -70,6 +73,8 @@ public function reindexAllInvalid()
7073
} else {
7174
/** @var \Magento\Indexer\Model\Indexer\State $state */
7275
$state = $indexer->getState();
76+
$state->setStatus(StateInterface::STATUS_WORKING);
77+
$state->save();
7378
$state->setStatus(StateInterface::STATUS_VALID);
7479
$state->save();
7580
}

dev/tests/integration/testsuite/Magento/Indexer/Console/Command/IndexerReindexCommandTest.php

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@
88
namespace Magento\Indexer\Console\Command;
99

1010
use Magento\Framework\ObjectManagerInterface;
11+
use Magento\Indexer\Model\Indexer\CollectionFactory as IndexerCollectionFactory;
1112
use Magento\TestFramework\Helper\Bootstrap;
12-
use PHPUnit_Framework_MockObject_MockObject as Mock;
13+
use PHPUnit\Framework\MockObject\MockObject;
1314
use Symfony\Component\Console\Input\InputInterface;
1415
use Symfony\Component\Console\Output\OutputInterface;
1516

@@ -27,12 +28,12 @@ class IndexerReindexCommandTest extends \PHPUnit\Framework\TestCase
2728
private $objectManager;
2829

2930
/**
30-
* @var InputInterface|Mock
31+
* @var InputInterface|MockObject
3132
*/
3233
private $inputMock;
3334

3435
/**
35-
* @var OutputInterface|Mock
36+
* @var OutputInterface|MockObject
3637
*/
3738
private $outputMock;
3839

@@ -41,6 +42,11 @@ class IndexerReindexCommandTest extends \PHPUnit\Framework\TestCase
4142
*/
4243
private $command;
4344

45+
/**
46+
* @var IndexerCollectionFactory
47+
*/
48+
private $indexerCollectionFactory;
49+
4450
/**
4551
* @inheritdoc
4652
*/
@@ -52,6 +58,7 @@ protected function setUp()
5258
$this->outputMock = $this->getMockBuilder(OutputInterface::class)->getMockForAbstractClass();
5359

5460
$this->command = $this->objectManager->get(IndexerReindexCommand::class);
61+
$this->indexerCollectionFactory = $this->objectManager->create(IndexerCollectionFactory::class);
5562
}
5663

5764
/**
@@ -65,5 +72,19 @@ public function testReindexAll()
6572
$status,
6673
'Index wasn\'t success'
6774
);
75+
76+
$notValidIndexers = [];
77+
$indexers = $this->indexerCollectionFactory->create()->getItems();
78+
foreach ($indexers as $indexer) {
79+
if ($indexer->isValid()) {
80+
continue;
81+
}
82+
83+
$notValidIndexers[] = $indexer->getId();
84+
}
85+
$this->assertEmpty(
86+
$notValidIndexers,
87+
'Following indexers are not valid: ' . implode(', ', $notValidIndexers)
88+
);
6889
}
6990
}
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Indexer\Model;
9+
10+
use Magento\Framework\Indexer\ConfigInterface as IndexerConfig;
11+
use Magento\Framework\Indexer\IndexerInterfaceFactory;
12+
use Magento\Indexer\Model\Indexer\CollectionFactory as IndexerCollectionFactory;
13+
use Magento\TestFramework\Helper\Bootstrap;
14+
15+
/**
16+
* Test for \Magento\Indexer\Model\Processor
17+
*/
18+
class ProcessorTest extends \PHPUnit\Framework\TestCase
19+
{
20+
/**
21+
* @var \Magento\Framework\Indexer\Config\Converter
22+
*/
23+
private $processor;
24+
25+
/**
26+
* @inheritdoc
27+
*/
28+
protected function setUp()
29+
{
30+
$this->processor = Bootstrap::getObjectManager()->create(Processor::class);
31+
}
32+
33+
/**
34+
* @return void
35+
*/
36+
public function testReindexAllInvalid()
37+
{
38+
$indexerConfig = Bootstrap::getObjectManager()->create(IndexerConfig::class);
39+
$indexerFactory = Bootstrap::getObjectManager()->create(IndexerInterfaceFactory::class);
40+
$indexerIds = array_keys($indexerConfig->getIndexers());
41+
42+
foreach ($indexerIds as $indexerId) {
43+
$indexer = $indexerFactory->create()->load($indexerId);
44+
$indexer->invalidate();
45+
}
46+
47+
$this->processor->reindexAllInvalid();
48+
49+
$notValidIndexers = [];
50+
foreach ($indexerIds as $indexerId) {
51+
$indexer = $indexerFactory->create()->load($indexerId);
52+
if ($indexer->isValid()) {
53+
continue;
54+
}
55+
56+
$notValidIndexers[] = $indexer->getId();
57+
}
58+
$this->assertEmpty(
59+
$notValidIndexers,
60+
'Following indexers are not valid: ' . implode(', ', $notValidIndexers)
61+
);
62+
}
63+
64+
/**
65+
* @return void
66+
*/
67+
public function testReindexAll()
68+
{
69+
$indexerCollectionFactory = Bootstrap::getObjectManager()->create(IndexerCollectionFactory::class);
70+
$indexers = $indexerCollectionFactory->create()->getItems();
71+
foreach ($indexers as $indexer) {
72+
$indexer->invalidate();
73+
}
74+
75+
$this->processor->reindexAll();
76+
77+
$notValidIndexers = [];
78+
$indexers = $indexerCollectionFactory->create()->getItems();
79+
foreach ($indexers as $indexer) {
80+
if ($indexer->isValid()) {
81+
continue;
82+
}
83+
84+
$notValidIndexers[] = $indexer->getId();
85+
}
86+
$this->assertEmpty(
87+
$notValidIndexers,
88+
'Following indexers are not valid: ' . implode(', ', $notValidIndexers)
89+
);
90+
}
91+
}

0 commit comments

Comments
 (0)