/** * @param array $billingData * @param array $expectedResult * * @dataProvider dataProviderBuild */ public function testBuild($billingData, $expectedResult) { $billingMock = $this->getBillingMock($billingData); $this->paymentDOMock->expects(static::once())->method('getOrder')->willReturn($this->orderMock); $this->orderMock->expects(static::once())->method('getBillingAddress')->willReturn($billingMock); $buildSubject = ['payment' => $this->paymentDOMock]; $this->subjectReaderMock->expects(self::once())->method('readPayment')->with($buildSubject)->willReturn($this->paymentDOMock); self::assertEquals($expectedResult, $this->builder->build($buildSubject)); }
/** * Run test for validate method * * @param array $validationSubject * @param bool $isValid * @return void * * @dataProvider dataProviderTestValidate */ public function testValidate(array $validationSubject, $isValid) { /** @var ResultInterface|\PHPUnit_Framework_MockObject_MockObject $resultMock */ $resultMock = $this->getMock(ResultInterface::class); $this->subjectReaderMock->expects(self::once())->method('readResponseObject')->with($validationSubject)->willReturn($validationSubject['response']['object']); $this->resultInterfaceFactoryMock->expects(self::once())->method('create')->with(['isValid' => $isValid, 'failsDescription' => ['Transaction has been declined, please, try again later.']])->willReturn($resultMock); $actualMock = $this->responseValidator->validate($validationSubject); self::assertEquals($resultMock, $actualMock); }
/** * @covers \Magento\BraintreeTwo\Gateway\Response\CaptureDetailsHandler::handle */ public function testHandle() { $paymentData = $this->getPaymentDataObjectMock(); $subject['payment'] = $paymentData; $this->payment->expects(static::once())->method('setIsTransactionClosed')->with(false); $response = ['object' => ['success' => true]]; $this->subjectReader->expects(self::once())->method('readPayment')->with($subject)->willReturn($paymentData); $this->captureHandler->handle($subject, $response); }
/** * @covers \Magento\BraintreeTwo\Gateway\Response\PaymentDetailsHandler::handle */ public function testHandle() { $paymentData = $this->getPaymentDataObjectMock(); $transaction = $this->getBraintreeTransaction(); $subject = ['payment' => $paymentData]; $response = ['object' => $transaction]; $this->subjectReader->expects(self::once())->method('readPayment')->with($subject)->willReturn($paymentData); $this->subjectReader->expects(self::once())->method('readTransaction')->with($response)->willReturn($transaction); $this->paymentHandler->handle($subject, $response); }
/** * @covers \Magento\BraintreeTwo\Gateway\Response\CloneDetailsHandler::handle */ public function testHandle() { $paymentData = $this->getPaymentDataObjectMock(); $transaction = $this->getBraintreeTransaction(); $subject['payment'] = $paymentData; $this->payment->expects(static::once())->method('setTransactionId')->with(self::TRANSACTION_ID); $response = ['object' => $transaction]; $this->subjectReader->expects(self::once())->method('readPayment')->with($subject)->willReturn($paymentData); $this->subjectReader->expects(self::once())->method('readTransaction')->with($response)->willReturn($transaction); $this->cloneHandler->handle($subject, $response); }
public function testBuild() { $additionalData = [DataAssignObserver::DEVICE_DATA => self::DEVICE_DATA]; $expectedResult = [KountPaymentDataBuilder::DEVICE_DATA => self::DEVICE_DATA]; $buildSubject = ['payment' => $this->paymentDO]; $this->paymentMock->expects(static::exactly(count($additionalData)))->method('getAdditionalInformation')->willReturn($additionalData); $this->configMock->expects(static::once())->method('hasFraudProtection')->willReturn(true); $this->paymentDO->expects(static::once())->method('getPayment')->willReturn($this->paymentMock); $this->subjectReaderMock->expects(self::once())->method('readPayment')->with($buildSubject)->willReturn($this->paymentDO); static::assertEquals($expectedResult, $this->builder->build($buildSubject)); }
/** * @covers \Magento\BraintreeTwo\Gateway\Response\ThreeDSecureDetailsHandler::handle */ public function testHandle() { $paymentData = $this->getPaymentDataObjectMock(); $transaction = $this->getBraintreeTransaction(); $subject = ['payment' => $paymentData]; $response = ['object' => $transaction]; $this->subjectReaderMock->expects(self::once())->method('readPayment')->with($subject)->willReturn($paymentData); $this->subjectReaderMock->expects(self::once())->method('readTransaction')->with($response)->willReturn($transaction); $this->payment->expects(static::at(1))->method('setAdditionalInformation')->with('liabilityShifted', 'Yes'); $this->payment->expects(static::at(2))->method('setAdditionalInformation')->with('liabilityShiftPossible', 'Yes'); $this->handler->handle($subject, $response); }
/** * @param bool $verify * @param float $thresholdAmount * @param string $countryId * @param array $countries * @param array $expected * @covers \Magento\BraintreeTwo\Gateway\Request\ThreeDSecureDataBuilder::build * @dataProvider buildDataProvider */ public function testBuild($verify, $thresholdAmount, $countryId, array $countries, array $expected) { $buildSubject = ['payment' => $this->paymentDO, 'amount' => 25]; $this->configMock->expects(static::once())->method('isVerify3DSecure')->willReturn($verify); $this->configMock->expects(static::any())->method('getThresholdAmount')->willReturn($thresholdAmount); $this->configMock->expects(static::any())->method('get3DSecureSpecificCountries')->willReturn($countries); $this->billingAddress->expects(static::any())->method('getCountryId')->willReturn($countryId); $this->subjectReaderMock->expects(self::once())->method('readPayment')->with($buildSubject)->willReturn($this->paymentDO); $this->subjectReaderMock->expects(self::once())->method('readAmount')->with($buildSubject)->willReturn(25); $result = $this->builder->build($buildSubject); static::assertEquals($expected, $result); }
public function testBuild() { $additionalData = [[DataAssignObserver::PAYMENT_METHOD_NONCE, self::PAYMENT_METHOD_NONCE]]; $expectedResult = [PaymentDataBuilder::AMOUNT => 10.0, PaymentDataBuilder::PAYMENT_METHOD_NONCE => self::PAYMENT_METHOD_NONCE, PaymentDataBuilder::MERCHANT_ACCOUNT_ID => self::MERCHANT_ACCOUNT_ID]; $buildSubject = ['payment' => $this->paymentDO, 'amount' => 10.0]; $this->paymentMock->expects(static::exactly(count($additionalData)))->method('getAdditionalInformation')->willReturnMap($additionalData); $this->configMock->expects(static::once())->method('getValue')->with(Config::KEY_MERCHANT_ACCOUNT_ID)->willReturn(self::MERCHANT_ACCOUNT_ID); $this->paymentDO->expects(static::once())->method('getPayment')->willReturn($this->paymentMock); $this->subjectReaderMock->expects(self::once())->method('readPayment')->with($buildSubject)->willReturn($this->paymentDO); $this->subjectReaderMock->expects(self::once())->method('readAmount')->with($buildSubject)->willReturn(10.0); static::assertEquals($expectedResult, $this->builder->build($buildSubject)); }
/** * @covers \Magento\BraintreeTwo\Gateway\Response\PayPalDetailsHandler::handle */ public function testHandle() { $paymentData = $this->getPaymentDataObjectMock(); $transaction = $this->getBraintreeTransaction(); $subject = ['payment' => $paymentData]; $response = ['object' => $transaction]; $this->subjectReader->expects(self::once())->method('readPayment')->with($subject)->willReturn($paymentData); $this->subjectReader->expects(self::once())->method('readTransaction')->with($response)->willReturn($transaction); $this->subjectReader->expects(static::once())->method('readPayPal')->with($transaction)->willReturn($transaction->paypal); $this->payment->expects(static::exactly(2))->method('setAdditionalInformation'); $this->payPalHandler->handle($subject, $response); }
/** * @covers \Magento\BraintreeTwo\Gateway\Request\CaptureDataBuilder::build */ public function testBuild() { $transactionId = 'b3b99d'; $amount = 10.0; $expected = ['transaction_id' => $transactionId, 'amount' => $amount]; $buildSubject = ['payment' => $this->paymentDO, 'amount' => $amount]; $this->payment->expects(static::once())->method('getCcTransId')->willReturn($transactionId); $this->paymentDO->expects(static::once())->method('getPayment')->willReturn($this->payment); $this->subjectReaderMock->expects(self::once())->method('readPayment')->with($buildSubject)->willReturn($this->paymentDO); $this->subjectReaderMock->expects(self::once())->method('readAmount')->with($buildSubject)->willReturn($amount); static::assertEquals($expected, $this->builder->build($buildSubject)); }
public function testValidateSuccess() { $obj = new \stdClass(); $obj->success = true; $obj->paymentMethodNonce = new \stdClass(); $obj->paymentMethodNonce->nonce = 'fj2hd9239kd1kq9'; $subject = ['response' => ['object' => $obj]]; $this->subjectReader->expects(static::once())->method('readResponseObject')->willReturn($obj); $result = $this->getMock(ResultInterface::class); $this->resultInterfaceFactory->expects(self::once())->method('create')->with(['isValid' => true, 'failsDescription' => []])->willReturn($result); $actual = $this->validator->validate($subject); static::assertEquals($result, $actual); }
/** * \Magento\BraintreeTwo\Gateway\Request\VaultCaptureDataBuilder::build */ public function testBuild() { $amount = 30.0; $token = '5tfm4c'; $buildSubject = ['payment' => $this->paymentDO, 'amount' => $amount]; $expected = ['amount' => $amount, 'paymentMethodToken' => $token]; $this->subjectReader->expects(self::once())->method('readPayment')->with($buildSubject)->willReturn($this->paymentDO); $this->subjectReader->expects(self::once())->method('readAmount')->with($buildSubject)->willReturn($amount); $paymentExtension = $this->getMockBuilder(OrderPaymentExtension::class)->setMethods(['getVaultPaymentToken'])->disableOriginalConstructor()->getMock(); $paymentToken = $this->getMockBuilder(PaymentToken::class)->disableOriginalConstructor()->getMock(); $paymentExtension->expects(static::once())->method('getVaultPaymentToken')->willReturn($paymentToken); $this->payment->expects(static::once())->method('getExtensionAttributes')->willReturn($paymentExtension); $paymentToken->expects(static::once())->method('getGatewayToken')->willReturn($token); $result = $this->builder->build($buildSubject); static::assertEquals($expected, $result); }
/** * @covers \Magento\BraintreeTwo\Gateway\Command\GetPaymentNonceCommand::execute */ public function testExecute() { $publicHash = '3wv2m24d2er3'; $customerId = 1; $token = 'jd2vnq'; $nonce = 's1dj23'; $this->subjectReader->expects(static::once())->method('readPublicHash')->willReturn($publicHash); $this->subjectReader->expects(static::once())->method('readCustomerId')->willReturn($customerId); $this->tokenManagement->expects(static::once())->method('getByPublicHash')->with($publicHash, $customerId)->willReturn($this->paymentToken); $this->paymentToken->expects(static::once())->method('getGatewayToken')->willReturn($token); $obj = new \stdClass(); $obj->success = true; $obj->paymentMethodNonce = new \stdClass(); $obj->paymentMethodNonce->nonce = $nonce; $this->adapter->expects(static::once())->method('createNonce')->with($token)->willReturn($obj); $this->responseValidator->expects(static::once())->method('validate')->with(['response' => ['object' => $obj]])->willReturn($this->validationResult); $this->validationResult->expects(static::once())->method('isValid')->willReturn(true); $this->validationResult->expects(static::never())->method('getFailsDescription'); $expected = $this->getMockBuilder(ArrayResult::class)->disableOriginalConstructor()->setMethods(['get'])->getMock(); $expected->expects(static::once())->method('get')->willReturn(['paymentMethodNonce' => $nonce]); $this->resultFactory->expects(static::once())->method('create')->willReturn($expected); $actual = $this->command->execute(['publicHash' => $publicHash, 'customerId' => $customerId]); static::assertEquals($expected, $actual); static::assertEquals($nonce, $actual->get()['paymentMethodNonce']); }
/** * @covers \Magento\BraintreeTwo\Gateway\Command\CaptureStrategyCommand::execute */ public function testVaultCaptureExecute() { $paymentData = $this->getPaymentDataObjectMock(); $subject['payment'] = $paymentData; $this->subjectReaderMock->expects(self::once())->method('readPayment')->with($subject)->willReturn($paymentData); $this->payment->expects(static::once())->method('getAuthorizationTransaction')->willReturn(true); $this->payment->expects(static::once())->method('getId')->willReturn(1); $this->buildSearchCriteria(); $this->transactionRepository->expects(static::once())->method('getTotalCount')->willReturn(1); $this->commandPool->expects(static::once())->method('get')->with(CaptureStrategyCommand::VAULT_CAPTURE)->willReturn($this->command); $this->strategyCommand->execute($subject); }
/** * @covers \Magento\BraintreeTwo\Gateway\Command\CaptureStrategyCommand::execute */ public function testCloneExecute() { $paymentData = $this->getPaymentDataObjectMock(); $subject['payment'] = $paymentData; $this->subjectReaderMock->expects(self::once())->method('readPayment')->with($subject)->willReturn($paymentData); $this->payment->expects(static::once())->method('getAuthorizationTransaction')->willReturn(true); $this->payment->expects(static::once())->method('getId')->willReturn(1); $this->buildSearchCriteria(); $this->transactionRepository->expects(static::once())->method('getTotalCount')->willReturn(1); $paymentExtension = $this->getMockBuilder(OrderPaymentExtension::class)->setMethods(['getVaultPaymentToken'])->disableOriginalConstructor()->getMock(); $paymentExtension->expects(static::once())->method('getVaultPaymentToken')->willReturn(null); $this->payment->expects(static::once())->method('getExtensionAttributes')->willReturn($paymentExtension); $this->commandPool->expects(static::once())->method('get')->with(CaptureStrategyCommand::CLONE_TRANSACTION)->willReturn($this->command); $this->strategyCommand->execute($subject); }
/** * @covers \Magento\BraintreeTwo\Gateway\Response\VaultDetailsHandler::handle */ public function testHandle() { $this->paymentExtension->expects(self::once())->method('setVaultPaymentToken')->with($this->paymentToken); $this->paymentExtension->expects(self::once())->method('getVaultPaymentToken')->willReturn($this->paymentToken); $paymentData = $this->getPaymentDataObjectMock(); $transaction = $this->getBraintreeTransaction(); $subject = ['payment' => $paymentData]; $response = ['object' => $transaction]; $this->subjectReader->expects(self::once())->method('readPayment')->with($subject)->willReturn($paymentData); $this->subjectReader->expects(self::once())->method('readTransaction')->with($response)->willReturn($transaction); $this->paymentToken->expects(static::once())->method('setGatewayToken')->with('rh3gd4'); $this->paymentToken->expects(static::once())->method('setExpiresAt')->with('2022-01-01 00:00:00'); $this->paymentHandler->handle($subject, $response); $this->assertSame($this->paymentToken, $this->payment->getExtensionAttributes()->getVaultPaymentToken()); }
/** * @covers \Magento\BraintreeTwo\Gateway\Response\VaultDetailsHandler::handle */ public function testHandle() { $this->vaultPaymentMock->expects(self::once())->method('isActiveForPayment')->willReturn(true); $this->paymentExtension->expects(self::once())->method('setVaultPaymentToken')->with($this->paymentTokenMock); $this->paymentExtension->expects(self::once())->method('getVaultPaymentToken')->willReturn($this->paymentTokenMock); $paymentData = $this->getPaymentDataObjectMock(); $transaction = $this->getBraintreeTransaction(); $subject = ['payment' => $paymentData]; $response = ['object' => $transaction]; $this->subjectReaderMock->expects(self::once())->method('readPayment')->with($subject)->willReturn($paymentData); $this->subjectReaderMock->expects(self::once())->method('readTransaction')->with($response)->willReturn($transaction); $this->salesOrderMock->setCustomerId(10); $this->paymentHandler->handle($subject, $response); $this->assertEquals('rh3gd4', $this->paymentTokenMock->getGatewayToken()); $this->assertEquals('10', $this->paymentTokenMock->getCustomerId()); $this->assertSame($this->paymentTokenMock, $this->payment->getExtensionAttributes()->getVaultPaymentToken()); }
/** * @param int $size * @param string $command * @covers \Magento\BraintreeTwo\Gateway\Command\CaptureStrategyCommand::execute * @dataProvider captureDataProvider */ public function testCaptureExecute($size, $command) { $paymentData = $this->getPaymentDataObjectMock(); $subject['payment'] = $paymentData; $this->subjectReaderMock->expects(self::once())->method('readPayment')->with($subject)->willReturn($paymentData); $this->payment->expects(static::once())->method('getAuthorizationTransaction')->willReturn(true); $this->payment->expects(static::once())->method('getId')->willReturn(1); $this->filterBuilder->expects(static::exactly(2))->method('setField')->willReturnSelf(); $this->filterBuilder->expects(static::exactly(2))->method('setValue')->willReturnSelf(); $searchCriteria = new SearchCriteria(); $this->searchCriteriaBuilder->expects(static::once())->method('addFilters')->willReturnSelf(); $this->searchCriteriaBuilder->expects(static::once())->method('create')->willReturn($searchCriteria); $this->transactionRepository->expects(static::once())->method('getList')->with($searchCriteria)->willReturnSelf(); $this->transactionRepository->expects(static::once())->method('getTotalCount')->willReturn($size); $this->commandPool->expects(static::once())->method('get')->with($command)->willReturn($this->command); $this->strategyCommand->execute($subject); }