11<?php
22/**
3- * Copyright © Magento, Inc. All rights reserved.
4- * See COPYING.txt for license details .
3+ * Copyright 2015 Adobe
4+ * All Rights Reserved .
55 */
66declare (strict_types=1 );
77
@@ -117,10 +117,12 @@ protected function setUp(): void
117117 *
118118 * @dataProvider captureCorrectIdDataProvider
119119 * @param string $parentTransactionId
120+ * @param bool $createPaymentToken
120121 * @throws InvalidTransitionException
121122 * @throws LocalizedException
123+ * @SuppressWarnings(PHPMD.CyclomaticComplexity)
122124 */
123- public function testCaptureCorrectId (string $ parentTransactionId )
125+ public function testCaptureCorrectId (string $ parentTransactionId, bool $ createPaymentToken )
124126 {
125127 if (empty ($ parentTransactionId )) {
126128 $ setParentTransactionIdCalls = 1 ;
@@ -132,36 +134,54 @@ public function testCaptureCorrectId(string $parentTransactionId)
132134 $ getGatewayTokenCalls = 0 ;
133135 }
134136
135- $ gatewayToken = 'gateway_token ' ;
136- $ this ->payment ->expects ($ this ->once ())->method ('getParentTransactionId ' )->willReturn ($ parentTransactionId );
137- $ this ->payment ->expects ($ this ->exactly ($ setParentTransactionIdCalls ))->method ('setParentTransactionId ' );
138- $ this ->payment ->expects ($ this ->exactly ($ setAdditionalInformationCalls ))
139- ->method ('setAdditionalInformation ' )
140- ->with (Payflowpro::PNREF , $ gatewayToken );
141- $ this ->payment ->expects ($ this ->exactly (4 ))
137+ $ this ->payment ->expects ($ this ->any ())
142138 ->method ('getAdditionalInformation ' )
143- ->willReturnCallback (function ($ args ) {
139+ ->willReturnCallback (function ($ args ) use ( $ createPaymentToken ) {
144140 static $ callCount = 0 ;
145141 if ($ callCount == 0 && $ args == 'result_code ' ) {
146142 $ callCount ++;
147143 return 0 ;
148- } elseif ($ callCount == 1 && $ args == Payflowpro::PNREF ) {
144+ } elseif ($ callCount == 1 && $ args == Payflowpro::PNREF && ! $ createPaymentToken ) {
149145 $ callCount ++;
150146 return '' ;
147+ } elseif ($ callCount == 1 && $ args == Payflowpro::PNREF && $ createPaymentToken ) {
148+ $ callCount ++;
149+ return 'ABCD ' ;
151150 } elseif ($ callCount == 2 && $ args == Payflowpro::PNREF ) {
152151 $ callCount ++;
153152 return Payflowpro::PNREF ;
154153 } elseif ($ callCount == 3 && $ args == Payflowpro::PNREF ) {
155154 $ callCount ++;
156155 return Payflowpro::PNREF ;
156+ } elseif ($ args == PayPalPayflowTransparent::CC_DETAILS && $ createPaymentToken ) {
157+ return json_encode ([]);
157158 }
158159 });
159- $ this ->paymentExtensionAttributes ->expects ($ this ->once ())
160- ->method ('getVaultPaymentToken ' )
161- ->willReturn ($ this ->paymentToken );
162- $ this ->paymentToken ->expects ($ this ->exactly ($ getGatewayTokenCalls ))
163- ->method ('getGatewayToken ' )
164- ->willReturn ($ gatewayToken );
160+
161+ $ gatewayToken = 'gateway_token ' ;
162+ if ($ createPaymentToken ) {
163+ $ this ->payment ->expects ($ this ->never ())->method ('setParentTransactionId ' );
164+ $ this ->payment ->expects ($ this ->never ())
165+ ->method ('setAdditionalInformation ' );
166+ $ this ->paymentExtensionAttributes ->expects ($ this ->once ())
167+ ->method ('getVaultPaymentToken ' )
168+ ->willReturn (null );
169+ $ this ->paymentToken ->expects ($ this ->never ())
170+ ->method ('getGatewayToken ' )
171+ ->willReturn ($ gatewayToken );
172+ } else {
173+ $ this ->payment ->expects ($ this ->once ())->method ('getParentTransactionId ' )->willReturn ($ parentTransactionId );
174+ $ this ->payment ->expects ($ this ->exactly ($ setParentTransactionIdCalls ))->method ('setParentTransactionId ' );
175+ $ this ->payment ->expects ($ this ->exactly ($ setAdditionalInformationCalls ))
176+ ->method ('setAdditionalInformation ' )
177+ ->with (Payflowpro::PNREF , $ gatewayToken );
178+ $ this ->paymentExtensionAttributes ->expects ($ this ->once ())
179+ ->method ('getVaultPaymentToken ' )
180+ ->willReturn ($ this ->paymentToken );
181+ $ this ->paymentToken ->expects ($ this ->exactly ($ getGatewayTokenCalls ))
182+ ->method ('getGatewayToken ' )
183+ ->willReturn ($ gatewayToken );
184+ }
165185
166186 $ this ->subject ->capture ($ this ->payment , 100 );
167187 }
@@ -174,8 +194,10 @@ public function testCaptureCorrectId(string $parentTransactionId)
174194 public static function captureCorrectIdDataProvider (): array
175195 {
176196 return [
177- 'No Transaction ID ' => ['' ],
178- 'With Transaction ID ' => ['1 ' ],
197+ ['' , false ],
198+ ['1 ' , false ],
199+ ['' , true ],
200+ ['1 ' , true ],
179201 ];
180202 }
181203
@@ -387,7 +409,8 @@ private function initPayment()
387409 'getParentTransactionId ' ,
388410 'setParentTransactionId ' ,
389411 'setAdditionalInformation ' ,
390- 'getAdditionalInformation '
412+ 'getAdditionalInformation ' ,
413+ 'setExtensionAttributes '
391414 ]
392415 )
393416 ->getMock ();
0 commit comments