8 use Braintree\Result\Successful;
9 use Braintree\Transaction;
10 use Braintree\Transaction\PayPalDetails;
16 use Magento\Sales\Api\Data\OrderPaymentExtensionInterface;
17 use Magento\Sales\Api\Data\OrderPaymentExtensionInterfaceFactory;
22 use PHPUnit\Framework\TestCase;
23 use PHPUnit_Framework_MockObject_MockObject as MockObject;
32 private static $transactionId =
'1n2suy';
34 private static $token =
'rc39al';
41 private $paymentDataObjectMock;
46 private $paymentInfoMock;
51 private $paymentTokenFactoryMock;
61 private $paymentExtensionMock;
66 private $paymentExtensionFactoryMock;
76 private $dateTimeFactoryMock;
81 private $subject = [];
87 $this->paymentDataObjectMock = $this->getMockForAbstractClass(PaymentDataObjectInterface::class);
89 $this->paymentInfoMock = $this->getMockBuilder(Payment::class)
90 ->disableOriginalConstructor()
91 ->setMethods([
'__wakeup',
'getExtensionAttributes'])
94 $this->paymentTokenMock =
$objectManager->getObject(PaymentToken::class);
96 $this->paymentTokenFactoryMock = $this->getMockBuilder(PaymentTokenFactoryInterface::class)
97 ->setMethods([
'create'])
98 ->disableOriginalConstructor()
101 $this->paymentExtensionMock = $this->getMockBuilder(OrderPaymentExtensionInterface::class)
102 ->setMethods([
'setVaultPaymentToken',
'getVaultPaymentToken'])
103 ->disableOriginalConstructor()
105 $this->paymentExtensionFactoryMock = $this->getMockBuilder(OrderPaymentExtensionInterfaceFactory::class)
106 ->disableOriginalConstructor()
107 ->setMethods([
'create'])
110 $this->paymentInfoMock->expects(self::any())
111 ->method(
'getExtensionAttributes')
112 ->willReturn($this->paymentExtensionMock);
115 'payment' => $this->paymentDataObjectMock,
118 $this->dateTimeFactoryMock = $this->getMockBuilder(DateTimeFactory::class)
119 ->disableOriginalConstructor()
120 ->setMethods([
'create'])
124 $this->paymentTokenFactoryMock,
125 $this->paymentExtensionFactoryMock,
127 $this->dateTimeFactoryMock
138 $this->paymentExtensionMock->method(
'setVaultPaymentToken')
139 ->with($this->paymentTokenMock);
140 $this->paymentExtensionMock->method(
'getVaultPaymentToken')
141 ->willReturn($this->paymentTokenMock);
143 $this->paymentDataObjectMock->method(
'getPayment')
144 ->willReturn($this->paymentInfoMock);
146 $this->paymentTokenFactoryMock->method(
'create')
148 ->willReturn($this->paymentTokenMock);
150 $this->paymentExtensionFactoryMock->method(
'create')
151 ->willReturn($this->paymentExtensionMock);
153 $dateTime = new \DateTime(
'2016-07-05 00:00:00',
new \DateTimeZone(
'UTC'));
154 $expirationDate =
'2017-07-05 00:00:00';
155 $this->dateTimeFactoryMock->method(
'create')
158 $this->handler->handle($this->subject,
$response);
164 $tokenDetails = json_decode(
$paymentToken->getTokenDetails(),
true);
169 self::assertEquals($expirationDate,
$paymentToken->getExpiresAt());
181 $this->paymentDataObjectMock->method(
'getPayment')
182 ->willReturn($this->paymentInfoMock);
184 $this->paymentTokenFactoryMock->expects(self::never())
187 $this->dateTimeFactoryMock->expects(self::never())
190 $this->handler->handle($this->subject,
$response);
191 self::assertNotNull($this->paymentInfoMock->getExtensionAttributes());
199 private function getTransaction(): Successful
202 'id' => self::$transactionId,
203 'paypalDetails' => $this->getPayPalDetails()
217 private function getPayPalDetails(): PayPalDetails