diff --git a/Test/Unit/AbstractAdyenTestCase.php b/Test/Unit/AbstractAdyenTestCase.php index 17f5a57a9..d87445bca 100644 --- a/Test/Unit/AbstractAdyenTestCase.php +++ b/Test/Unit/AbstractAdyenTestCase.php @@ -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, diff --git a/Test/Unit/Helper/InvoiceTest.php b/Test/Unit/Helper/InvoiceTest.php index 0b458ff27..c98bd41f9 100644 --- a/Test/Unit/Helper/InvoiceTest.php +++ b/Test/Unit/Helper/InvoiceTest.php @@ -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);