33namespace Adyen \Payment \Test \Gateway \Request ;
44
55use Adyen \Payment \Gateway \Request \MerchantRiskIndicatorDataBuilder ;
6- use Adyen \Payment \Helper \ChargedCurrency ;
7- use Adyen \Payment \Helper \GiftcardPayment ;
86use Adyen \Payment \Logger \AdyenLogger ;
9- use Adyen \Payment \Model \AdyenAmountCurrency ;
107use Adyen \Payment \Test \Unit \AbstractAdyenTestCase ;
118use Magento \Framework \Exception \NoSuchEntityException ;
129use Magento \Payment \Gateway \Data \PaymentDataObject ;
@@ -21,8 +18,6 @@ class MerchantRiskIndicatorDataBuilderTest extends AbstractAdyenTestCase
2118{
2219 protected ?MerchantRiskIndicatorDataBuilder $ merchantRiskIndicatorDataBuilder ;
2320 protected CartRepositoryInterface |MockObject $ cartRepositoryMock ;
24- protected ChargedCurrency |MockObject $ chargedCurrencyMock ;
25- protected GiftcardPayment |MockObject $ giftcardPaymentHelperMock ;
2621 protected PaymentDataObject |MockObject $ paymentDataObjectMock ;
2722 protected Payment |MockObject $ paymentMock ;
2823 protected Order |MockObject $ orderMock ;
@@ -36,14 +31,12 @@ protected function setUp(): void
3631 {
3732 // Constructor arguments
3833 $ this ->cartRepositoryMock = $ this ->createMock (CartRepositoryInterface::class);
39- $ this ->chargedCurrencyMock = $ this ->createMock (ChargedCurrency::class);
40- $ this ->giftcardPaymentHelperMock = $ this ->createMock (GiftcardPayment::class);
34+ $ this ->adyenLoggerMock = $ this ->createMock (AdyenLogger::class);
4135
4236 // Other mock objects
4337 $ this ->shippingAddressMock = $ this ->createMock (Address::class);
4438
4539 $ this ->quoteMock = $ this ->createMock (Quote::class);
46- $ this ->quoteMock ->expects ($ this ->atLeastOnce ())->method ('getId ' )->willReturn ($ this ->quoteId );
4740 $ this ->quoteMock ->method ('getShippingAddress ' )->willReturn ($ this ->shippingAddressMock );
4841 $ this ->cartRepositoryMock ->method ('get ' )->with ($ this ->quoteId )->willReturn ($ this ->quoteMock );
4942
@@ -56,15 +49,11 @@ protected function setUp(): void
5649 $ this ->paymentDataObjectMock = $ this ->createMock (PaymentDataObject::class);
5750 $ this ->paymentDataObjectMock ->method ('getPayment ' )->willReturn ($ this ->paymentMock );
5851
59- $ this ->adyenLoggerMock = $ this ->createMock (AdyenLogger::class);
60-
6152 $ this ->buildSubject = ['payment ' => $ this ->paymentDataObjectMock ];
6253
6354 // SUT generation
6455 $ this ->merchantRiskIndicatorDataBuilder = new MerchantRiskIndicatorDataBuilder (
6556 $ this ->cartRepositoryMock ,
66- $ this ->chargedCurrencyMock ,
67- $ this ->giftcardPaymentHelperMock ,
6857 $ this ->adyenLoggerMock
6958 );
7059 }
@@ -133,70 +122,4 @@ public function testBuildWithoutGiftcards($isVirtual, $sameAsBillingAddress, $de
133122 $ this ->assertEquals ($ deliveryAddressIndicator ,
134123 $ result ['body ' ]['merchantRiskIndicator ' ]['deliveryAddressIndicator ' ]);
135124 }
136-
137- /**
138- * @return void
139- * @throws NoSuchEntityException
140- */
141- public function testBuildPhysicalGoodsWithGiftcard ()
142- {
143- $ totalGiftcardDiscount = 1000 ;
144- $ currency = 'EUR ' ;
145- $ numberOfGiftcards = 2 ;
146-
147- $ this ->orderMock ->expects ($ this ->once ())->method ('getIsVirtual ' )->willReturn (false );
148-
149- $ quoteAmountCurrency = $ this ->createMock (AdyenAmountCurrency::class);
150- $ quoteAmountCurrency ->method ('getCurrencyCode ' )->willReturn ($ currency );
151- $ this ->chargedCurrencyMock ->expects ($ this ->once ())->method ('getQuoteAmountCurrency ' )
152- ->with ($ this ->quoteMock )
153- ->willReturn ($ quoteAmountCurrency );
154-
155- $ redeemedGiftcardsMock = '{"redeemedGiftcards":[{"stateDataId":"51","brand":"svs","title":"SVS","balance":{"currency":"EUR","value":5000},"deductedAmount":"50,00\u00a0\u20ac"},{"stateDataId":"52","brand":"svs","title":"SVS","balance":{"currency":"EUR","value":5000},"deductedAmount":"50,00\u00a0\u20ac"}],"remainingAmount":"8,00\u00a0\u20ac","totalDiscount":"100,00\u00a0\u20ac"} ' ;
156-
157- $ this ->giftcardPaymentHelperMock ->expects ($ this ->once ())
158- ->method ('getQuoteGiftcardDiscount ' )
159- ->with ($ this ->quoteMock )
160- ->willReturn ($ totalGiftcardDiscount );
161- $ this ->giftcardPaymentHelperMock ->expects ($ this ->once ())
162- ->method ('fetchRedeemedGiftcards ' )
163- ->with ($ this ->quoteId )
164- ->willReturn ($ redeemedGiftcardsMock );
165-
166- $ result = $ this ->merchantRiskIndicatorDataBuilder ->build ($ this ->buildSubject );
167-
168- $ this ->assertArrayHasKey ('body ' , $ result );
169- $ this ->assertArrayHasKey ('merchantRiskIndicator ' , $ result ['body ' ]);
170- $ this ->assertArrayHasKey ('giftCardCurr ' , $ result ['body ' ]['merchantRiskIndicator ' ]);
171- $ this ->assertArrayHasKey ('giftCardCount ' , $ result ['body ' ]['merchantRiskIndicator ' ]);
172- $ this ->assertEquals ($ numberOfGiftcards , $ result ['body ' ]['merchantRiskIndicator ' ]['giftCardCount ' ]);
173- $ this ->assertArrayHasKey ('giftCardAmount ' , $ result ['body ' ]['merchantRiskIndicator ' ]);
174- $ this ->assertArrayHasKey ('currency ' , $ result ['body ' ]['merchantRiskIndicator ' ]['giftCardAmount ' ]);
175- $ this ->assertEquals ($ currency , $ result ['body ' ]['merchantRiskIndicator ' ]['giftCardAmount ' ]['currency ' ]);
176- $ this ->assertArrayHasKey ('value ' , $ result ['body ' ]['merchantRiskIndicator ' ]['giftCardAmount ' ]);
177- $ this ->assertEquals ($ totalGiftcardDiscount ,
178- $ result ['body ' ]['merchantRiskIndicator ' ]['giftCardAmount ' ]['value ' ]);
179- }
180-
181- /**
182- * @return void
183- * @throws NoSuchEntityException
184- */
185- public function testBuildPhysicalGoodsWithGiftcardInvalidData ()
186- {
187- $ quoteAmountCurrency = $ this ->createMock (AdyenAmountCurrency::class);
188- $ quoteAmountCurrency ->method ('getCurrencyCode ' )->willReturn ('EUR ' );
189- $ this ->chargedCurrencyMock ->expects ($ this ->once ())->method ('getQuoteAmountCurrency ' )
190- ->with ($ this ->quoteMock )
191- ->willReturn ($ quoteAmountCurrency );
192-
193- $ this ->giftcardPaymentHelperMock ->method ('fetchRedeemedGiftcards ' )
194- ->willThrowException (new \Exception ());
195-
196- $ this ->adyenLoggerMock ->expects ($ this ->once ())->method ('error ' );
197- $ this ->assertArrayNotHasKey (
198- 'body ' ,
199- $ this ->merchantRiskIndicatorDataBuilder ->build ($ this ->buildSubject )
200- );
201- }
202125}
0 commit comments