Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
VaultConfigProviderTest.php
Go to the documentation of this file.
1 <?php
7 
15 use PHPUnit_Framework_MockObject_MockObject as MockObject;
16 
20 class VaultConfigProviderTest extends \PHPUnit\Framework\TestCase
21 {
25  private $vaultPayment;
26 
30  private $session;
31 
35  private $store;
36 
40  private $storeManager;
41 
45  private $vaultPaymentList;
46 
50  private $vaultConfigProvider;
51 
52  protected function setUp()
53  {
54  $this->vaultPayment = $this->getMockForAbstractClass(VaultPaymentInterface::class);
55  $this->storeManager = $this->getMockForAbstractClass(StoreManagerInterface::class);
56  $this->store = $this->getMockForAbstractClass(StoreInterface::class);
57  $this->session = $this->getMockBuilder(Session::class)
58  ->disableOriginalConstructor()
59  ->getMock();
60  $this->vaultPaymentList = $this->createMock(PaymentMethodListInterface::class);
61 
62  $objectManager = new ObjectManager($this);
63  $this->vaultConfigProvider = new VaultConfigProvider($this->storeManager, $this->session);
64  $objectManager->setBackwardCompatibleProperty(
65  $this->vaultConfigProvider,
66  'vaultPaymentList',
67  $this->vaultPaymentList
68  );
69  }
70 
76  public function testGetConfig($customerId, $vaultEnabled)
77  {
78  $storeId = 1;
79  $vaultPaymentCode = 'vault_payment';
80 
81  $expectedConfiguration = [
82  'vault' => [
83  $vaultPaymentCode => [
84  'is_enabled' => $vaultEnabled
85  ],
86  ]
87  ];
88 
89  $this->session->expects(static::once())
90  ->method('getCustomerId')
91  ->willReturn($customerId);
92  $this->storeManager->expects(static::once())
93  ->method('getStore')
94  ->willReturn($this->store);
95  $this->store->expects(static::once())
96  ->method('getId')
97  ->willReturn($storeId);
98 
99  $this->vaultPaymentList->expects(static::once())
100  ->method('getActiveList')
101  ->willReturn([$this->vaultPayment]);
102 
103  $this->vaultPayment->expects(static::once())
104  ->method('getCode')
105  ->willReturn($vaultPaymentCode);
106  $this->vaultPayment->expects($customerId !== null ? static::once() : static::never())
107  ->method('isActive')
108  ->with($storeId)
109  ->willReturn($vaultEnabled);
110 
111  static::assertEquals($expectedConfiguration, $this->vaultConfigProvider->getConfig());
112  }
113 
117  public function customerIdProvider()
118  {
119  return [
120  [
121  'id' => 1,
122  'vault_enabled' => true
123  ],
124  [
125  'id' => null,
126  'vault_enabled' => false
127  ]
128  ];
129  }
130 }
$objectManager
Definition: bootstrap.php:17
return false
Definition: gallery.phtml:36