Skip to content

Commit

Permalink
[ECP-9489] Write unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Can Demiralp committed Jan 28, 2025
1 parent 75bf608 commit 9976d3e
Showing 1 changed file with 82 additions and 0 deletions.
82 changes: 82 additions & 0 deletions Test/Unit/Model/ResourceModel/Invoice/InvoiceTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?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 <[email protected]>
*/

namespace Adyen\Payment\Test\Helper\Unit\Model\ResourceModel\Invoice;

use Adyen\Payment\Api\Data\InvoiceInterface;
use Adyen\Payment\Model\ResourceModel\Invoice\Invoice;
use Adyen\Payment\Test\Unit\AbstractAdyenTestCase;
use Magento\Framework\App\ResourceConnection;
use Magento\Framework\DB\Adapter\AdapterInterface;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Model\ResourceModel\Db\Context;
use PHPUnit\Framework\MockObject\MockObject;
use Zend_Db_Select;

class InvoiceTest extends AbstractAdyenTestCase
{
private ?Invoice $invoiceResourceModel;
private Context|MockObject $contextMock;
private Zend_Db_Select|MockObject $zendSelectMock;
private AdapterInterface|MockObject $connectionMock;

/**
* @return void
*/
protected function setUp(): void
{
$this->zendSelectMock = $this->createMock(Zend_Db_Select::class);

$this->connectionMock = $this->createMock(AdapterInterface::class);
$this->connectionMock->method('select')->willReturn($this->zendSelectMock);

$resourceConnectionMock = $this->createMock(ResourceConnection::class);
$resourceConnectionMock->method('getConnection')->willReturn($this->connectionMock);
$resourceConnectionMock->method('getTableName')->willReturn('adyen_invoice');

$this->contextMock = $this->createMock(Context::class);
$this->contextMock->method('getResources')->willReturn($resourceConnectionMock);

$this->invoiceResourceModel = new Invoice($this->contextMock);
}

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

/**
* @return void
* @throws LocalizedException
*/
public function testGetIdByPspreference()
{
$pspreference = 'abc_123456789';
$invoiceId = '1';

$this->zendSelectMock->method('from')
->with('adyen_invoice', InvoiceInterface::ENTITY_ID)
->willReturnSelf();
$this->zendSelectMock->method('where')
->with('pspreference = :pspreference')
->willReturnSelf();

$this->connectionMock->method('fetchOne')
->with($this->zendSelectMock, [':pspreference' => $pspreference])
->willReturn($invoiceId);

$result = $this->invoiceResourceModel->getIdByPspreference($pspreference);
$this->assertEquals($invoiceId, $result);
}
}

0 comments on commit 9976d3e

Please sign in to comment.