-
Notifications
You must be signed in to change notification settings - Fork 211
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Can Demiralp
committed
Jan 28, 2025
1 parent
75bf608
commit 9976d3e
Showing
1 changed file
with
82 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |