Skip to content
Snippets Groups Projects
Unverified Commit 480f8ae7 authored by Anton Evers's avatar Anton Evers
Browse files

add tests for refunding pending credit memos

parent 8a6c3f2d
No related merge requests found
...@@ -243,6 +243,78 @@ class CreditmemoServiceTest extends \PHPUnit\Framework\TestCase ...@@ -243,6 +243,78 @@ class CreditmemoServiceTest extends \PHPUnit\Framework\TestCase
$this->assertSame($creditMemoMock, $this->creditmemoService->refund($creditMemoMock, true)); $this->assertSame($creditMemoMock, $this->creditmemoService->refund($creditMemoMock, true));
} }
public function testRefundPendingCreditMemo()
{
$creditMemoMock = $this->getMockBuilder(\Magento\Sales\Api\Data\CreditmemoInterface::class)
->setMethods(['getId', 'getOrder', 'getState', 'getInvoice'])
->disableOriginalConstructor()
->getMockForAbstractClass();
$creditMemoMock->expects($this->once())->method('getId')->willReturn(444);
$creditMemoMock->expects($this->once())->method('getState')
->willReturn(\Magento\Sales\Model\Order\Creditmemo::STATE_OPEN);
$orderMock = $this->getMockBuilder(Order::class)->disableOriginalConstructor()->getMock();
$creditMemoMock->expects($this->atLeastOnce())->method('getOrder')->willReturn($orderMock);
$orderMock->expects($this->once())->method('getBaseTotalRefunded')->willReturn(0);
$orderMock->expects($this->once())->method('getBaseTotalPaid')->willReturn(10);
$creditMemoMock->expects($this->once())->method('getBaseGrandTotal')->willReturn(10);
$this->priceCurrencyMock->expects($this->any())
->method('round')
->willReturnArgument(0);
// Set payment adapter dependency
$refundAdapterMock = $this->getMockBuilder(\Magento\Sales\Model\Order\RefundAdapterInterface::class)
->disableOriginalConstructor()
->getMockForAbstractClass();
$this->objectManagerHelper->setBackwardCompatibleProperty(
$this->creditmemoService,
'refundAdapter',
$refundAdapterMock
);
// Set resource dependency
$resourceMock = $this->getMockBuilder(\Magento\Framework\App\ResourceConnection::class)
->disableOriginalConstructor()
->getMock();
$this->objectManagerHelper->setBackwardCompatibleProperty(
$this->creditmemoService,
'resource',
$resourceMock
);
// Set order repository dependency
$orderRepositoryMock = $this->getMockBuilder(\Magento\Sales\Api\OrderRepositoryInterface::class)
->disableOriginalConstructor()
->getMockForAbstractClass();
$this->objectManagerHelper->setBackwardCompatibleProperty(
$this->creditmemoService,
'orderRepository',
$orderRepositoryMock
);
$adapterMock = $this->getMockBuilder(\Magento\Framework\DB\Adapter\AdapterInterface::class)
->disableOriginalConstructor()
->getMockForAbstractClass();
$resourceMock->expects($this->once())->method('getConnection')->with('sales')->willReturn($adapterMock);
$adapterMock->expects($this->once())->method('beginTransaction');
$refundAdapterMock->expects($this->once())
->method('refund')
->with($creditMemoMock, $orderMock, false)
->willReturn($orderMock);
$orderRepositoryMock->expects($this->once())
->method('save')
->with($orderMock);
$creditMemoMock->expects($this->once())
->method('getInvoice')
->willReturn(null);
$adapterMock->expects($this->once())->method('commit');
$this->creditmemoRepositoryMock->expects($this->once())
->method('save');
$this->assertSame($creditMemoMock, $this->creditmemoService->refund($creditMemoMock, true));
}
/** /**
* @expectedExceptionMessage The most money available to refund is 1. * @expectedExceptionMessage The most money available to refund is 1.
* @expectedException \Magento\Framework\Exception\LocalizedException * @expectedException \Magento\Framework\Exception\LocalizedException
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment