Skip to content

Commit

Permalink
[ECP-8888] Fix unit failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Can Demiralp committed Feb 26, 2025
1 parent 56268e8 commit 481d3c5
Showing 1 changed file with 31 additions and 22 deletions.
53 changes: 31 additions & 22 deletions Test/Unit/Helper/OpenInvoiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
{
Expand All @@ -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;
Expand All @@ -36,6 +41,7 @@ class OpenInvoiceTest extends AbstractAdyenTestCase
private $creditmemoItemMock;
private $shippingAddressMock;
private $shippingAmountCurrencyMock;
private $adyenLoggerMock;

protected function setUp(): void
{
Expand All @@ -47,21 +53,27 @@ 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);
$this->creditmemoItemMock = $this->createMock(Creditmemo\Item::class);
$this->cartMock = $this->createMock(Quote::class);
$this->shippingAddressMock = $this->createMock(Address::class);
$this->shippingAmountCurrencyMock = $this->createMock(AdyenAmountCurrency::class);
$this->adyenLoggerMock = $this->createMock(AdyenLogger::class);
}

/**
Expand All @@ -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);
Expand All @@ -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);

Expand Down Expand Up @@ -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' => '',
Expand Down Expand Up @@ -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);
Expand All @@ -203,7 +215,8 @@ public function getUrl()
$this->cartRepositoryMock,
$this->chargedCurrencyMock,
$this->configHelperMock,
$this->imageHelperMock
$this->imageHelperMock,
$this->adyenLoggerMock
);

$expectedResult = [
Expand All @@ -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' => '',
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -286,7 +297,8 @@ public function getUrl()
$this->cartRepositoryMock,
$this->chargedCurrencyMock,
$this->configHelperMock,
$this->imageHelperMock
$this->imageHelperMock,
$this->adyenLoggerMock
);

$expectedResult = [
Expand All @@ -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' => ''
Expand Down

0 comments on commit 481d3c5

Please sign in to comment.