88
99use Magento \Braintree \Model \PaymentMethod ;
1010use Magento \Framework \TestFramework \Unit \Helper \ObjectManager as ObjectManagerHelper ;
11+ use Magento \Payment \Model \InfoInterface ;
12+ use Magento \Quote \Model \Quote \Payment ;
1113use Magento \Sales \Model \Order \Payment \Transaction ;
1214use \Magento \Sales \Model \ResourceModel \Order \Payment \Transaction \CollectionFactory as TransactionCollectionFactory ;
1315use Magento \Framework \Exception \LocalizedException ;
@@ -62,7 +64,7 @@ class PaymentMethodTest extends \PHPUnit_Framework_TestCase
6264 protected $ registryMock ;
6365
6466 /**
65- * @var \Magento\ Payment\Model\InfoInterface |\PHPUnit_Framework_MockObject_MockObject
67+ * @var Payment|\PHPUnit_Framework_MockObject_MockObject
6668 */
6769 protected $ infoInstanceMock ;
6870
@@ -200,29 +202,25 @@ protected function setUp()
200202 'orderRepository ' => $ this ->orderRepository
201203 ]
202204 );
203- $ this ->infoInstanceMock = $ this ->getMockForAbstractClass (
204- '\Magento\Payment\Model\InfoInterface ' ,
205- [],
206- '' ,
207- false ,
208- false ,
209- false ,
210- [
211- 'setCcType ' ,
212- 'setCcOwner ' ,
213- 'setCcLast4 ' ,
214- 'setCcNumber ' ,
215- 'setCcCid ' ,
216- 'setCcExpMonth ' ,
217- 'setCcExpYear ' ,
218- 'setCcSsIssue ' ,
219- 'setCcSsStartMonth ' ,
220- 'setCcSsStartYear ' ,
221- 'getOrder ' ,
222- 'getQuote ' ,
223- 'getCcType ' ,
224- ]
225- );
205+ $ this ->infoInstanceMock = $ this ->getMockBuilder (InfoInterface::class)
206+ ->disableOriginalConstructor ()
207+ ->setMethods (
208+ [
209+ 'setCcType ' ,
210+ 'setCcOwner ' ,
211+ 'setCcLast4 ' ,
212+ 'setCcNumber ' ,
213+ 'setCcCid ' ,
214+ 'setCcExpMonth ' ,
215+ 'setCcExpYear ' ,
216+ 'setCcSsIssue ' ,
217+ 'setCcSsStartMonth ' ,
218+ 'setCcSsStartYear ' ,
219+ 'getOrder ' ,
220+ 'getQuote ' ,
221+ 'getCcType '
222+ ]
223+ )->getMockForAbstractClass ();
226224 $ this ->productMetaDataMock ->expects ($ this ->any ())
227225 ->method ('getEdition ' )
228226 ->willReturn ('Community Edition ' );
@@ -234,7 +232,6 @@ protected function setUp()
234232 public function testAssignData ()
235233 {
236234 $ ccType = 'VI ' ;
237- $ ccOwner = 'John Doe ' ;
238235 $ ccExpMonth = '10 ' ;
239236 $ ccExpYear = '2020 ' ;
240237
@@ -244,15 +241,16 @@ public function testAssignData()
244241 $ storeInVault = true ;
245242 $ deviceData = 'mobile ' ;
246243 $ data = [
247- 'cc_type ' => $ ccType ,
248- 'cc_owner ' => $ ccOwner ,
249- 'cc_exp_month ' => $ ccExpMonth ,
250- 'cc_exp_year ' => $ ccExpYear ,
251- 'cc_last4 ' => $ ccLast4 ,
252- 'cc_token ' => $ ccToken ,
253- 'payment_method_nonce ' => $ paymentMethodNonce ,
254- 'store_in_vault ' => $ storeInVault ,
255- 'device_data ' => $ deviceData ,
244+ 'additional_data ' => [
245+ 'cc_type ' => $ ccType ,
246+ 'cc_exp_month ' => $ ccExpMonth ,
247+ 'cc_exp_year ' => $ ccExpYear ,
248+ 'cc_last4 ' => $ ccLast4 ,
249+ 'cc_token ' => $ ccToken ,
250+ 'payment_method_nonce ' => $ paymentMethodNonce ,
251+ 'store_in_vault ' => $ storeInVault ,
252+ 'device_data ' => $ deviceData
253+ ]
256254 ];
257255 $ data = new \Magento \Framework \DataObject ($ data );
258256 $ this ->model ->setInfoInstance ($ this ->infoInstanceMock );
@@ -265,21 +263,9 @@ public function testAssignData()
265263 ->method ('setCcType ' )
266264 ->with ($ ccType )
267265 ->willReturnSelf ();
268- $ this ->infoInstanceMock ->expects ($ this ->once ())
269- ->method ('setCcOwner ' )
270- ->with ($ ccOwner )
271- ->willReturnSelf ();
272266 $ this ->infoInstanceMock ->expects ($ this ->once ())
273267 ->method ('setCcLast4 ' )
274- ->with (false )
275- ->willReturnSelf ();
276- $ this ->infoInstanceMock ->expects ($ this ->once ())
277- ->method ('setCcNumber ' )
278- ->with (null )
279- ->willReturnSelf ();
280- $ this ->infoInstanceMock ->expects ($ this ->once ())
281- ->method ('setCcCid ' )
282- ->with (null )
268+ ->with ($ ccLast4 )
283269 ->willReturnSelf ();
284270 $ this ->infoInstanceMock ->expects ($ this ->once ())
285271 ->method ('setCcExpMonth ' )
@@ -289,34 +275,19 @@ public function testAssignData()
289275 ->method ('setCcExpYear ' )
290276 ->with ($ ccExpYear )
291277 ->willReturnSelf ();
292- $ this ->infoInstanceMock ->expects ($ this ->once ())
293- ->method ('setCcSsIssue ' )
294- ->with (null )
295- ->willReturnSelf ();
296- $ this ->infoInstanceMock ->expects ($ this ->once ())
297- ->method ('setCcSsStartMonth ' )
298- ->with (null )
299- ->willReturnSelf ();
300- $ this ->infoInstanceMock ->expects ($ this ->once ())
301- ->method ('setCcSsStartYear ' )
302- ->with (null )
303- ->willReturnSelf ();
304278
305- $ this ->infoInstanceMock ->expects ($ this ->at ( 10 ))
279+ $ this ->infoInstanceMock ->expects ($ this ->atLeastOnce ( ))
306280 ->method ('setAdditionalInformation ' )
307- ->with ('device_data ' , $ deviceData );
308- $ this ->infoInstanceMock ->expects ($ this ->at (11 ))
309- ->method ('setAdditionalInformation ' )
310- ->with ('cc_last4 ' , $ ccLast4 );
311- $ this ->infoInstanceMock ->expects ($ this ->at (12 ))
312- ->method ('setAdditionalInformation ' )
313- ->with ('cc_token ' , $ ccToken );
314- $ this ->infoInstanceMock ->expects ($ this ->at (13 ))
315- ->method ('setAdditionalInformation ' )
316- ->with ('payment_method_nonce ' , $ paymentMethodNonce );
317- $ this ->infoInstanceMock ->expects ($ this ->at (14 ))
318- ->method ('setAdditionalInformation ' )
319- ->with ('store_in_vault ' , $ storeInVault );
281+ ->willReturnMap (
282+ [
283+ ['device_data ' , $ deviceData ],
284+ ['cc_last4 ' , $ ccLast4 ],
285+ ['cc_token ' , $ ccToken ],
286+ ['payment_method_nonce ' , $ paymentMethodNonce ],
287+ ['store_in_vault ' , $ storeInVault ]
288+ ]
289+ );
290+
320291 $ this ->model ->assignData ($ data );
321292 }
322293
0 commit comments