Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
TokenFormatterTest.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
12 
13 class TokenFormatterTest extends \PHPUnit\Framework\TestCase
14 {
18  private $paymentTokenMock;
19 
23  private $paypalTokenFormatter;
24 
28  private $tokenDetails = [
29  'type' => 'visa',
30  'maskedCC' => '4444************9999',
31  'expirationDate' => '07-07-2025'
32  ];
33 
37  protected function setUp()
38  {
39  $this->paymentTokenMock = $this->getMockBuilder(PaymentTokenInterface::class)
40  ->getMockForAbstractClass();
41 
42  $this->paypalTokenFormatter = new PaypalTokenFormatter();
43  }
44 
49  {
50  $this->tokenDetails['type'] = key(PaypalTokenFormatter::$baseCardTypes);
51  $this->paymentTokenMock->expects($this->once())
52  ->method('getTokenDetails')
53  ->willReturn(json_encode($this->tokenDetails));
54 
55  $formattedString = sprintf(
56  '%s: %s, %s: %s (%s: %s)',
57  __('Credit Card'),
58  reset(PaypalTokenFormatter::$baseCardTypes),
59  __('ending'),
60  $this->tokenDetails['maskedCC'],
61  __('expires'),
62  $this->tokenDetails['expirationDate']
63  );
64 
65  self::assertEquals($formattedString, $this->paypalTokenFormatter->formatPaymentToken($this->paymentTokenMock));
66  }
67 
72  {
73  $this->paymentTokenMock->expects($this->once())
74  ->method('getTokenDetails')
75  ->willReturn(json_encode($this->tokenDetails));
76 
77  $formattedString = sprintf(
78  '%s: %s, %s: %s (%s: %s)',
79  __('Credit Card'),
80  $this->tokenDetails['type'],
81  __('ending'),
82  $this->tokenDetails['maskedCC'],
83  __('expires'),
84  $this->tokenDetails['expirationDate']
85  );
86 
87  self::assertEquals($formattedString, $this->paypalTokenFormatter->formatPaymentToken($this->paymentTokenMock));
88  }
89 
94  {
95  unset($this->tokenDetails['type']);
96 
97  $this->paymentTokenMock->expects($this->once())
98  ->method('getTokenDetails')
99  ->willReturn(json_encode($this->tokenDetails));
100  self::expectException('\InvalidArgumentException');
101 
102  $this->paypalTokenFormatter->formatPaymentToken($this->paymentTokenMock);
103  }
104 }
__()
Definition: __.php:13