Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CaptureOperationTest.php
Go to the documentation of this file.
1 <?php
8 
12 
13 class CaptureOperationTest extends \PHPUnit\Framework\TestCase
14 {
19 
23  protected $eventManager;
24 
29 
33  protected $stateCommand;
34 
38  protected $model;
39 
40  protected function setUp()
41  {
42  $transactionClass = \Magento\Sales\Model\Order\Payment\Transaction\ManagerInterface::class;
43  $transactionBuilderClass = \Magento\Sales\Model\Order\Payment\Transaction\BuilderInterface::class;
44  $this->transactionManager = $this->getMockBuilder($transactionClass)
45  ->disableOriginalConstructor()
46  ->getMock();
47  $this->eventManager = $this->getMockBuilder(\Magento\Framework\Event\ManagerInterface::class)
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::class)
54  ->disableOriginalConstructor()
55  ->getMock();
56  $objectManagerHelper = new ObjectManagerHelper($this);
57  $this->model = $objectManagerHelper->getObject(
58  \Magento\Sales\Model\Order\Payment\Operations\CaptureOperation::class,
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::class)
73  ->disableOriginalConstructor()
74  ->getMock();
75 
76  $paymentMethod = $this->getMockBuilder(\Magento\Payment\Model\MethodInterface::class)
77  ->disableOriginalConstructor()
78  ->getMock();
79 
80  $orderPayment = $this->getMockBuilder(\Magento\Sales\Model\Order\Payment::class)
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::class)
110  ->disableOriginalConstructor()
111  ->getMock();
112  $invoice->expects($this->any())
113  ->method('getBaseGrandTotal')
114  ->willReturn($baseGrandTotal);
115 
116  $this->model->capture($orderPayment, $invoice);
117  }
118 }
$order
Definition: order.php:55
$invoice