|
5 | 5 | */
|
6 | 6 | namespace Magento\Catalog\Test\Unit\Model\Indexer\Product\Eav\Action;
|
7 | 7 |
|
| 8 | +/** |
| 9 | + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) |
| 10 | + */ |
8 | 11 | class FullTest extends \PHPUnit_Framework_TestCase
|
9 | 12 | {
|
10 | 13 | public function testExecuteWithAdapterErrorThrowsException()
|
@@ -55,4 +58,103 @@ public function testExecuteWithAdapterErrorThrowsException()
|
55 | 58 |
|
56 | 59 | $model->execute();
|
57 | 60 | }
|
| 61 | + |
| 62 | + public function testExecute() |
| 63 | + { |
| 64 | + $eavDecimalFactory = $this->getMock( |
| 65 | + \Magento\Catalog\Model\ResourceModel\Product\Indexer\Eav\DecimalFactory::class, |
| 66 | + ['create'], |
| 67 | + [], |
| 68 | + '', |
| 69 | + false |
| 70 | + ); |
| 71 | + $eavSourceFactory = $this->getMock( |
| 72 | + \Magento\Catalog\Model\ResourceModel\Product\Indexer\Eav\SourceFactory::class, |
| 73 | + ['create'], |
| 74 | + [], |
| 75 | + '', |
| 76 | + false |
| 77 | + ); |
| 78 | + |
| 79 | + $ids = [1, 2, 3]; |
| 80 | + $connectionMock = $this->getMockBuilder(\Magento\Framework\DB\Adapter\AdapterInterface::class) |
| 81 | + ->getMockForAbstractClass(); |
| 82 | + |
| 83 | + $connectionMock->expects($this->atLeastOnce())->method('describeTable')->willReturn(['id' => []]); |
| 84 | + $eavSource = $this->getMockBuilder(\Magento\Catalog\Model\ResourceModel\Product\Indexer\Eav\Source::class) |
| 85 | + ->disableOriginalConstructor() |
| 86 | + ->getMock(); |
| 87 | + |
| 88 | + $eavDecimal = $this->getMockBuilder(\Magento\Catalog\Model\ResourceModel\Product\Indexer\Eav\Decimal::class) |
| 89 | + ->disableOriginalConstructor() |
| 90 | + ->getMock(); |
| 91 | + |
| 92 | + $eavSource->expects($this->once())->method('getRelationsByChild')->with($ids)->willReturn([]); |
| 93 | + $eavSource->expects($this->never())->method('getRelationsByParent')->with($ids)->willReturn([]); |
| 94 | + |
| 95 | + $eavDecimal->expects($this->once())->method('getRelationsByChild')->with($ids)->willReturn([]); |
| 96 | + $eavDecimal->expects($this->never())->method('getRelationsByParent')->with($ids)->willReturn([]); |
| 97 | + |
| 98 | + $eavSource->expects($this->atLeastOnce())->method('getConnection')->willReturn($connectionMock); |
| 99 | + $eavDecimal->expects($this->atLeastOnce())->method('getConnection')->willReturn($connectionMock); |
| 100 | + |
| 101 | + $eavDecimal->expects($this->once()) |
| 102 | + ->method('reindexEntities') |
| 103 | + ->with($ids); |
| 104 | + |
| 105 | + $eavSource->expects($this->once()) |
| 106 | + ->method('reindexEntities') |
| 107 | + ->with($ids); |
| 108 | + |
| 109 | + $eavDecimalFactory->expects($this->once()) |
| 110 | + ->method('create') |
| 111 | + ->will($this->returnValue($eavSource)); |
| 112 | + |
| 113 | + $eavSourceFactory->expects($this->once()) |
| 114 | + ->method('create') |
| 115 | + ->will($this->returnValue($eavDecimal)); |
| 116 | + |
| 117 | + $metadataMock = $this->getMock(\Magento\Framework\EntityManager\MetadataPool::class, [], [], '', false); |
| 118 | + $entityMetadataMock = $this->getMockBuilder(\Magento\Framework\EntityManager\EntityMetadataInterface::class) |
| 119 | + ->getMockForAbstractClass(); |
| 120 | + |
| 121 | + $metadataMock->expects($this->atLeastOnce()) |
| 122 | + ->method('getMetadata') |
| 123 | + ->with(\Magento\Catalog\Api\Data\ProductInterface::class) |
| 124 | + ->willReturn($entityMetadataMock); |
| 125 | + |
| 126 | + $batchProviderMock = $this->getMock(\Magento\Framework\Indexer\BatchProviderInterface::class); |
| 127 | + $batchProviderMock->expects($this->atLeastOnce()) |
| 128 | + ->method('getBatches') |
| 129 | + ->willReturn([['from' => 10, 'to' => 100]]); |
| 130 | + $batchProviderMock->expects($this->atLeastOnce()) |
| 131 | + ->method('getBatchIds') |
| 132 | + ->willReturn($ids); |
| 133 | + |
| 134 | + $batchManagementMock = $this->getMock( |
| 135 | + \Magento\Catalog\Model\ResourceModel\Product\Indexer\Eav\BatchSizeCalculator::class, |
| 136 | + [], |
| 137 | + [], |
| 138 | + '', |
| 139 | + false |
| 140 | + ); |
| 141 | + $selectMock = $this->getMockBuilder(\Magento\Framework\DB\Select::class) |
| 142 | + ->disableOriginalConstructor() |
| 143 | + ->getMock(); |
| 144 | + |
| 145 | + $connectionMock->method('select')->willReturn($selectMock); |
| 146 | + $selectMock->expects($this->atLeastOnce())->method('distinct')->willReturnSelf(); |
| 147 | + $selectMock->expects($this->atLeastOnce())->method('from')->willReturnSelf(); |
| 148 | + |
| 149 | + $model = new \Magento\Catalog\Model\Indexer\Product\Eav\Action\Full( |
| 150 | + $eavDecimalFactory, |
| 151 | + $eavSourceFactory, |
| 152 | + $metadataMock, |
| 153 | + $batchProviderMock, |
| 154 | + $batchManagementMock, |
| 155 | + [] |
| 156 | + ); |
| 157 | + |
| 158 | + $model->execute(); |
| 159 | + } |
58 | 160 | }
|
0 commit comments