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); }
/** * @inheritdoc * @throws \Exception */ public function execute(array $commandSubject) { $publicHash = $this->subjectReader->readPublicHash($commandSubject); $customerId = $this->subjectReader->readCustomerId($commandSubject); $paymentToken = $this->tokenManagement->getByPublicHash($publicHash, $customerId); if (!$paymentToken) { throw new Exception('No available payment tokens'); } $data = $this->adapter->createNonce($paymentToken->getGatewayToken()); $result = $this->responseValidator->validate(['response' => ['object' => $data]]); if (!$result->isValid()) { throw new Exception(__(implode("\n", $result->getFailsDescription()))); } return $this->resultFactory->create(['array' => ['paymentMethodNonce' => $data->paymentMethodNonce->nonce]]); }
/** * @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']); }