Skip to content

Commit 1cf1f8a

Browse files
committed
MAGETWO-57990: Implement Active Payments API
- Fix unit tests - Fix doc blocks
1 parent 4664e11 commit 1cf1f8a

File tree

7 files changed

+190
-81
lines changed

7 files changed

+190
-81
lines changed

app/code/Magento/Payment/Test/Unit/Gateway/Http/Client/SoapTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ protected function setUp()
4848
\Magento\Payment\Gateway\Http\ConverterInterface::class
4949
)->getMockForAbstractClass();
5050
$this->client = $this->getMockBuilder(\SoapClient::class)
51+
->setMethods(['__setSoapHeaders', '__soapCall', '__getLastRequest'])
5152
->disableOriginalConstructor()
5253
->getMock();
5354

app/code/Magento/Payment/Test/Unit/Model/MethodListTest.php

Lines changed: 43 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,14 @@ class MethodListTest extends \PHPUnit_Framework_TestCase
2424
protected $objectManager;
2525

2626
/**
27-
* @var \PHPUnit_Framework_MockObject_MockObject
27+
* @var \Magento\Payment\Api\PaymentMethodListInterface|\PHPUnit_Framework_MockObject_MockObject
28+
*/
29+
private $paymentMethodList;
30+
31+
/**
32+
* @var \Magento\Payment\Model\Method\InstanceFactory|\PHPUnit_Framework_MockObject_MockObject
2833
*/
29-
protected $paymentHelperMock;
34+
private $paymentMethodInstanceFactory;
3035

3136
/**
3237
* @var \PHPUnit_Framework_MockObject_MockObject
@@ -36,17 +41,35 @@ class MethodListTest extends \PHPUnit_Framework_TestCase
3641
protected function setUp()
3742
{
3843
$this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
39-
$this->paymentHelperMock = $this->getMock(\Magento\Payment\Helper\Data::class, [], [], '', false);
40-
$this->specificationFactoryMock = $this->getMock(
44+
45+
$this->paymentMethodList = $this->getMockBuilder(\Magento\Payment\Api\PaymentMethodListInterface::class)
46+
->disableOriginalConstructor()
47+
->getMockForAbstractClass();
48+
49+
$this->paymentMethodInstanceFactory = $this->getMockBuilder(
50+
\Magento\Payment\Model\Method\InstanceFactory::class
51+
)->disableOriginalConstructor()->getMock();
52+
53+
$this->specificationFactoryMock = $this->getMock(
4154
\Magento\Payment\Model\Checks\SpecificationFactory::class, [], [], '', false
4255
);
43-
$this->methodList = $this->objectManager->getObject(
56+
$this->methodList = $this->objectManager->getObject(
4457
\Magento\Payment\Model\MethodList::class,
4558
[
46-
'paymentHelper' => $this->paymentHelperMock,
4759
'specificationFactory' => $this->specificationFactoryMock
4860
]
4961
);
62+
63+
$this->objectManager->setBackwardCompatibleProperty(
64+
$this->methodList,
65+
'paymentMethodList',
66+
$this->paymentMethodList
67+
);
68+
$this->objectManager->setBackwardCompatibleProperty(
69+
$this->methodList,
70+
'paymentMethodInstanceFactory',
71+
$this->paymentMethodInstanceFactory
72+
);
5073
}
5174

5275
public function testGetAvailableMethods()
@@ -58,12 +81,15 @@ public function testGetAvailableMethods()
5881
->method('getPayment')
5982
->will($this->returnValue($this->getMock(\Magento\Quote\Model\Quote\Payment::class, [], [], '', false)));
6083

61-
$methodMock = $this->getMock(\Magento\Payment\Model\Method\AbstractMethod::class, [], [], '', false);
84+
$methodInstanceMock = $this->getMock(\Magento\Payment\Model\Method\AbstractMethod::class, [], [], '', false);
85+
$methodInstanceMock->expects($this->once())
86+
->method('isAvailable')
87+
->willReturn(true);
6288

6389
$compositeMock = $this->getMock(\Magento\Payment\Model\Checks\Composite::class, [], [], '', false);
6490
$compositeMock->expects($this->atLeastOnce())
6591
->method('isApplicable')
66-
->with($methodMock, $quoteMock)
92+
->with($methodInstanceMock, $quoteMock)
6793
->will($this->returnValue(true));
6894

6995
$this->specificationFactoryMock->expects($this->atLeastOnce())
@@ -76,18 +102,19 @@ public function testGetAvailableMethods()
76102
])
77103
->will($this->returnValue($compositeMock));
78104

79-
$storeMethods = [$methodMock];
80-
81-
$this->paymentHelperMock->expects($this->once())
82-
->method('getStoreMethods')
83-
->with($storeId, $quoteMock)
84-
->will($this->returnValue($storeMethods));
105+
$methodMock = $this->getMockForAbstractClass(\Magento\Payment\Api\Data\PaymentMethodInterface::class);
106+
$this->paymentMethodList->expects($this->once())
107+
->method('getActiveList')
108+
->willReturn([$methodMock]);
109+
$this->paymentMethodInstanceFactory->expects($this->once())
110+
->method('create')
111+
->willReturn($methodInstanceMock);
85112

86-
$methodMock->expects($this->atLeastOnce())
113+
$methodInstanceMock->expects($this->atLeastOnce())
87114
->method('setInfoInstance')
88115
->with($this->getMock(\Magento\Quote\Model\Quote\Payment::class, [], [], '', false))
89116
->will($this->returnSelf());
90117

91-
$this->assertEquals([$methodMock], $this->methodList->getAvailableMethods($quoteMock));
118+
$this->assertEquals([$methodInstanceMock], $this->methodList->getAvailableMethods($quoteMock));
92119
}
93120
}

app/code/Magento/Paypal/Test/Unit/Helper/DataTest.php

Lines changed: 67 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,14 @@
88
class DataTest extends \PHPUnit_Framework_TestCase
99
{
1010
/**
11-
* @var \PHPUnit_Framework_MockObject_MockObject
11+
* @var \Magento\Payment\Api\PaymentMethodListInterface|\PHPUnit_Framework_MockObject_MockObject
1212
*/
13-
protected $_paymentDataMock;
13+
private $paymentMethodList;
14+
15+
/**
16+
* @var \Magento\Payment\Model\Method\InstanceFactory|\PHPUnit_Framework_MockObject_MockObject
17+
*/
18+
private $paymentMethodInstanceFactory;
1419

1520
/**
1621
* @var \Magento\Paypal\Model\Config | \PHPUnit_Framework_MockObject_MockObject
@@ -24,11 +29,13 @@ class DataTest extends \PHPUnit_Framework_TestCase
2429

2530
protected function setUp()
2631
{
27-
$this->_paymentDataMock = $this->getMockBuilder(
28-
\Magento\Payment\Helper\Data::class
29-
)->disableOriginalConstructor()->setMethods(
30-
['getStoreMethods', 'getPaymentMethods']
31-
)->getMock();
32+
$this->paymentMethodList = $this->getMockBuilder(\Magento\Payment\Api\PaymentMethodListInterface::class)
33+
->disableOriginalConstructor()
34+
->getMockForAbstractClass();
35+
36+
$this->paymentMethodInstanceFactory = $this->getMockBuilder(
37+
\Magento\Payment\Model\Method\InstanceFactory::class
38+
)->disableOriginalConstructor()->getMock();
3239

3340
$this->configMock = $this->getMock(
3441
\Magento\Paypal\Model\Config::class,
@@ -48,32 +55,41 @@ protected function setUp()
4855
$this->_helper = $objectManager->getObject(
4956
\Magento\Paypal\Helper\Data::class,
5057
[
51-
'paymentData' => $this->_paymentDataMock,
5258
'methodCodes' => ['expressCheckout' => 'paypal_express', 'hostedPro' => 'hosted_pro'],
5359
'configFactory' => $configMockFactory
5460
]
5561
);
62+
63+
$objectManager->setBackwardCompatibleProperty(
64+
$this->_helper,
65+
'paymentMethodList',
66+
$this->paymentMethodList
67+
);
68+
$objectManager->setBackwardCompatibleProperty(
69+
$this->_helper,
70+
'paymentMethodInstanceFactory',
71+
$this->paymentMethodInstanceFactory
72+
);
5673
}
5774

5875
/**
5976
* @dataProvider getBillingAgreementMethodsDataProvider
6077
* @param $store
6178
* @param $quote
62-
* @param $paymentMethods
79+
* @param $paymentMethodsMap
6380
* @param $expectedResult
6481
*/
65-
public function testGetBillingAgreementMethods($store, $quote, $paymentMethods, $expectedResult)
82+
public function testGetBillingAgreementMethods($store, $quote, $paymentMethodsMap, $expectedResult)
6683
{
67-
$this->_paymentDataMock->expects(
68-
$this->any()
69-
)->method(
70-
'getStoreMethods'
71-
)->with(
72-
$store,
73-
$quote
74-
)->will(
75-
$this->returnValue($paymentMethods)
76-
);
84+
$this->paymentMethodList->expects(static::once())
85+
->method('getActiveList')
86+
->with($store)
87+
->willReturn(array_column($paymentMethodsMap, 0));
88+
89+
$this->paymentMethodInstanceFactory->expects(static::any())
90+
->method('create')
91+
->willReturnMap($paymentMethodsMap);
92+
7793
$this->assertEquals($expectedResult, $this->_helper->getBillingAgreementMethods($store, $quote));
7894
}
7995

@@ -84,16 +100,40 @@ public function getBillingAgreementMethodsDataProvider()
84100
{
85101
$quoteMock = $this->getMockBuilder(
86102
\Magento\Quote\Model\Quote::class
87-
)->disableOriginalConstructor()->setMethods(
88-
null
89-
);
90-
$methodInterfaceMock = $this->getMockBuilder(
91-
\Magento\Paypal\Model\Billing\Agreement\MethodInterface::class
103+
)->disableOriginalConstructor()->getMock();
104+
105+
$methodMock = $this->getMockBuilder(
106+
\Magento\Payment\Api\Data\PaymentMethodInterface::class
92107
)->getMock();
93108

109+
$agreementMethodInstanceMock = $this->getMockBuilder(
110+
\Magento\Paypal\Model\Method\Agreement::class
111+
)->disableOriginalConstructor()->getMock();
112+
$agreementMethodInstanceMock->expects($this->any())
113+
->method('isAvailable')
114+
->willReturn(true);
115+
116+
$methodInstanceMock = $this->getMockBuilder(
117+
\Magento\Payment\Model\Method\Cc::class
118+
)->disableOriginalConstructor()->getMock();
119+
94120
return [
95-
['1', $quoteMock, [$methodInterfaceMock], [$methodInterfaceMock]],
96-
['1', $quoteMock, [new \StdClass()], []]
121+
[
122+
'1',
123+
$quoteMock,
124+
[
125+
[$methodMock, $agreementMethodInstanceMock]
126+
],
127+
[$agreementMethodInstanceMock]
128+
],
129+
[
130+
'1',
131+
$quoteMock,
132+
[
133+
[$methodMock, $methodInstanceMock]
134+
],
135+
[]
136+
]
97137
];
98138
}
99139

app/code/Magento/Vault/Model/Ui/TokensConfigProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ private function getComponentProvider($vaultProviderCode)
141141
/**
142142
* Get list of active Vault payment methods.
143143
*
144-
* @return \Magento\Payment\Model\MethodInterface[]
144+
* @return VaultPaymentInterface[]
145145
*/
146146
private function getVaultPaymentMethodList()
147147
{

app/code/Magento/Vault/Model/Ui/VaultConfigProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public function getConfig()
8080
/**
8181
* Get list of active Vault payment methods.
8282
*
83-
* @return \Magento\Payment\Model\MethodInterface[]
83+
* @return VaultPaymentInterface[]
8484
*/
8585
private function getVaultPaymentMethodList()
8686
{

app/code/Magento/Vault/Test/Unit/Model/Ui/TokensConfigProviderTest.php

Lines changed: 41 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
use Magento\Customer\Model\Session;
99
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
10-
use Magento\Payment\Helper\Data;
1110
use Magento\Store\Api\Data\StoreInterface;
1211
use Magento\Store\Model\StoreManagerInterface;
1312
use Magento\Vault\Api\Data\PaymentTokenInterface;
@@ -33,10 +32,25 @@ class TokensConfigProviderTest extends \PHPUnit_Framework_TestCase
3332
private $storeManager;
3433

3534
/**
36-
* @var VaultPaymentInterface|MockObject
35+
* @var \Magento\Payment\Api\PaymentMethodListInterface|MockObject
36+
*/
37+
private $paymentMethodList;
38+
39+
/**
40+
* @var \Magento\Payment\Model\Method\InstanceFactory|MockObject
41+
*/
42+
private $paymentMethodInstanceFactory;
43+
44+
/**
45+
* @var \Magento\Payment\Api\Data\PaymentMethodInterface|MockObject
3746
*/
3847
private $vaultPayment;
3948

49+
/**
50+
* @var VaultPaymentInterface|MockObject
51+
*/
52+
private $vaultPaymentInstance;
53+
4054
/**
4155
* @var StoreInterface|MockObject
4256
*/
@@ -47,25 +61,25 @@ class TokensConfigProviderTest extends \PHPUnit_Framework_TestCase
4761
*/
4862
private $customerTokenManagement;
4963

50-
/**
51-
* @var Data|MockObject
52-
*/
53-
private $paymentDataHelper;
54-
5564
/**
5665
* @var ObjectManager
5766
*/
5867
private $objectManager;
5968

6069
protected function setUp()
6170
{
62-
$this->vaultPayment = $this->getMock(VaultPaymentInterface::class);
71+
$this->paymentMethodList = $this->getMockBuilder(\Magento\Payment\Api\PaymentMethodListInterface::class)
72+
->disableOriginalConstructor()
73+
->getMockForAbstractClass();
74+
75+
$this->paymentMethodInstanceFactory = $this->getMockBuilder(
76+
\Magento\Payment\Model\Method\InstanceFactory::class
77+
)->disableOriginalConstructor()->getMock();
78+
79+
$this->vaultPayment = $this->getMockForAbstractClass(\Magento\Payment\Api\Data\PaymentMethodInterface::class);
80+
$this->vaultPaymentInstance = $this->getMockForAbstractClass(VaultPaymentInterface::class);
6381
$this->storeManager = $this->getMock(StoreManagerInterface::class);
6482
$this->store = $this->getMock(StoreInterface::class);
65-
$this->paymentDataHelper = $this->getMockBuilder(Data::class)
66-
->disableOriginalConstructor()
67-
->setMethods(['getStoreMethods'])
68-
->getMock();
6983

7084
$this->objectManager = new ObjectManager($this);
7185
$this->customerTokenManagement = $this->getMockBuilder(CustomerTokenManagement::class)
@@ -99,17 +113,17 @@ public function testGetConfig()
99113
$this->store->expects(static::once())
100114
->method('getId')
101115
->willReturn($storeId);
102-
103-
$this->paymentDataHelper->expects(static::once())
104-
->method('getStoreMethods')
116+
117+
$this->paymentMethodList->expects(static::once())
118+
->method('getActiveList')
105119
->with($storeId)
106120
->willReturn([$this->vaultPayment]);
121+
122+
$this->paymentMethodInstanceFactory->expects($this->once())
123+
->method('create')
124+
->willReturn($this->vaultPaymentInstance);
107125

108-
$this->vaultPayment->expects(static::once())
109-
->method('isActive')
110-
->with($storeId)
111-
->willReturn(true);
112-
$this->vaultPayment->expects(static::once())
126+
$this->vaultPaymentInstance->expects(static::once())
113127
->method('getProviderCode')
114128
->willReturn($vaultProviderCode);
115129

@@ -142,8 +156,13 @@ public function testGetConfig()
142156

143157
$this->objectManager->setBackwardCompatibleProperty(
144158
$configProvider,
145-
'paymentDataHelper',
146-
$this->paymentDataHelper
159+
'paymentMethodList',
160+
$this->paymentMethodList
161+
);
162+
$this->objectManager->setBackwardCompatibleProperty(
163+
$configProvider,
164+
'paymentMethodInstanceFactory',
165+
$this->paymentMethodInstanceFactory
147166
);
148167

149168
static::assertEquals($expectedConfig, $configProvider->getConfig());

0 commit comments

Comments
 (0)