Skip to content

Commit

Permalink
[EPC-9489] Write unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Can Demiralp committed Jan 31, 2025
1 parent 2ff0636 commit 3cbb7ca
Showing 1 changed file with 72 additions and 0 deletions.
72 changes: 72 additions & 0 deletions Test/Unit/Model/Api/GuestAdyenGiftcardTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php
/**
*
* Adyen Payment module (https://www.adyen.com/)
*
* Copyright (c) 2025 Adyen N.V. (https://www.adyen.com/)
* See LICENSE.txt for license details.
*
* Author: Adyen <magento@adyen.com>
*/

namespace Adyen\Payment\Test\Unit\Model\Api;

use Adyen\Payment\Helper\GiftcardPayment;
use Adyen\Payment\Model\Api\GuestAdyenGiftcard;
use Adyen\Payment\Test\Unit\AbstractAdyenTestCase;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Quote\Model\MaskedQuoteIdToQuoteIdInterface;
use PHPUnit\Framework\MockObject\MockObject;

class GuestAdyenGiftcardTest extends AbstractAdyenTestCase
{
protected ?GuestAdyenGiftcard $guestAdyenGiftcard;
protected MockObject|GiftcardPayment $giftcardPaymentHelperMock;
protected MockObject|MaskedQuoteIdToQuoteIdInterface $maskedQuoteIdToQuoteId;

/**
* @return void
*/
protected function setUp(): void
{
$this->giftcardPaymentHelperMock = $this->createMock(GiftcardPayment::class);
$this->maskedQuoteIdToQuoteId = $this->createMock(MaskedQuoteIdToQuoteIdInterface::class);

$this->guestAdyenGiftcard = new GuestAdyenGiftcard(
$this->giftcardPaymentHelperMock,
$this->maskedQuoteIdToQuoteId
);
}

/**
* @return void
*/
protected function tearDown(): void
{
$this->guestAdyenGiftcard = null;
}

/**
* @return void
* @throws NoSuchEntityException
*/
public function testGetRedeemedGiftcards()
{
$cartId = 'abc_123456789_xyz';
$quoteId = 1;
$mockResponse = '{}';

$this->maskedQuoteIdToQuoteId->expects($this->once())
->method('execute')
->with($cartId)
->willReturn($quoteId);

$this->giftcardPaymentHelperMock->expects($this->once())
->method('fetchRedeemedGiftcards')
->with($quoteId)
->willReturn($mockResponse);

$result = $this->guestAdyenGiftcard->getRedeemedGiftcards($cartId);
$this->assertIsString($result);
}
}

0 comments on commit 3cbb7ca

Please sign in to comment.