68 $this->_objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
70 $this->_storeManagerMock = $this->createMock(\
Magento\
Store\Model\StoreManagerInterface::class);
71 $this->_resourceMock = $this->createMock(\
Magento\Framework\
App\ResourceConnection::class);
72 $this->_dateTimeMock = $this->createMock(\
Magento\Framework\Stdlib\DateTime::class);
73 $this->_localeDateMock = $this->createMock(\
Magento\Framework\Stdlib\DateTime\TimezoneInterface::class);
74 $this->_eavConfigMock = $this->createMock(\
Magento\Eav\Model\Config::class);
75 $this->_priceProcessorMock = $this->createMock(\
Magento\Catalog\Model\
Indexer\Product\Price\Processor::class);
77 $this->metadataMock = $this->createMock(\
Magento\Framework\EntityManager\EntityMetadata::class);
79 $this->_model = $this->_objectManager->getObject(
80 \
Magento\Catalog\Cron\RefreshSpecialPrices::class,
82 'storeManager' => $this->_storeManagerMock,
83 'resource' => $this->_resourceMock,
84 'dateTime' => $this->_dateTimeMock,
85 'localeDate' => $this->_localeDateMock,
86 'eavConfig' => $this->_eavConfigMock,
87 'processor' => $this->_priceProcessorMock
91 $this->metadataPool = $this->createMock(MetadataPool::class);
93 $reflection = new \ReflectionClass(get_class($this->_model));
94 $reflectionProperty = $reflection->getProperty(
'metadataPool');
95 $reflectionProperty->setAccessible(
true);
96 $reflectionProperty->setValue($this->_model, $this->metadataPool);
101 $idsToProcess = [1, 2, 3];
103 $this->metadataPool->expects($this->atLeastOnce())
104 ->method(
'getMetadata')
105 ->willReturn($this->metadataMock);
107 $this->metadataMock->expects($this->atLeastOnce())->method(
'getLinkField')->willReturn(
'row_id');
109 $this->metadataMock->expects($this->atLeastOnce())->method(
'getIdentifierField')->willReturn(
'entity_id');
111 $selectMock = $this->createMock(\
Magento\Framework\DB\Select::class);
112 $selectMock->expects($this->any())->method(
'from')->will($this->returnSelf());
113 $selectMock->expects($this->any())->method(
'joinLeft')->will($this->returnSelf());
114 $selectMock->expects($this->any())->method(
'where')->will($this->returnSelf());
116 $connectionMock = $this->createMock(\
Magento\Framework\DB\Adapter\AdapterInterface::class);
117 $connectionMock->expects($this->any())->method(
'select')->will($this->returnValue($selectMock));
118 $connectionMock->expects(
123 $this->returnValue($idsToProcess)
126 $this->_resourceMock->expects(
131 $this->returnValue($connectionMock)
134 $this->_resourceMock->expects(
139 $this->returnValue(
'category')
142 $storeMock = $this->createMock(\
Magento\
Store\Model\Store::class);
143 $storeMock->expects($this->any())->method(
'getId')->will($this->returnValue(1));
145 $this->_storeManagerMock->expects(
152 $this->returnValue([$storeMock])
155 $this->_localeDateMock->expects(
162 $this->returnValue(32000)
165 $indexerMock = $this->createMock(\
Magento\
Indexer\Model\Indexer::class);
166 $indexerMock->expects($this->exactly(2))->method(
'reindexList');
168 $this->_priceProcessorMock->expects(
173 $this->returnValue($indexerMock)
176 $attributeMock = $this->getMockForAbstractClass(
183 [
'__wakeup',
'getAttributeId']
185 $attributeMock->expects($this->any())->method(
'getAttributeId')->will($this->returnValue(1));
187 $this->_eavConfigMock->expects($this->any())->method(
'getAttribute')->will($this->returnValue($attributeMock));
189 $this->_model->execute();
testRefreshSpecialPrices()