75 $this->stockIndexerProcessor = $this->createPartialMock(
76 \
Magento\CatalogInventory\Model\Indexer\Stock\Processor::class,
80 $this->stockManagement = $this->createMock(\
Magento\CatalogInventory\Model\StockManagement::class);
82 $this->stockConfiguration = $this->getMockForAbstractClass(
83 \
Magento\CatalogInventory\Api\StockConfigurationInterface::class,
85 'isAutoReturnEnabled',
86 'isDisplayProductStockStatus' 92 $this->priceIndexer = $this->getMockBuilder(\
Magento\Catalog\Model\Indexer\Product\Price\Processor::class)
93 ->disableOriginalConstructor()
96 $this->
event = $this->getMockBuilder(\
Magento\Framework\Event::class)
97 ->disableOriginalConstructor()
98 ->setMethods([
'getProduct',
'getCollection',
'getCreditmemo',
'getQuote',
'getWebsite'])
101 $this->eventObserver = $this->getMockBuilder(\
Magento\Framework\Event\Observer::class)
102 ->disableOriginalConstructor()
103 ->setMethods([
'getEvent'])
106 $this->eventObserver->expects($this->atLeastOnce())
108 ->will($this->returnValue($this->event));
110 $this->orderRepositoryMock = $this->getMockBuilder(OrderRepository::class)
111 ->disableOriginalConstructor()
114 $this->returnProcessorMock = $this->getMockBuilder(ReturnProcessor::class)
115 ->disableOriginalConstructor()
118 $this->orderMock = $this->getMockBuilder(OrderInterface::class)
119 ->disableOriginalConstructor()
122 $this->objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
124 $this->observer = $this->objectManagerHelper->getObject(
125 \
Magento\SalesInventory\Observer\RefundOrderInventoryObserver::class,
127 'stockConfiguration' => $this->stockConfiguration,
128 'stockManagement' => $this->stockManagement,
129 'stockIndexerProcessor' => $this->stockIndexerProcessor,
130 'priceIndexer' => $this->priceIndexer,
134 $this->objectManagerHelper->setBackwardCompatibleProperty(
137 $this->orderRepositoryMock
139 $this->objectManagerHelper->setBackwardCompatibleProperty(
142 $this->returnProcessorMock
151 $creditMemo = $this->createMock(\
Magento\Sales\Model\Order\Creditmemo::class);
153 foreach ($ids as
$id) {
154 $item = $this->getCreditMemoItem(
$id);
158 $creditMemo->expects($this->once())
160 ->will($this->returnValue(
$items));
161 $this->
event->expects($this->once())
162 ->method(
'getCreditmemo')
163 ->will($this->returnValue($creditMemo));
165 $this->orderRepositoryMock->expects($this->once())
167 ->willReturn($this->orderMock);
169 $this->returnProcessorMock->expects($this->once())
171 ->with($creditMemo, $this->orderMock, $ids);
173 $this->observer->execute($this->eventObserver);
180 private function getCreditMemoItem(
$productId)
183 $item = $this->createPartialMock(
184 \
Magento\Sales\Model\Order\Creditmemo\Item::class,
185 [
'getOrderItemId',
'getBackToStock',
'getQty',
'__wakeup']
187 $item->expects($this->any())->method(
'getBackToStock')->willReturn($backToStock);
188 $item->expects($this->any())->method(
'getOrderItemId')->willReturn(
$productId);
testRefundOrderInventory()