Skip to content

Commit 2d85db3

Browse files
dmytro-chronak2ram
authored andcommitted
Braintree: Add unit test for PaymentAdditionalInformationProvider
1 parent 3ab543e commit 2d85db3

File tree

1 file changed

+83
-0
lines changed

1 file changed

+83
-0
lines changed
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Braintree\Test\Unit\Model\InstantPurchase\CreditCard;
9+
10+
use Magento\Braintree\Gateway\Command\GetPaymentNonceCommand;
11+
use Magento\Braintree\Model\InstantPurchase\PaymentAdditionalInformationProvider;
12+
use Magento\Payment\Gateway\Command\Result\ArrayResult;
13+
use Magento\Vault\Api\Data\PaymentTokenInterface;
14+
15+
/**
16+
* @covers \Magento\Braintree\Model\InstantPurchase\PaymentAdditionalInformationProvider
17+
*/
18+
class PaymentAdditionalInformationProviderTest extends \PHPUnit\Framework\TestCase
19+
{
20+
/**
21+
* Testable Object
22+
*
23+
* @var PaymentAdditionalInformationProvider
24+
*/
25+
private $paymentAdditionalInformationProvider;
26+
27+
/**
28+
* @var GetPaymentNonceCommand|\PHPUnit_Framework_MockObject_MockObject
29+
*/
30+
private $getPaymentNonceCommandMock;
31+
32+
/**
33+
* @var PaymentTokenInterface|\PHPUnit_Framework_MockObject_MockObject
34+
*/
35+
private $paymentTokenMock;
36+
37+
/**
38+
* @var ArrayResult|\PHPUnit_Framework_MockObject_MockObject
39+
*/
40+
private $arrayResultMock;
41+
42+
/**
43+
* Set Up
44+
*
45+
* @return void
46+
*/
47+
protected function setUp()
48+
{
49+
$this->getPaymentNonceCommandMock = $this->createMock(GetPaymentNonceCommand::class);
50+
$this->paymentTokenMock = $this->createMock(PaymentTokenInterface::class);
51+
$this->arrayResultMock = $this->createMock(ArrayResult::class);
52+
$this->paymentAdditionalInformationProvider = new PaymentAdditionalInformationProvider(
53+
$this->getPaymentNonceCommandMock
54+
);
55+
}
56+
57+
/**
58+
* Test getAdditionalInformation method
59+
*
60+
* @return void
61+
*/
62+
public function testGetAdditionalInformation()
63+
{
64+
$customerId = 15;
65+
$publicHash = '3n4b7sn48g';
66+
$paymentMethodNonce = 'test';
67+
68+
$this->paymentTokenMock->expects($this->once())->method('getCustomerId')->willReturn($customerId);
69+
$this->paymentTokenMock->expects($this->once())->method('getPublicHash')->willReturn($publicHash);
70+
$this->getPaymentNonceCommandMock->expects($this->once())->method('execute')->with([
71+
PaymentTokenInterface::CUSTOMER_ID => $customerId,
72+
PaymentTokenInterface::PUBLIC_HASH => $publicHash,
73+
])->willReturn($this->arrayResultMock);
74+
$this->arrayResultMock->expects($this->once())->method('get')
75+
->willReturn(['paymentMethodNonce' => $paymentMethodNonce]);
76+
77+
$expected = [
78+
'payment_method_nonce' => $paymentMethodNonce,
79+
];
80+
$actual = $this->paymentAdditionalInformationProvider->getAdditionalInformation($this->paymentTokenMock);
81+
self::assertEquals($expected, $actual);
82+
}
83+
}

0 commit comments

Comments
 (0)