|
7 | 7 |
|
8 | 8 | namespace Magento\Catalog\Test\Unit\Model\Indexer\Product\Eav\Action;
|
9 | 9 |
|
| 10 | +use Magento\Catalog\Model\Indexer\Product\Eav\Action\Row; |
10 | 11 | use Magento\Catalog\Model\Indexer\Product\Eav\Action\Rows;
|
11 |
| -use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; |
| 12 | +use Magento\Catalog\Model\ResourceModel\Product\Indexer\Eav\Decimal; |
| 13 | +use Magento\Catalog\Model\ResourceModel\Product\Indexer\Eav\DecimalFactory; |
| 14 | +use Magento\Catalog\Model\ResourceModel\Product\Indexer\Eav\Source; |
| 15 | +use Magento\Catalog\Model\ResourceModel\Product\Indexer\Eav\SourceFactory; |
| 16 | +use Magento\Framework\App\Config\ScopeConfigInterface; |
| 17 | +use Magento\Framework\DB\Adapter\AdapterInterface; |
| 18 | +use Magento\Framework\Exception\InputException; |
| 19 | +use Magento\Store\Model\ScopeInterface; |
| 20 | +use PHPUnit\Framework\MockObject\MockObject; |
12 | 21 | use PHPUnit\Framework\TestCase;
|
13 | 22 |
|
14 | 23 | class RowsTest extends TestCase
|
15 | 24 | {
|
| 25 | + /** |
| 26 | + * @var DecimalFactory|MockObject |
| 27 | + */ |
| 28 | + private $eavDecimalFactoryMock; |
| 29 | + |
| 30 | + /** |
| 31 | + * @var SourceFactory|MockObject |
| 32 | + */ |
| 33 | + private $eavSourceFactoryMock; |
| 34 | + |
| 35 | + /** |
| 36 | + * @var ScopeConfigInterface|MockObject |
| 37 | + */ |
| 38 | + private $scopeConfigMock; |
| 39 | + |
16 | 40 | /**
|
17 | 41 | * @var Rows
|
18 | 42 | */
|
19 |
| - protected $_model; |
| 43 | + private $model; |
20 | 44 |
|
21 | 45 | protected function setUp(): void
|
22 | 46 | {
|
23 |
| - $objectManager = new ObjectManager($this); |
24 |
| - $this->_model = $objectManager->getObject(Rows::class); |
| 47 | + $this->eavDecimalFactoryMock = $this->createMock(DecimalFactory::class); |
| 48 | + $this->eavSourceFactoryMock = $this->createMock(SourceFactory::class); |
| 49 | + $this->scopeConfigMock = $this->createMock(ScopeConfigInterface::class); |
| 50 | + $this->model = new Rows( |
| 51 | + $this->eavDecimalFactoryMock, |
| 52 | + $this->eavSourceFactoryMock, |
| 53 | + $this->scopeConfigMock |
| 54 | + ); |
25 | 55 | }
|
26 | 56 |
|
27 | 57 | public function testEmptyIds()
|
28 | 58 | {
|
29 |
| - $this->expectException('Magento\Framework\Exception\InputException'); |
| 59 | + $this->expectException(InputException::class); |
30 | 60 | $this->expectExceptionMessage('Bad value was supplied.');
|
31 |
| - $this->_model->execute(null); |
| 61 | + $this->model->execute(null); |
| 62 | + } |
| 63 | + |
| 64 | + public function testExecute(): void |
| 65 | + { |
| 66 | + $this->scopeConfigMock->expects($this->once()) |
| 67 | + ->method('getValue') |
| 68 | + ->with(Row::ENABLE_EAV_INDEXER, ScopeInterface::SCOPE_STORE) |
| 69 | + ->willReturn(true); |
| 70 | + |
| 71 | + $eavDecimalMock = $this->createMock(Decimal::class); |
| 72 | + $this->eavDecimalFactoryMock->expects($this->once()) |
| 73 | + ->method('create') |
| 74 | + ->willReturn($eavDecimalMock); |
| 75 | + $eavSourceMock = $this->createMock(Source::class); |
| 76 | + $this->eavSourceFactoryMock->expects($this->once()) |
| 77 | + ->method('create') |
| 78 | + ->willReturn($eavSourceMock); |
| 79 | + |
| 80 | + foreach ([$eavDecimalMock, $eavSourceMock] as $indexerMock) { |
| 81 | + $indexerMock->expects($this->atLeastOnce()) |
| 82 | + ->method('getRelationsByChild') |
| 83 | + ->with([2, 4, 5]) |
| 84 | + ->willReturn([]); |
| 85 | + $indexerMock->expects($this->atLeastOnce()) |
| 86 | + ->method('getRelationsByParent') |
| 87 | + ->with([2, 4, 5]) |
| 88 | + ->willReturn([]); |
| 89 | + $indexerMock->expects($this->once()) |
| 90 | + ->method('reindexEntities') |
| 91 | + ->with([2, 4, 5]) |
| 92 | + ->willReturnSelf(); |
| 93 | + $mainTable = 'main_table_name'; |
| 94 | + $indexerMock->expects($this->atLeastOnce()) |
| 95 | + ->method('getMainTable') |
| 96 | + ->willReturn($mainTable); |
| 97 | + |
| 98 | + $connectionMock = $this->createMock(AdapterInterface::class); |
| 99 | + $indexerMock->expects($this->atLeastOnce()) |
| 100 | + ->method('getConnection') |
| 101 | + ->willReturn($connectionMock); |
| 102 | + $connectionMock->expects($this->once()) |
| 103 | + ->method('beginTransaction') |
| 104 | + ->willReturnSelf(); |
| 105 | + $connectionMock->expects($this->once()) |
| 106 | + ->method('quoteInto') |
| 107 | + ->with('entity_id IN (?)', [2, 4, 5], 'INT') |
| 108 | + ->willReturn('entity_id IN (2, 4, 5)'); |
| 109 | + $connectionMock->expects($this->once()) |
| 110 | + ->method('delete') |
| 111 | + ->with($mainTable, 'entity_id IN (2, 4, 5)') |
| 112 | + ->willReturn(3); |
| 113 | + $idxTable = 'idx_table_name'; |
| 114 | + $indexerMock->expects($this->atLeastOnce()) |
| 115 | + ->method('getIdxTable') |
| 116 | + ->with() |
| 117 | + ->willReturn($idxTable); |
| 118 | + $indexerMock->expects($this->once()) |
| 119 | + ->method('insertFromTable') |
| 120 | + ->with($idxTable, $mainTable) |
| 121 | + ->willReturnSelf(); |
| 122 | + $connectionMock->expects($this->once()) |
| 123 | + ->method('commit') |
| 124 | + ->willReturnSelf(); |
| 125 | + } |
| 126 | + |
| 127 | + $ids = [2, 4, 5]; |
| 128 | + $this->model->execute($ids); |
32 | 129 | }
|
33 | 130 | }
|
0 commit comments