|
| 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\Catalog\Test\Unit\Model\ResourceModel\Product\Indexer\Eav; |
| 9 | + |
| 10 | +use Magento\Catalog\Model\ResourceModel\Helper; |
| 11 | +use Magento\Catalog\Model\ResourceModel\Product\Indexer\Eav\Source; |
| 12 | +use Magento\Eav\Api\AttributeRepositoryInterface; |
| 13 | +use Magento\Eav\Model\Config; |
| 14 | +use Magento\Framework\Api\SearchCriteriaBuilder; |
| 15 | +use Magento\Framework\App\ResourceConnection; |
| 16 | +use Magento\Framework\DB\Adapter\AdapterInterface; |
| 17 | +use Magento\Framework\EntityManager\EntityMetadataInterface; |
| 18 | +use Magento\Framework\Event\ManagerInterface; |
| 19 | +use Magento\Framework\Indexer\Table\StrategyInterface; |
| 20 | +use Magento\Framework\Model\ResourceModel\Db\Context; |
| 21 | +use Magento\ResourceConnections\DB\Select; |
| 22 | +use PHPUnit\Framework\MockObject\MockObject; |
| 23 | +use PHPUnit\Framework\TestCase; |
| 24 | +use Magento\Framework\EntityManager\MetadataPool; |
| 25 | + |
| 26 | +class SourceTest extends TestCase |
| 27 | +{ |
| 28 | + /** |
| 29 | + * @var Context|MockObject |
| 30 | + */ |
| 31 | + private Context $context; |
| 32 | + |
| 33 | + /** |
| 34 | + * @var StrategyInterface|MockObject |
| 35 | + */ |
| 36 | + private StrategyInterface $tableStrategy; |
| 37 | + |
| 38 | + /** |
| 39 | + * @var Config|MockObject |
| 40 | + */ |
| 41 | + private Config $eavConfig; |
| 42 | + |
| 43 | + /** |
| 44 | + * @var ManagerInterface|MockObject |
| 45 | + */ |
| 46 | + private ManagerInterface $eventManager; |
| 47 | + |
| 48 | + /** |
| 49 | + * @var Helper|MockObject |
| 50 | + */ |
| 51 | + private Helper $resourceHelper; |
| 52 | + |
| 53 | + /** |
| 54 | + * @var AttributeRepositoryInterface|MockObject |
| 55 | + */ |
| 56 | + private AttributeRepositoryInterface $attributeRepository; |
| 57 | + |
| 58 | + /** |
| 59 | + * @var SearchCriteriaBuilder|MockObject |
| 60 | + */ |
| 61 | + private SearchCriteriaBuilder $criteriaBuilder; |
| 62 | + |
| 63 | + /** |
| 64 | + * @var MetadataPool|MockObject |
| 65 | + */ |
| 66 | + private MetadataPool $metadataPool; |
| 67 | + |
| 68 | + /** |
| 69 | + * @var Source |
| 70 | + */ |
| 71 | + private Source $indexer; |
| 72 | + |
| 73 | + /** |
| 74 | + * @return void |
| 75 | + */ |
| 76 | + protected function setUp(): void |
| 77 | + { |
| 78 | + $this->context = $this->createMock(Context::class); |
| 79 | + $this->tableStrategy = $this->createMock(StrategyInterface::class); |
| 80 | + $this->eavConfig = $this->createMock(Config::class); |
| 81 | + $this->eventManager = $this->createMock(ManagerInterface::class); |
| 82 | + $this->resourceHelper = $this->createMock(Helper::class); |
| 83 | + $this->attributeRepository = $this->createMock(AttributeRepositoryInterface::class); |
| 84 | + $this->criteriaBuilder = $this->createMock(SearchCriteriaBuilder::class); |
| 85 | + $this->metadataPool = $this->createMock(MetadataPool::class); |
| 86 | + |
| 87 | + parent::setUp(); |
| 88 | + } |
| 89 | + |
| 90 | + /** |
| 91 | + * @return void |
| 92 | + * @throws \Exception |
| 93 | + */ |
| 94 | + public function testReindexEntities(): void |
| 95 | + { |
| 96 | + $products = [1, 2]; |
| 97 | + $select = $this->createMock(Select::class); |
| 98 | + $select->expects($this->any())->method('from')->willReturn($select); |
| 99 | + $select->expects($this->any())->method('join')->willReturn($select); |
| 100 | + $select->expects($this->any())->method('where')->willReturn($select); |
| 101 | + $select->expects($this->any())->method('joinLeft')->willReturn($select); |
| 102 | + $select->expects($this->any())->method('joinLeft')->willReturn($select); |
| 103 | + $select->expects($this->any())->method('group')->willReturn($select); |
| 104 | + $select->expects($this->any())->method('columns')->willReturn($select); |
| 105 | + $connection = $this->createMock(AdapterInterface::class); |
| 106 | + $connection->expects($this->once())->method('delete'); |
| 107 | + $connection->expects($this->any())->method('select')->willReturn($select); |
| 108 | + $resources = $this->createMock(ResourceConnection::class); |
| 109 | + $resources->expects($this->any()) |
| 110 | + ->method('getConnection') |
| 111 | + ->with('test_connection_name') |
| 112 | + ->willReturn($connection); |
| 113 | + $this->context->expects($this->any())->method('getResources')->willReturn($resources); |
| 114 | + $this->tableStrategy->expects($this->any())->method('getTableName')->willReturn('idx_table'); |
| 115 | + $this->tableStrategy->expects($this->any())->method('getUseIdxTable')->willReturn(true); |
| 116 | + $metadata = $this->createMock(EntityMetadataInterface::class); |
| 117 | + $this->metadataPool->expects($this->any())->method('getMetadata')->willReturn($metadata); |
| 118 | + |
| 119 | + $this->indexer = new Source( |
| 120 | + $this->context, |
| 121 | + $this->tableStrategy, |
| 122 | + $this->eavConfig, |
| 123 | + $this->eventManager, |
| 124 | + $this->resourceHelper, |
| 125 | + 'test_connection_name', |
| 126 | + $this->attributeRepository, |
| 127 | + $this->criteriaBuilder, |
| 128 | + $this->metadataPool |
| 129 | + ); |
| 130 | + $this->indexer->reindexEntities($products); |
| 131 | + } |
| 132 | +} |
0 commit comments