|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © Magento, Inc. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | + |
| 7 | +namespace Magento\Sales\Test\Unit\Model\Order; |
| 8 | + |
| 9 | +/** |
| 10 | + * Unit test for creditmemo factory class. |
| 11 | + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) |
| 12 | + */ |
| 13 | +class CreditmemoFactoryTest extends \PHPUnit\Framework\TestCase |
| 14 | +{ |
| 15 | + /** |
| 16 | + * Subject of testing. |
| 17 | + * |
| 18 | + * @var \Magento\Sales\Model\Order\CreditmemoFactory |
| 19 | + */ |
| 20 | + protected $subject; |
| 21 | + |
| 22 | + /** |
| 23 | + * @return void |
| 24 | + * @SuppressWarnings(PHPMD.ExcessiveMethodLength) |
| 25 | + */ |
| 26 | + protected function setUp() |
| 27 | + { |
| 28 | + $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); |
| 29 | + $this->subject = $objectManager->getObject(\Magento\Sales\Model\Order\CreditmemoFactory::class, []); |
| 30 | + } |
| 31 | + |
| 32 | + /** |
| 33 | + * Check if order item can be refunded |
| 34 | + */ |
| 35 | + public function testCanRefundItem() |
| 36 | + { |
| 37 | + $orderItem = $this->createPartialMock( |
| 38 | + \Magento\Sales\Model\Order\Item::class, |
| 39 | + ['getChildrenItems', 'isDummy', 'getHasChildren', 'getId', 'getParentItemId'] |
| 40 | + ); |
| 41 | + $orderItem->expects($this->any()) |
| 42 | + ->method('getId') |
| 43 | + ->willReturn(1); |
| 44 | + $orderItem->expects($this->any())->method('getParentItemId')->willReturn(false); |
| 45 | + $orderItem->expects($this->any())->method('isDummy')->willReturn(true); |
| 46 | + $orderItem->expects($this->any())->method('getHasChildren')->willReturn(true); |
| 47 | + $orderChildItemOne = $this->createPartialMock( |
| 48 | + \Magento\Sales\Model\Order\Item::class, |
| 49 | + ['getQtyToRefund', 'getId'] |
| 50 | + ); |
| 51 | + $orderChildItemOne->expects($this->any())->method('getQtyToRefund')->willReturn(1); |
| 52 | + $orderChildItemOne->expects($this->any())->method('getId')->willReturn(2); |
| 53 | + $orderChildItemTwo = $this->createPartialMock( |
| 54 | + \Magento\Sales\Model\Order\Item::class, |
| 55 | + ['getQtyToRefund', 'getId'] |
| 56 | + ); |
| 57 | + $orderChildItemTwo->expects($this->any())->method('getQtyToRefund')->willReturn(1); |
| 58 | + $orderChildItemTwo->expects($this->any())->method('getId')->willReturn(3); |
| 59 | + $orderItem->expects($this->any())->method('getChildrenItems')->willReturn([$orderChildItemOne, $orderChildItemTwo]); |
| 60 | + $testMethod = new \ReflectionMethod( |
| 61 | + \Magento\Sales\Model\Order\CreditmemoFactory::class, |
| 62 | + 'canRefundItem' |
| 63 | + ); |
| 64 | + $orderItemQtys = [ |
| 65 | + 2 => 0, |
| 66 | + 3 => 0 |
| 67 | + ]; |
| 68 | + $invoiceQtysRefundLimits = []; |
| 69 | + $testMethod->setAccessible(true); |
| 70 | + $result = $testMethod->invoke($this->subject, $orderItem, $orderItemQtys, $invoiceQtysRefundLimits); |
| 71 | + $expectedResult = true; |
| 72 | + $this->assertEquals($expectedResult, $result); |
| 73 | + } |
| 74 | +} |
0 commit comments