Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CustomerTokenManagementTest.php
Go to the documentation of this file.
1 <?php
7 
12 use PHPUnit_Framework_MockObject_MockObject as MockObject;
13 
14 class CustomerTokenManagementTest extends \PHPUnit\Framework\TestCase
15 {
19  private $paymentTokenManagement;
20 
24  private $customerSession;
25 
29  private $tokenManagement;
30 
31  protected function setUp()
32  {
33  $this->paymentTokenManagement = $this->getMockBuilder(PaymentTokenManagement::class)
34  ->disableOriginalConstructor()
35  ->getMock();
36  $this->customerSession = $this->getMockBuilder(Session::class)
37  ->disableOriginalConstructor()
38  ->getMock();
39 
40  $this->tokenManagement = new CustomerTokenManagement(
41  $this->paymentTokenManagement,
42  $this->customerSession
43  );
44  }
45 
52  public function testGetCustomerSessionTokensNegative($customerId, bool $isLoggedCustomer)
53  {
54  $this->customerSession->method('getCustomerId')->willReturn($customerId);
55  $this->customerSession->method('isLoggedIn')->willReturn($isLoggedCustomer);
56  $this->paymentTokenManagement->expects(static::never())->method('getVisibleAvailableTokens');
57 
58  static::assertEquals([], $this->tokenManagement->getCustomerSessionTokens());
59  }
60 
65  {
66  return [
67  'not registered customer' => [null, false],
68  'not logged in customer' => [1, false],
69  ];
70  }
71 
72  public function testGetCustomerSessionTokens()
73  {
74  $customerId = 1;
75  $token = $this->createMock(PaymentTokenInterface::class);
76  $expectation = [$token];
77 
78  $this->customerSession->expects(static::once())
79  ->method('getCustomerId')
80  ->willReturn($customerId);
81 
82  $this->customerSession->expects(static::once())
83  ->method('isLoggedIn')
84  ->willReturn(true);
85 
86  $this->paymentTokenManagement->expects(static::once())
87  ->method('getVisibleAvailableTokens')
88  ->with($customerId)
89  ->willReturn($expectation);
90 
91  static::assertEquals(
92  $expectation,
93  $this->tokenManagement->getCustomerSessionTokens()
94  );
95  }
96 }