6 declare(strict_types=1);
12 use PHPUnit\Framework\TestCase;
13 use PHPUnit_Framework_MockObject_MockObject;
20 private $paymentTokenMock;
25 private $creditCardTokenFormatter;
30 private $tokenDetails = [
32 'maskedCC' =>
'1111************9999',
33 'expirationDate' =>
'01-01-2020' 43 $this->paymentTokenMock = $this->getMockBuilder(PaymentTokenInterface::class)
44 ->getMockForAbstractClass();
46 $this->creditCardTokenFormatter =
new CreditCardTokenFormatter();
56 $this->tokenDetails[
'type'] = key(CreditCardTokenFormatter::$baseCardTypes);
57 $this->paymentTokenMock->expects($this->once())
58 ->method(
'getTokenDetails')
59 ->willReturn(json_encode($this->tokenDetails));
61 $formattedString = sprintf(
62 '%s: %s, %s: %s (%s: %s)',
64 reset(CreditCardTokenFormatter::$baseCardTypes),
66 $this->tokenDetails[
'maskedCC'],
68 $this->tokenDetails[
'expirationDate']
73 $this->creditCardTokenFormatter->formatPaymentToken($this->paymentTokenMock)
84 $this->paymentTokenMock->expects($this->once())
85 ->method(
'getTokenDetails')
86 ->willReturn(json_encode($this->tokenDetails));
88 $formattedString = sprintf(
89 '%s: %s, %s: %s (%s: %s)',
91 $this->tokenDetails[
'type'],
93 $this->tokenDetails[
'maskedCC'],
95 $this->tokenDetails[
'expirationDate']
100 $this->creditCardTokenFormatter->formatPaymentToken($this->paymentTokenMock)
111 unset($this->tokenDetails[
'type']);
112 $this->paymentTokenMock->expects($this->once())
113 ->method(
'getTokenDetails')
114 ->willReturn(json_encode($this->tokenDetails));
115 self::expectException(
'\InvalidArgumentException');
117 $this->creditCardTokenFormatter->formatPaymentToken($this->paymentTokenMock);