public function testVoid() { $orderId = 1005; $paymentObject = $this->setupPaymentObjectForVoid($orderId); $transactions = ['1' => \Braintree_Transaction::factory(['id' => '1', 'status' => \Braintree_Transaction::SUBMITTED_FOR_SETTLEMENT]), '2' => \Braintree_Transaction::factory(['id' => '2', 'status' => \Braintree_Transaction::AUTHORIZED])]; $this->setupTransactionIds($orderId, array_keys($transactions)); $index = 0; foreach ($transactions as $id => $transaction) { $this->braintreeTransactionMock->expects($this->at($index))->method('find')->with($id)->willReturn($transaction); $index++; } foreach (array_keys($transactions) as $id) { $resultSuccess = $this->setupSuccessResponse([]); $this->braintreeTransactionMock->expects($this->at($index))->method('void')->with($id)->willReturn($resultSuccess); $index++; } $index = 1; foreach (array_keys($transactions) as $id) { $transactionCollectionMock = $this->getMockBuilder('\\Magento\\Sales\\Model\\ResourceModel\\Order\\Payment\\Transaction\\Collection')->disableOriginalConstructor()->getMock(); $transactionCollectionMock->expects($this->at(0))->method('addFieldToFilter')->with('parent_txn_id', ['eq' => $id])->willReturnSelf(); $transactionCollectionMock->expects($this->at(1))->method('addFieldToFilter')->with('txn_type', PaymentTransaction::TYPE_VOID)->willReturnSelf(); $transactionCollectionMock->expects($this->once())->method('getSize')->willReturn(1); $this->salesTransactionCollectionFactoryMock->expects($this->at($index))->method('create')->willReturn($transactionCollectionMock); $index++; } $this->model->void($paymentObject); $this->assertEquals(1, $paymentObject->getIsTransactionClosed()); $this->assertEquals('Voided capture.', $paymentObject->getMessage()->getText()); }
public function testAroundGetAuthorizationTransactionNoInvoiceTransaction() { $result = 'result'; $transactionId = 're45gf'; $transaction = 'invoice_transaction'; $proceed = function () use($result) { return $result; }; $methodInstanceMock = $this->getMock('\\Magento\\Payment\\Model\\MethodInterface'); $methodInstanceMock->expects($this->once())->method('getCode')->willReturn(PaymentMethod::METHOD_CODE); $invoiceMock = $this->getMockBuilder('\\Magento\\Sales\\Model\\Order\\Invoice')->disableOriginalConstructor()->getMock(); $invoiceMock->expects($this->once())->method('getId')->willReturn(1004); $invoiceMock->expects($this->once())->method('getTransactionId')->willReturn($transactionId); $this->helperMock->expects($this->once())->method('clearTransactionId')->with($transactionId)->willReturn($transactionId); $collectionMock = $this->getMockBuilder('\\Magento\\Sales\\Model\\ResourceModel\\Order\\Payment\\Transaction\\Collection')->disableOriginalConstructor()->getMock(); $this->transactionCollectionFactoryMock->expects($this->once())->method('create')->willReturn($collectionMock); $collectionMock->expects($this->once())->method('addFieldToFilter')->with('txn_id', ['eq' => $transactionId])->willReturnSelf(); $collectionMock->expects($this->once())->method('getSize')->willReturn(0); $collectionMock->expects($this->never())->method('getFirstItem')->willReturn($transaction); $this->registryMock->expects($this->once())->method('registry')->with('current_invoice')->willReturn($invoiceMock); $payment = $this->getMockBuilder('\\Magento\\Sales\\Model\\Order\\Payment')->disableOriginalConstructor()->getMock(); $payment->expects($this->once())->method('getMethodInstance')->willReturn($methodInstanceMock); $this->assertEquals($result, $this->model->aroundGetAuthorizationTransaction($payment, $proceed)); }