|
| 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