/** * @expectedException \Magento\Framework\Exception\LocalizedException * @expectedExceptionMessage There was an error capturing the transaction: error. */ public function testPartialCaptureCloneTransactionError() { $amount = self::AUTH_AMOUNT; $paymentId = 1005; $authTransactionId = 1006; $braintreeTransactionId = '4fg7hj'; $paymentObject = $this->setupPaymentObjectForCapture($paymentId); $this->setupSalesTransaction($paymentId, 1); //one existing capture transaction $authTransactionMock = $this->getMockBuilder('\\Magento\\Sales\\Model\\Order\\Payment\\Transaction')->disableOriginalConstructor()->getMock(); $authTransactionMock->expects($this->any())->method('getId')->willReturn($authTransactionId); $authTransactionMock->expects($this->once())->method('getAdditionalInformation')->with('token')->willReturn(self::CC_TOKEN); $authTransactionMock->expects($this->once())->method('getTxnId')->willReturn($braintreeTransactionId); $this->setupAuthTransaction($paymentId, $authTransactionMock); $this->braintreeCreditCardMock->expects($this->once())->method('find')->with(self::CC_TOKEN)->willThrowException(new \Exception('not found')); $resultError = $this->getMockBuilder('\\Braintree_Result_Error')->disableOriginalConstructor()->getMock(); $this->braintreeTransactionMock->expects($this->once())->method('cloneTransaction')->with($braintreeTransactionId, ['amount' => $amount, 'options' => ['submitForSettlement' => true]])->willReturn($resultError); $this->errorHelperMock->expects($this->once())->method('parseBraintreeError')->with($resultError)->willReturn(new \Magento\Framework\Phrase('error')); $this->model->capture($paymentObject, $amount); }