|
7 | 7 |
|
8 | 8 | namespace Magento\Catalog\Test\Unit\Model\Indexer\Product\Price\Action;
|
9 | 9 |
|
| 10 | +use Magento\Store\Model\StoreManagerInterface; |
| 11 | +use Magento\Directory\Model\CurrencyFactory; |
| 12 | +use Magento\Catalog\Model\Product\Type; |
| 13 | +use Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\Factory; |
| 14 | +use Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\DefaultPrice; |
| 15 | +use Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\TierPrice; |
| 16 | +use Magento\Catalog\Model\Indexer\Product\Price\DimensionCollectionFactory; |
| 17 | +use Magento\Catalog\Model\Indexer\Product\Price\TableMaintainer; |
10 | 18 | use Magento\Catalog\Model\Indexer\Product\Price\Action\Rows;
|
11 |
| -use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; |
| 19 | +use Magento\Framework\App\Config\ScopeConfigInterface; |
| 20 | +use Magento\Framework\Stdlib\DateTime; |
| 21 | +use Magento\Framework\Stdlib\DateTime\TimezoneInterface; |
| 22 | +use Magento\Framework\DB\Adapter\AdapterInterface; |
| 23 | +use Magento\Framework\DB\Select; |
| 24 | +use Magento\Framework\Indexer\MultiDimensionProvider; |
12 | 25 | use PHPUnit\Framework\TestCase;
|
| 26 | +use PHPUnit\Framework\MockObject\MockObject; |
13 | 27 |
|
| 28 | +/** |
| 29 | + * Test coverage for the rows action |
| 30 | + * |
| 31 | + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) to preserve compatibility with parent class |
| 32 | + */ |
14 | 33 | class RowsTest extends TestCase
|
15 | 34 | {
|
16 | 35 | /**
|
17 | 36 | * @var Rows
|
18 | 37 | */
|
19 |
| - protected $_model; |
| 38 | + private $actionRows; |
| 39 | + |
| 40 | + /** |
| 41 | + * @var ScopeConfigInterface|MockObject |
| 42 | + */ |
| 43 | + private $config; |
| 44 | + |
| 45 | + /** |
| 46 | + * @var StoreManagerInterface|MockObject |
| 47 | + */ |
| 48 | + private $storeManager; |
| 49 | + |
| 50 | + /** |
| 51 | + * @var CurrencyFactory|MockObject |
| 52 | + */ |
| 53 | + private $currencyFactory; |
| 54 | + |
| 55 | + /** |
| 56 | + * @var TimezoneInterface|MockObject |
| 57 | + */ |
| 58 | + private $localeDate; |
| 59 | + |
| 60 | + /** |
| 61 | + * @var DateTime|MockObject |
| 62 | + */ |
| 63 | + private $dateTime; |
| 64 | + |
| 65 | + /** |
| 66 | + * @var Type|MockObject |
| 67 | + */ |
| 68 | + private $catalogProductType; |
| 69 | + |
| 70 | + /** |
| 71 | + * @var Factory|MockObject |
| 72 | + */ |
| 73 | + private $indexerPriceFactory; |
| 74 | + |
| 75 | + /** |
| 76 | + * @var DefaultPrice|MockObject |
| 77 | + */ |
| 78 | + private $defaultIndexerResource; |
| 79 | + |
| 80 | + /** |
| 81 | + * @var TierPrice|MockObject |
| 82 | + */ |
| 83 | + private $tierPriceIndexResource; |
| 84 | + |
| 85 | + /** |
| 86 | + * @var DimensionCollectionFactory|MockObject |
| 87 | + */ |
| 88 | + private $dimensionCollectionFactory; |
| 89 | + |
| 90 | + /** |
| 91 | + * @var TableMaintainer|MockObject |
| 92 | + */ |
| 93 | + private $tableMaintainer; |
20 | 94 |
|
21 | 95 | protected function setUp(): void
|
22 | 96 | {
|
23 |
| - $objectManager = new ObjectManager($this); |
24 |
| - $this->_model = $objectManager->getObject(Rows::class); |
| 97 | + $this->config = $this->getMockBuilder(ScopeConfigInterface::class) |
| 98 | + ->getMockForAbstractClass(); |
| 99 | + $this->storeManager = $this->getMockBuilder(StoreManagerInterface::class) |
| 100 | + ->getMockForAbstractClass(); |
| 101 | + $this->currencyFactory = $this->getMockBuilder(CurrencyFactory::class) |
| 102 | + ->disableOriginalConstructor() |
| 103 | + ->getMock(); |
| 104 | + $this->localeDate = $this->getMockBuilder(TimezoneInterface::class) |
| 105 | + ->getMockForAbstractClass(); |
| 106 | + $this->dateTime = $this->getMockBuilder(DateTime::class) |
| 107 | + ->disableOriginalConstructor() |
| 108 | + ->getMock(); |
| 109 | + $this->catalogProductType = $this->getMockBuilder(Type::class) |
| 110 | + ->disableOriginalConstructor() |
| 111 | + ->getMock(); |
| 112 | + $this->indexerPriceFactory = $this->getMockBuilder(Factory::class) |
| 113 | + ->disableOriginalConstructor() |
| 114 | + ->getMock(); |
| 115 | + $this->defaultIndexerResource = $this->getMockBuilder(DefaultPrice::class) |
| 116 | + ->disableOriginalConstructor() |
| 117 | + ->getMock(); |
| 118 | + $this->tierPriceIndexResource = $this->getMockBuilder(TierPrice::class) |
| 119 | + ->disableOriginalConstructor() |
| 120 | + ->getMock(); |
| 121 | + $this->dimensionCollectionFactory = $this->getMockBuilder(DimensionCollectionFactory::class) |
| 122 | + ->disableOriginalConstructor() |
| 123 | + ->getMock(); |
| 124 | + $this->tableMaintainer = $this->getMockBuilder(TableMaintainer::class) |
| 125 | + ->disableOriginalConstructor() |
| 126 | + ->getMock(); |
| 127 | + $batchSize = 2; |
| 128 | + |
| 129 | + $this->actionRows = new Rows( |
| 130 | + $this->config, |
| 131 | + $this->storeManager, |
| 132 | + $this->currencyFactory, |
| 133 | + $this->localeDate, |
| 134 | + $this->dateTime, |
| 135 | + $this->catalogProductType, |
| 136 | + $this->indexerPriceFactory, |
| 137 | + $this->defaultIndexerResource, |
| 138 | + $this->tierPriceIndexResource, |
| 139 | + $this->dimensionCollectionFactory, |
| 140 | + $this->tableMaintainer, |
| 141 | + $batchSize |
| 142 | + ); |
25 | 143 | }
|
26 | 144 |
|
27 | 145 | public function testEmptyIds()
|
28 | 146 | {
|
29 | 147 | $this->expectException('Magento\Framework\Exception\InputException');
|
30 | 148 | $this->expectExceptionMessage('Bad value was supplied.');
|
31 |
| - $this->_model->execute(null); |
| 149 | + $this->actionRows->execute(null); |
| 150 | + } |
| 151 | + |
| 152 | + public function testBatchProcessing() |
| 153 | + { |
| 154 | + $ids = [1, 2, 3, 4]; |
| 155 | + $select = $this->getMockBuilder(Select::class) |
| 156 | + ->disableOriginalConstructor() |
| 157 | + ->getMock(); |
| 158 | + $select->expects($this->any())->method('from')->willReturnSelf(); |
| 159 | + $select->expects($this->any())->method('where')->willReturnSelf(); |
| 160 | + $select->expects($this->any())->method('join')->willReturnSelf(); |
| 161 | + $adapter = $this->getMockBuilder(AdapterInterface::class)->getMockForAbstractClass(); |
| 162 | + $adapter->expects($this->any())->method('select')->willReturn($select); |
| 163 | + $this->defaultIndexerResource->expects($this->any()) |
| 164 | + ->method('getConnection') |
| 165 | + ->willReturn($adapter); |
| 166 | + $adapter->expects($this->any()) |
| 167 | + ->method('fetchAll') |
| 168 | + ->with($select) |
| 169 | + ->willReturn([]); |
| 170 | + $adapter->expects($this->any()) |
| 171 | + ->method('fetchPairs') |
| 172 | + ->with($select) |
| 173 | + ->willReturn([]); |
| 174 | + $multiDimensionProvider = $this->getMockBuilder(MultiDimensionProvider::class) |
| 175 | + ->disableOriginalConstructor() |
| 176 | + ->getMock(); |
| 177 | + $this->dimensionCollectionFactory->expects($this->exactly(2)) |
| 178 | + ->method('create') |
| 179 | + ->willReturn($multiDimensionProvider); |
| 180 | + $iterator = new \ArrayIterator([]); |
| 181 | + $multiDimensionProvider->expects($this->exactly(2)) |
| 182 | + ->method('getIterator') |
| 183 | + ->willReturn($iterator); |
| 184 | + $this->catalogProductType->expects($this->any()) |
| 185 | + ->method('getTypesByPriority') |
| 186 | + ->willReturn([]); |
| 187 | + $adapter->expects($this->exactly(2)) |
| 188 | + ->method('getIndexList') |
| 189 | + ->willReturn(['entity_id'=>['COLUMNS_LIST'=>['test']]]); |
| 190 | + $adapter->expects($this->exactly(2)) |
| 191 | + ->method('getPrimaryKeyName') |
| 192 | + ->willReturn('entity_id'); |
| 193 | + $this->actionRows->execute($ids); |
32 | 194 | }
|
33 | 195 | }
|
0 commit comments