public function testGetCustomerSessionTokens() { $customerId = 1; $token = $this->getMock(PaymentTokenInterface::class); $expectation = [$token]; $this->customerSession->expects(static::once())->method('getCustomerId')->willReturn($customerId); $this->paymentTokenManagement->expects(static::once())->method('getVisibleAvailableTokens')->with($customerId)->willReturn($expectation); static::assertEquals($expectation, $this->tokenManagement->getCustomerSessionTokens()); }
public function testGetCustomerSessionTokens() { $customerId = 1; $providerCode = 'vault_provider'; $storeId = 1; $token = $this->getMock(PaymentTokenInterface::class); $expectation = [$token]; $this->customerSessionMock->expects(self::once())->method('getCustomerId')->willReturn($customerId); $this->storeManager->expects(static::once())->method('getStore')->with(null)->willReturn($this->store); $this->store->expects(static::once())->method('getId')->willReturn($storeId); $this->vaultPayment->expects(static::once())->method('isActive')->with($storeId)->willReturn(true); $this->vaultPayment->expects(static::once())->method('getProviderCode')->with($storeId)->willReturn($providerCode); $this->paymentTokenManagementMock->expects(static::once())->method('getVisibleAvailableTokens')->with($customerId, $providerCode)->willReturn($expectation); static::assertEquals($expectation, $this->tokenManagement->getCustomerSessionTokens()); }
/** * @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']); }