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 3cbb7ca commit 7740e8f
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 3 deletions.
9 changes: 6 additions & 3 deletions Test/Unit/AbstractAdyenTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,13 @@ protected function createOrder(?string $status = null)
]);
}

protected function createWebhook(?string $originalReference = null, ?string $pspReference = null)
{
protected function createWebhook(
?string $originalReference = null,
?string $pspReference = null,
?int $value = 1000
) {
return $this->createConfiguredMock(Notification::class, [
'getAmountValue' => 1000,
'getAmountValue' => $value,
'getEventCode' => 'AUTHORISATION',
'getAmountCurrency' => 'EUR',
'getOriginalReference' => $originalReference,
Expand Down
58 changes: 58 additions & 0 deletions Test/Unit/Helper/InvoiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,64 @@ public function testCreateInvoice()
$this->assertInstanceOf(InvoiceModel::class, $invoice);
}

private static function notificationAmountDataProvider(): array
{
return [
['notificationAmount' => 0],
['notificationAmount' => 1000]
];
}

/**
* @dataProvider notificationAmountDataProvider
*
* @throws LocalizedException
*/
public function testCreateInvoiceManualCapture($notificationAmount = 1000)
{
$invoiceMock = $this->createGeneratedMock(InvoiceModel::class, [
'setRequestedCaptureCase',
'getOrder',
'register'
]);
$invoiceMock->method('getOrder')->willReturn($this->createMock(Order::class));
$invoiceMock->method('register')->willReturn($this->createMock(InvoiceModel::class));

$orderMock = $this->createConfiguredMock(MagentoOrder::class, [
'prepareInvoice' => $invoiceMock,
'canInvoice' => true,
]);

$scopeConfigMock = $this->createConfiguredMock(ScopeConfigInterface::class, [
'isSetFlag' => false
]);
$contextMock = $this->createConfiguredMock(Context::class, [
'getScopeConfig' => $scopeConfigMock
]);

$invoiceHelper = $this->createInvoiceHelper($contextMock);

$notificationMock = $this->createWebhook(null, null, $notificationAmount);

if ($notificationAmount == 0) {
$invoiceMock->expects($this->once())
->method('setRequestedCaptureCase')
->with(InvoiceModel::CAPTURE_OFFLINE);
} else {
$invoiceMock->expects($this->once())
->method('setRequestedCaptureCase')
->with(InvoiceModel::NOT_CAPTURE);
}

$invoice = $invoiceHelper->createInvoice(
$orderMock,
$notificationMock,
false
);

$this->assertInstanceOf(InvoiceModel::class, $invoice);
}

public function testCreateAdyenInvoice()
{
$adyenInvoiceMockForFactory = $this->createMock(AdyenInvoice::class);
Expand Down

0 comments on commit 7740e8f

Please sign in to comment.