|
| 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\Indexer\Product\Price; |
| 9 | + |
| 10 | +use Magento\Catalog\Helper\Data; |
| 11 | +use Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\CustomOptionPriceModifier; |
| 12 | +use Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\IndexTableStructure; |
| 13 | +use Magento\Framework\App\ResourceConnection; |
| 14 | +use Magento\Framework\DB\Adapter\AdapterInterface; |
| 15 | +use Magento\Framework\DB\Select; |
| 16 | +use Magento\Framework\DB\Sql\ColumnValueExpressionFactory; |
| 17 | +use Magento\Framework\EntityManager\EntityMetadataInterface; |
| 18 | +use Magento\Framework\EntityManager\MetadataPool; |
| 19 | +use Magento\Framework\Indexer\Table\StrategyInterface; |
| 20 | +use PHPUnit\Framework\MockObject\MockObject; |
| 21 | +use PHPUnit\Framework\TestCase; |
| 22 | + |
| 23 | +class CustomOptionPriceModifierTest extends TestCase |
| 24 | +{ |
| 25 | + /** |
| 26 | + * @var ResourceConnection|MockObject |
| 27 | + */ |
| 28 | + private ResourceConnection $resource; |
| 29 | + |
| 30 | + /** |
| 31 | + * @var MetadataPool|MockObject |
| 32 | + */ |
| 33 | + private MetadataPool $metadataPool; |
| 34 | + |
| 35 | + /** |
| 36 | + * @var ColumnValueExpressionFactory|MockObject |
| 37 | + */ |
| 38 | + private ColumnValueExpressionFactory $columnValueExpressionFactory; |
| 39 | + |
| 40 | + /** |
| 41 | + * @var Data|MockObject |
| 42 | + */ |
| 43 | + private Data $dataHelper; |
| 44 | + |
| 45 | + /** |
| 46 | + * @var StrategyInterface|MockObject |
| 47 | + */ |
| 48 | + private StrategyInterface $tableStrategy; |
| 49 | + |
| 50 | + /** |
| 51 | + * @var CustomOptionPriceModifier |
| 52 | + */ |
| 53 | + private CustomOptionPriceModifier $priceModifier; |
| 54 | + |
| 55 | + /** |
| 56 | + * @return void |
| 57 | + */ |
| 58 | + protected function setUp(): void |
| 59 | + { |
| 60 | + $this->resource = $this->createMock(ResourceConnection::class); |
| 61 | + $this->metadataPool = $this->createMock(MetadataPool::class); |
| 62 | + $this->columnValueExpressionFactory = $this->createMock(ColumnValueExpressionFactory::class); |
| 63 | + $this->dataHelper = $this->createMock(Data::class); |
| 64 | + $this->tableStrategy = $this->createMock(StrategyInterface::class); |
| 65 | + $this->priceModifier = new CustomOptionPriceModifier( |
| 66 | + $this->resource, |
| 67 | + $this->metadataPool, |
| 68 | + $this->columnValueExpressionFactory, |
| 69 | + $this->dataHelper, |
| 70 | + $this->tableStrategy |
| 71 | + ); |
| 72 | + |
| 73 | + parent::setUp(); |
| 74 | + } |
| 75 | + |
| 76 | + /** |
| 77 | + * @return void |
| 78 | + * @throws \Exception |
| 79 | + */ |
| 80 | + public function testModifyPrice(): void |
| 81 | + { |
| 82 | + $priceTable = $this->createMock(IndexTableStructure::class); |
| 83 | + $priceTable->expects($this->exactly(2))->method('getTableName')->willReturn('temporary_table_name'); |
| 84 | + |
| 85 | + $select = $this->createMock(Select::class); |
| 86 | + $select->expects($this->any())->method('from')->willReturn($select); |
| 87 | + $select->expects($this->any())->method('join')->willReturn($select); |
| 88 | + $select->expects($this->any())->method('group')->willReturn($select); |
| 89 | + $select->expects($this->any())->method('columns')->willReturn($select); |
| 90 | + |
| 91 | + $connection = $this->createMock(AdapterInterface::class); |
| 92 | + $connection->expects($this->exactly(2))->method('delete'); |
| 93 | + $connection->expects($this->any())->method('select')->willReturn($select); |
| 94 | + $connection->expects($this->any())->method('fetchRow')->willReturn(['exists']); |
| 95 | + $connection->expects($this->exactly(4))->method('query'); |
| 96 | + $connection->expects($this->exactly(2))->method('dropTemporaryTable'); |
| 97 | + $this->resource->expects($this->any())->method('getConnection')->willReturn($connection); |
| 98 | + $this->resource->expects($this->any())->method('getTableName')->willReturn('table'); |
| 99 | + $this->tableStrategy->expects($this->any()) |
| 100 | + ->method('getTableName') |
| 101 | + ->willReturn('table_name'); |
| 102 | + |
| 103 | + $metadata = $this->createMock(EntityMetadataInterface::class); |
| 104 | + $this->metadataPool->expects($this->any())->method('getMetadata')->willReturn($metadata); |
| 105 | + $this->dataHelper->expects($this->once())->method('isPriceGlobal')->willReturn(true); |
| 106 | + |
| 107 | + $this->priceModifier->modifyPrice($priceTable); |
| 108 | + } |
| 109 | +} |
0 commit comments