/** * @param string $params * @dataProvider dataProcessNonce */ public function testProcessNonceException($params = null, $exceptionMessage = null) { $this->customerSessionMock->expects($this->any())->method('getCustomerId')->willReturn($params['customerId']); $countryCollectionMock = $this->getMockBuilder('\\Magento\\Directory\\Model\\Resource\\Country\\Collection')->disableOriginalConstructor()->getMock(); $countryCollectionMock->expects($this->any())->method('addCountryCodeFilter')->willReturn($countryCollectionMock); $this->countryFactoryMock->expects($this->any())->method('create')->willReturn($countryCollectionMock); $this->configMock->expects($this->any())->method('canUseForCountry')->willReturn($params['canUseForCountry']); $this->configMock->expects($this->any())->method('canUseCcTypeForCountry')->willReturn($params['canUseCcTypeForCountry']); $this->helperMock->expects($this->any())->method('generateCustomerId')->willReturn($params['customerId']); $this->customerMock->expects($this->any())->method('load')->willReturn($this->customerMock); $this->customerFactoryMock->expects($this->any())->method('create')->willReturn($this->customerMock); if (is_object($params['paymentMethodObj'])) { if (!$params['optionsArray']['update']) { $this->braintreePaymentMethodMock->expects($this->once())->method('create')->willReturn($params['paymentMethodObj']); } else { $this->braintreePaymentMethodMock->expects($this->once())->method('update')->willReturn($params['paymentMethodObj']); } if (!$params['paymentMethodObj']->success) { $this->errorHelperMock->expects($this->once())->method('parseBraintreeError')->willReturn(new \Magento\Framework\Phrase($exceptionMessage)); } else { $this->errorHelperMock->expects($this->never())->method('parseBraintreeError'); } } try { $this->model->processNonce($params['nonce'], $params['optionsArray'], $params['billingAddress']); } catch (\Magento\Framework\Exception\LocalizedException $e) { $this->assertEquals($exceptionMessage, $e->getMessage()); } }
/** * @expectedException \Magento\Framework\Exception\LocalizedException * @expectedExceptionMessage There was an error capturing the transaction: error. */ public function testCaptureError() { $amount = self::AUTH_AMOUNT; $paymentId = 1005; $paymentObject = $this->setupPaymentObjectForCapture($paymentId); //setup braintree error response $resultError = $this->getMockBuilder('\\Braintree_Result_Error')->disableOriginalConstructor()->getMock(); $this->errorHelperMock->expects($this->once())->method('parseBraintreeError')->with($resultError)->willReturn(new \Magento\Framework\Phrase('error')); $this->braintreeTransactionMock->expects($this->once())->method('submitForSettlement')->with(self::AUTH_TRAN_ID, $amount)->willReturn($resultError); $this->psrLoggerMock->expects($this->once())->method('critical'); $this->model->capture($paymentObject, $amount); }
/** * @expectedException \Magento\Framework\Exception\LocalizedException * @expectedExceptionMessage There was an error voiding the transaction: error. */ public function testVoidError() { $orderId = 1005; $paymentObject = $this->setupPaymentObjectForVoid($orderId); $transactions = ['1' => \Braintree_Transaction::factory(['id' => '1', 'status' => \Braintree_Transaction::SUBMITTED_FOR_SETTLEMENT])]; $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) { $resultError = $this->getMockBuilder('\\Braintree_Result_Error')->disableOriginalConstructor()->getMock(); $this->errorHelperMock->expects($this->once())->method('parseBraintreeError')->with($resultError)->willReturn(new \Magento\Framework\Phrase('error')); $this->braintreeTransactionMock->expects($this->at($index))->method('void')->with($id)->willReturn($resultError); $index++; } $this->model->void($paymentObject); }