From 481d3c5832e174ef1f89862a5e8a331926cc665c Mon Sep 17 00:00:00 2001 From: Can Demiralp Date: Wed, 26 Feb 2025 14:28:09 +0100 Subject: [PATCH] [ECP-8888] Fix unit failing tests --- Test/Unit/Helper/OpenInvoiceTest.php | 53 ++++++++++++++++------------ 1 file changed, 31 insertions(+), 22 deletions(-) diff --git a/Test/Unit/Helper/OpenInvoiceTest.php b/Test/Unit/Helper/OpenInvoiceTest.php index 49741c0e0..8824b2f67 100644 --- a/Test/Unit/Helper/OpenInvoiceTest.php +++ b/Test/Unit/Helper/OpenInvoiceTest.php @@ -5,6 +5,7 @@ use Adyen\Payment\Helper\ChargedCurrency; use Adyen\Payment\Helper\Config; use Adyen\Payment\Helper\Data; +use Adyen\Payment\Logger\AdyenLogger; use Adyen\Payment\Model\AdyenAmountCurrency; use Adyen\Payment\Test\Unit\AbstractAdyenTestCase; use Adyen\Payment\Helper\OpenInvoice; @@ -17,6 +18,7 @@ use Magento\Sales\Model\Order; use Magento\Sales\Model\Order\Creditmemo; use Magento\Sales\Model\Order\Invoice; +use Magento\Sales\Model\Order\Payment; class OpenInvoiceTest extends AbstractAdyenTestCase { @@ -26,8 +28,11 @@ class OpenInvoiceTest extends AbstractAdyenTestCase private $configHelperMock; private $imageHelperMock; private $orderMock; + private $orderPaymentMock; + private $quoteMock; + private $quotePaymentMock; private $cartMock; - private $itemMock; + private $quoteItemMock; private $productMock; private $invoiceMock; private $orderItemMock; @@ -36,6 +41,7 @@ class OpenInvoiceTest extends AbstractAdyenTestCase private $creditmemoItemMock; private $shippingAddressMock; private $shippingAmountCurrencyMock; + private $adyenLoggerMock; protected function setUp(): void { @@ -47,14 +53,19 @@ protected function setUp(): void $this->imageHelperMock = $this->createMock(Image::class); # Other mock property definitions + $this->orderPaymentMock = $this->createMock(Payment::class); $this->orderMock = $this->createMock(Order::class); - $this->itemMock = $this->createGeneratedMock(Item::class, - ['getIsVirtual', 'getQty', 'getProduct', 'getName', 'getSku', 'getTaxPercent'] + $this->orderMock->method('getPayment')->willReturn($this->orderPaymentMock); + $this->quotePaymentMock = $this->createMock(Quote\Payment::class); + $this->quoteMock = $this->createMock(Quote::class); + $this->quoteMock->method('getPayment')->willReturn($this->quotePaymentMock); + $this->quoteItemMock = $this->createGeneratedMock(Item::class, + ['getIsVirtual', 'getQty', 'getProduct', 'getName', 'getSku', 'getTaxPercent', 'getQuote'] ); $this->productMock = $this->createMock(Product::class); $this->invoiceMock = $this->createMock(Invoice::class); $this->orderItemMock = $this->createGeneratedMock(Order\Item::class, - ['getIsVirtual', 'getQty', 'getProduct', 'getName', 'getSku', 'getTaxPercent'] + ['getIsVirtual', 'getQty', 'getProduct', 'getName', 'getSku', 'getTaxPercent', 'getOrder'] ); $this->invoiceItemMock = $this->createMock(Invoice\Item::class); $this->creditmemoMock = $this->createMock(Creditmemo::class); @@ -62,6 +73,7 @@ protected function setUp(): void $this->cartMock = $this->createMock(Quote::class); $this->shippingAddressMock = $this->createMock(Address::class); $this->shippingAmountCurrencyMock = $this->createMock(AdyenAmountCurrency::class); + $this->adyenLoggerMock = $this->createMock(AdyenLogger::class); } /** @@ -77,7 +89,8 @@ public function testGetOpenInvoiceDataFomOrder(bool $isVirtual): void $this->cartRepositoryMock, $this->chargedCurrencyMock, $this->configHelperMock, - $this->imageHelperMock + $this->imageHelperMock, + $this->adyenLoggerMock ); $itemAmountCurrencyMock = $this->createMock(AdyenAmountCurrency::class); @@ -87,14 +100,15 @@ public function testGetOpenInvoiceDataFomOrder(bool $isVirtual): void $this->chargedCurrencyMock->method('getQuoteItemAmountCurrency')->willReturn($itemAmountCurrencyMock); - $this->itemMock->method('getQty')->willReturn(1); - $this->itemMock->method('getProduct')->willReturn($this->productMock); - $this->itemMock->method('getName')->willReturn('Push It Messenger Bag'); - $this->itemMock->method('getSku')->willReturn('24-WB04'); - $this->itemMock->method('getIsVirtual')->willReturn($isVirtual); + $this->quoteItemMock->method('getQty')->willReturn(1); + $this->quoteItemMock->method('getProduct')->willReturn($this->productMock); + $this->quoteItemMock->method('getName')->willReturn('Push It Messenger Bag'); + $this->quoteItemMock->method('getSku')->willReturn('24-WB04'); + $this->quoteItemMock->method('getIsVirtual')->willReturn($isVirtual); + $this->quoteItemMock->method('getQuote')->willReturn($this->quoteMock); $this->cartMock->method('getShippingAddress')->willReturn($this->shippingAddressMock); - $this->cartMock->method('getAllVisibleItems')->willReturn([$this->itemMock]); + $this->cartMock->method('getAllVisibleItems')->willReturn([$this->quoteItemMock]); $this->cartRepositoryMock->method('get')->willReturn($this->cartMock); @@ -135,9 +149,6 @@ public function getUrl() 'taxPercentage' => 0, 'description' => 'Push It Messenger Bag', 'sku' => '24-WB04', - 'itemCategory' => $isVirtual ? - OpenInvoice::ITEM_CATEGORY_DIGITAL_GOODS : - OpenInvoice::ITEM_CATEGORY_PHYSICAL_GOODS, 'quantity' => 1, 'productUrl' => 'https://localhost.store/index.php/push-it-messenger-bag.html', 'imageUrl' => '', @@ -182,6 +193,7 @@ public function getUrl() $this->orderItemMock->method('getTaxPercent')->willReturn(21); $this->orderItemMock->method('getSku')->willReturn('24-WB04'); $this->orderItemMock->method('getIsVirtual')->willReturn($isVirtual); + $this->orderItemMock->method('getOrder')->willReturn($this->orderMock); $this->invoiceItemMock->method('getOrderItem')->willReturn($this->orderItemMock); $this->invoiceItemMock->method('getQty')->willReturn(1); @@ -203,7 +215,8 @@ public function getUrl() $this->cartRepositoryMock, $this->chargedCurrencyMock, $this->configHelperMock, - $this->imageHelperMock + $this->imageHelperMock, + $this->adyenLoggerMock ); $expectedResult = [ @@ -216,9 +229,6 @@ public function getUrl() 'taxPercentage' => 2100, 'description' => 'Push It Messenger Bag', 'sku' => '24-WB04', - 'itemCategory' => $isVirtual ? - OpenInvoice::ITEM_CATEGORY_DIGITAL_GOODS : - OpenInvoice::ITEM_CATEGORY_PHYSICAL_GOODS, 'quantity' => 1, 'productUrl' => 'https://localhost.store/index.php/push-it-messenger-bag.html', 'imageUrl' => '', @@ -258,6 +268,7 @@ public function testGetOpenInvoiceDataForCreditMemo(bool $isVirtual): void $this->orderItemMock->method('getTaxPercent')->willReturn(0); $this->orderItemMock->method('getSku')->willReturn('24-WB04'); $this->orderItemMock->method('getIsVirtual')->willReturn($isVirtual); + $this->orderItemMock->method('getOrder')->willReturn($this->orderMock); $itemAmountCurrencyMock = $this->createMock(AdyenAmountCurrency::class); $itemAmountCurrencyMock->method('getAmountIncludingTax')->willReturn(45); @@ -286,7 +297,8 @@ public function getUrl() $this->cartRepositoryMock, $this->chargedCurrencyMock, $this->configHelperMock, - $this->imageHelperMock + $this->imageHelperMock, + $this->adyenLoggerMock ); $expectedResult = [ @@ -299,9 +311,6 @@ public function getUrl() 'taxPercentage' => 0, 'description' => 'Push It Messenger Bag', 'sku' => '24-WB04', - 'itemCategory' => $isVirtual ? - OpenInvoice::ITEM_CATEGORY_DIGITAL_GOODS : - OpenInvoice::ITEM_CATEGORY_PHYSICAL_GOODS, 'quantity' => 1, 'productUrl' => 'https://localhost.store/index.php/push-it-messenger-bag.html', 'imageUrl' => ''