|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © 2015 Magento. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | + |
| 7 | +namespace Magento\Sales\Test\Unit\Model\Order\Payment\Operations; |
| 8 | + |
| 9 | +use Magento\Framework\ObjectManager\ObjectManager; |
| 10 | +use Magento\Payment\Model\Method; |
| 11 | +use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper; |
| 12 | + |
| 13 | +class CaptureOperationTest extends \PHPUnit_Framework_TestCase |
| 14 | +{ |
| 15 | + /** |
| 16 | + * @var \PHPUnit_Framework_MockObject_MockObject |
| 17 | + */ |
| 18 | + protected $transactionManager; |
| 19 | + |
| 20 | + /** |
| 21 | + * @var \PHPUnit_Framework_MockObject_MockObject |
| 22 | + */ |
| 23 | + protected $eventManager; |
| 24 | + |
| 25 | + /** |
| 26 | + * @var \PHPUnit_Framework_MockObject_MockObject |
| 27 | + */ |
| 28 | + protected $transactionBuilder; |
| 29 | + |
| 30 | + /** |
| 31 | + * @var \PHPUnit_Framework_MockObject_MockObject |
| 32 | + */ |
| 33 | + protected $stateCommand; |
| 34 | + |
| 35 | + /** |
| 36 | + * @var \Magento\Sales\Model\Order\Payment\Operations\CaptureOperation |
| 37 | + */ |
| 38 | + protected $model; |
| 39 | + |
| 40 | + protected function setUp() |
| 41 | + { |
| 42 | + $transactionClass = 'Magento\Sales\Model\Order\Payment\Transaction\ManagerInterface'; |
| 43 | + $transactionBuilderClass = 'Magento\Sales\Model\Order\Payment\Transaction\BuilderInterface'; |
| 44 | + $this->transactionManager = $this->getMockBuilder($transactionClass) |
| 45 | + ->disableOriginalConstructor() |
| 46 | + ->getMock(); |
| 47 | + $this->eventManager = $this->getMockBuilder('Magento\Framework\Event\ManagerInterface') |
| 48 | + ->disableOriginalConstructor() |
| 49 | + ->getMock(); |
| 50 | + $this->transactionBuilder = $this->getMockBuilder($transactionBuilderClass) |
| 51 | + ->disableOriginalConstructor() |
| 52 | + ->getMock(); |
| 53 | + $this->stateCommand = $this->getMockBuilder('Magento\Sales\Model\Order\Payment\State\CommandInterface') |
| 54 | + ->disableOriginalConstructor() |
| 55 | + ->getMock(); |
| 56 | + $objectManagerHelper = new ObjectManagerHelper($this); |
| 57 | + $this->model = $objectManagerHelper->getObject( |
| 58 | + 'Magento\Sales\Model\Order\Payment\Operations\CaptureOperation', |
| 59 | + [ |
| 60 | + 'transactionManager' => $this->transactionManager, |
| 61 | + 'eventManager' => $this->eventManager, |
| 62 | + 'transactionBuilder' => $this->transactionBuilder, |
| 63 | + 'stateCommand' => $this->stateCommand |
| 64 | + ] |
| 65 | + ); |
| 66 | + } |
| 67 | + |
| 68 | + public function testCapture() |
| 69 | + { |
| 70 | + $baseGrandTotal = 10; |
| 71 | + |
| 72 | + $order = $this->getMockBuilder('Magento\Sales\Model\Order') |
| 73 | + ->disableOriginalConstructor() |
| 74 | + ->getMock(); |
| 75 | + |
| 76 | + $paymentMethod = $this->getMockBuilder('Magento\Payment\Model\MethodInterface') |
| 77 | + ->disableOriginalConstructor() |
| 78 | + ->getMock(); |
| 79 | + |
| 80 | + $orderPayment = $this->getMockBuilder('Magento\Sales\Model\Order\Payment') |
| 81 | + ->disableOriginalConstructor() |
| 82 | + ->getMock(); |
| 83 | + $orderPayment->expects($this->any()) |
| 84 | + ->method('formatAmount') |
| 85 | + ->with($baseGrandTotal) |
| 86 | + ->willReturnArgument(0); |
| 87 | + $orderPayment->expects($this->any()) |
| 88 | + ->method('getOrder') |
| 89 | + ->willReturn($order); |
| 90 | + $orderPayment->expects($this->any()) |
| 91 | + ->method('getMethodInstance') |
| 92 | + ->willReturn($paymentMethod); |
| 93 | + $orderPayment->expects($this->once()) |
| 94 | + ->method('getIsTransactionPending') |
| 95 | + ->willReturn(true); |
| 96 | + $orderPayment->expects($this->once()) |
| 97 | + ->method('getTransactionAdditionalInfo') |
| 98 | + ->willReturn([]); |
| 99 | + |
| 100 | + $paymentMethod->expects($this->once()) |
| 101 | + ->method('capture') |
| 102 | + ->with($orderPayment, $baseGrandTotal); |
| 103 | + |
| 104 | + $this->transactionBuilder->expects($this->once()) |
| 105 | + ->method('setPayment') |
| 106 | + ->with($orderPayment) |
| 107 | + ->willReturnSelf(); |
| 108 | + |
| 109 | + $invoice = $this->getMockBuilder('Magento\Sales\Model\Order\Invoice') |
| 110 | + ->disableOriginalConstructor() |
| 111 | + ->getMock(); |
| 112 | + $invoice->expects($this->any()) |
| 113 | + ->method('getBaseGrandTotal') |
| 114 | + ->willReturn($baseGrandTotal); |
| 115 | + |
| 116 | + $this->model->capture($orderPayment, $invoice); |
| 117 | + } |
| 118 | +} |
0 commit comments