Skip to content

Commit

Permalink
UNZER-527 --control gha run--
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniil Tkachev committed Nov 29, 2024
1 parent 919b39f commit 7306823
Show file tree
Hide file tree
Showing 10 changed files with 171 additions and 70 deletions.
6 changes: 5 additions & 1 deletion Tests/Integration/Service/PaymentExtensionLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
use OxidEsales\Eshop\Application\Model\Payment as PaymentModel;
use OxidSolutionCatalysts\Unzer\Service\DebugHandler;
use OxidSolutionCatalysts\Unzer\Service\PaymentExtensionLoader;
use OxidSolutionCatalysts\Unzer\Service\SavedPayment\SavedPaymentSessionService;
use OxidSolutionCatalysts\Unzer\Service\TmpOrderService;
use OxidSolutionCatalysts\Unzer\Service\Unzer;
use OxidSolutionCatalysts\Unzer\Service\UnzerSDKLoader;
use PHPUnit\Framework\TestCase;
Expand Down Expand Up @@ -39,7 +41,9 @@ public function testPaymentTypeCanBeLoaded($paymentId, $paymentClass): void
$this->getMockBuilder(Unzer::class)
->disableOriginalConstructor()
->getMock(),
$this->logger
$this->logger,
$this->createMock(SavedPaymentSessionService::class),
$this->createMock(TmpOrderService::class)
);

$loadedPaymentType = $sut->getPaymentExtension($paymentStub);
Expand Down
4 changes: 3 additions & 1 deletion Tests/Integration/Service/PaymentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use OxidEsales\TestingLibrary\UnitTestCase;
use OxidSolutionCatalysts\Unzer\Service\Payment as PaymentService;
use OxidSolutionCatalysts\Unzer\Service\PaymentExtensionLoader;
use OxidSolutionCatalysts\Unzer\Service\TmpOrderService;
use OxidSolutionCatalysts\Unzer\Service\Transaction as TransactionService;
use OxidSolutionCatalysts\Unzer\Service\Translator;
use OxidSolutionCatalysts\Unzer\Service\Unzer as UnzerService;
Expand Down Expand Up @@ -40,7 +41,8 @@ public function testRemoveTemporaryOrder($sessionValue, $expectedResult): void
$this->createPartialMock(Translator::class, []),
$this->createPartialMock(UnzerService::class, []),
$this->createPartialMock(UnzerSDKLoader::class, []),
$this->createPartialMock(TransactionService::class, [])
$this->createPartialMock(TransactionService::class, [] ),
$this->createPartialMock(TmpOrderService::class, [] )
);

$this->assertSame($expectedResult, $sut->removeTemporaryOrder());
Expand Down
21 changes: 7 additions & 14 deletions Tests/PhpStan/phpstan-bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,18 @@ class_alias(
\OxidSolutionCatalysts\Unzer\Controller\Admin\ModuleConfiguration_parent::class
);


class_alias(
\OxidEsales\Eshop\Application\Controller\Admin\OrderMain::class,
\OxidSolutionCatalysts\Unzer\Controller\Admin\OrderMain_parent::class
);


class_alias(
\OxidEsales\Eshop\Application\Controller\PaymentController::class,
\OxidSolutionCatalysts\Unzer\Controller\PaymentController_parent::class
);

class_alias(
\OxidEsales\Eshop\Application\Controller\Admin\OrderList::class,
\OxidSolutionCatalysts\Unzer\Controller\Admin\OrderList_parent::class
Expand All @@ -31,10 +38,6 @@ class_alias(
\OxidEsales\Eshop\Application\Controller\Admin\AdminDetailsController::class,
\OxidSolutionCatalysts\Unzer\Controller\Admin\AdminDetailsController_parent::class
);
class_alias(
\OxidEsales\Eshop\Application\Controller\PaymentController::class,
\OxidSolutionCatalysts\Unzer\Controller\PaymentController_parent::class
);

class_alias(
\OxidEsales\Eshop\Core\Config::class,
Expand All @@ -56,16 +59,6 @@ class_alias(
\OxidSolutionCatalysts\Unzer\Model\Article_parent::class
);

class_alias(
\OxidEsales\Eshop\Application\Model\Order::class,
\OxidSolutionCatalysts\Unzer\Model\Order_parent::class,
);

class_alias(
\OxidSolutionCatalysts\Unzer\Model\Order::class,
\OxidEsales\Eshop\Application\Model\Order::class,
);

class_alias(
\OxidEsales\Eshop\Application\Model\Payment::class,
\OxidSolutionCatalysts\Unzer\Model\Payment_parent::class
Expand Down
3 changes: 2 additions & 1 deletion Tests/Unit/Controller/DispatcherControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

namespace OxidSolutionCatalysts\Unzer\Tests\Unit\Controller;

use OxidSolutionCatalysts\Unzer\Model\Order;

use OxidEsales\Eshop\Application\Model\Order;
use OxidSolutionCatalysts\Unzer\Service\FlexibleSerializer;
use OxidSolutionCatalysts\Unzer\Service\UnzerWebhooks;
use PHPUnit\Framework\MockObject\MockObject;
Expand Down
8 changes: 7 additions & 1 deletion Tests/Unit/PaymentExtensions/UnzerPaymentTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/**
* Copyright © OXID eSales AG. All rights reserved.
* See LICENSE file for license details.
Expand All @@ -10,6 +12,8 @@
use OxidEsales\Eshop\Application\Model\Basket as BasketModel;
use OxidEsales\Eshop\Application\Model\User as UserModel;
use OxidSolutionCatalysts\Unzer\PaymentExtensions\UnzerPayment;
use OxidSolutionCatalysts\Unzer\Service\SavedPayment\SavedPaymentSessionService;
use OxidSolutionCatalysts\Unzer\Service\TmpOrderService;
use OxidSolutionCatalysts\Unzer\Service\Unzer as UnzerService;
use PHPUnit\Framework\TestCase;
use UnzerSDK\Resources\Basket;
Expand Down Expand Up @@ -58,7 +62,9 @@ public function testDefaultExecute(): void
$unzerServiceMock,
new \OxidSolutionCatalysts\Unzer\Service\DebugHandler(
$this->createMock(\Monolog\Logger::class)
)
),
$this->createMock(SavedPaymentSessionService::class),
$this->createMock(TmpOrderService::class)
],
'',
true,
Expand Down
10 changes: 8 additions & 2 deletions Tests/Unit/PaymentExtensions/UnzerPaymentTypeObjectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
namespace OxidSolutionCatalysts\Unzer\Tests\Unit\Exception;

use OxidSolutionCatalysts\Unzer\Service\DebugHandler;
use OxidSolutionCatalysts\Unzer\Service\SavedPayment\SavedPaymentSessionService;
use OxidSolutionCatalysts\Unzer\Service\TmpOrderService;
use OxidSolutionCatalysts\Unzer\Service\Unzer as UnzerService;
use PHPUnit\Framework\TestCase;
use UnzerSDK\Unzer;
Expand All @@ -29,7 +31,9 @@ public function testCreatePaymentTypePaymentTypeObject($extensionClass, $resourc
$this->getMockBuilder(UnzerService::class)->disableOriginalConstructor()->getMock(),
new DebugHandler(
$this->createMock(\Monolog\Logger::class)
)
),
$this->createMock(SavedPaymentSessionService::class),
$this->createMock(TmpOrderService::class)
);

$result = $sut->getUnzerPaymentTypeObject();
Expand Down Expand Up @@ -100,7 +104,9 @@ public function testFetchPaymentTypeObject($extensionClass, $resourceClass)
]),
new DebugHandler(
$this->createMock(\Monolog\Logger::class)
)
),
$this->createMock(SavedPaymentSessionService::class),
$this->createMock(TmpOrderService::class)
);

$result = $sut->getUnzerPaymentTypeObject();
Expand Down
10 changes: 8 additions & 2 deletions Tests/Unit/Service/PaymentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
use OxidSolutionCatalysts\Unzer\Exception\RedirectWithMessage;
use OxidSolutionCatalysts\Unzer\PaymentExtensions\UnzerPayment;
use OxidSolutionCatalysts\Unzer\Service\Payment as PaymentService;
use OxidSolutionCatalysts\Unzer\Service\SavedPayment\SavedPaymentSessionService;
use OxidSolutionCatalysts\Unzer\Service\TmpOrderService;
use OxidSolutionCatalysts\Unzer\Service\TmpOrderServiceInterface;
use OxidSolutionCatalysts\Unzer\Service\Unzer as UnzerService;
use OxidSolutionCatalysts\Unzer\Service\PaymentExtensionLoader;
use OxidSolutionCatalysts\Unzer\Service\Transaction as TransactionService;
Expand Down Expand Up @@ -179,7 +182,8 @@ protected function getPaymentServiceMock(
$translatorMock,
$this->getUnzerServiceMock(),
$this->getUnzerSDKLoaderMock(),
$this->getTransactionServiceMock()
$this->getTransactionServiceMock(),
$this->createMock(TmpOrderServiceInterface::class)
])
->onlyMethods($methodsToMock)
->getMock();
Expand Down Expand Up @@ -212,7 +216,9 @@ protected function getExtensionLoaderMock(
->setConstructorArgs([
$this->getUnzerSDKLoaderMock(),
$this->getUnzerServiceMock(),
$this->getLoggerMock()
$this->getLoggerMock(),
$this->createMock(SavedPaymentSessionService::class),
$this->createMock(TmpOrderService::class)
])->onlyMethods(['getPaymentExtension', 'getPaymentExtensionByCustomerTypeAndCurrency'])
->getMock();

Expand Down
129 changes: 129 additions & 0 deletions Tests/Unit/Service/TmpOrderServiceTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
<?php

declare(strict_types=1);

namespace OxidSolutionCatalysts\Unzer\Tests\Integration\Service;

use OxidSolutionCatalysts\Unzer\Service\TmpOrderService;
use OxidSolutionCatalysts\Unzer\Model\TmpOrder;
use OxidEsales\Eshop\Application\Model\Order;
use PHPUnit\Framework\TestCase;

class TmpOrderServiceTest extends TestCase
{
private TmpOrderService $tmpOrderService;

protected function setUp(): void
{
parent::setUp();
$this->tmpOrderService = new TmpOrderService();
}

public function testGetOrderBySessionOrderIdReturnsOrderIfLoaded(): void
{
$orderMock = $this->createMock(Order::class);
$orderMock->method('load')->with('sessionOrderId')->willReturn(true);

$tmpOrderMock = $this->createMock(TmpOrder::class);
$tmpOrderMock->expects($this->never())->method('getTmpOrderByOxOrderId');

$this->tmpOrderService = $this->getMockBuilder(TmpOrderService::class)
->setMethods(['getTmpOrder'])
->getMock();

$this->tmpOrderService
->expects($this->any())
->method('getTmpOrder')
->willReturn($tmpOrderMock);

$result = $this->tmpOrderService->getOrderBySessionOrderId('sessionOrderId');

$this->assertInstanceOf(Order::class, $result);
}

public function testGetOrderBySessionOrderIdFallsBackToTmpOrder(): void
{
$orderMock = $this->createMock(Order::class);
$orderMock->method('load')->with('sessionOrderId')->willReturn(false);

$tmpOrderMock = $this->createMock(TmpOrder::class);
$tmpOrderMock->expects($this->once())->method('getTmpOrderByOxOrderId')->with('sessionOrderId')->willReturn($orderMock);

$this->tmpOrderService = $this->getMockBuilder(TmpOrderService::class)
->setMethods(['getTmpOrder'])
->getMock();

$this->tmpOrderService
->expects($this->any())
->method('getTmpOrder')
->willReturn($tmpOrderMock);

$result = $this->tmpOrderService->getOrderBySessionOrderId('sessionOrderId');

$this->assertInstanceOf(Order::class, $result);
}

public function testGetPaymentTypeReturnsOrderPaymentType(): void
{
$orderMock = $this->createMock(Order::class);
$orderMock->method('getFieldData')->with('oxpaymenttype')->willReturn('PAYMENT_TYPE');

$result = $this->tmpOrderService->getPaymentType('sessionOrderId', $orderMock);

$this->assertSame('PAYMENT_TYPE', $result);
}

public function testGetPaymentTypeFallsBackToTmpOrder(): void
{
$orderMock = $this->createMock(Order::class);
$orderMock->method('getFieldData')->with('oxpaymenttype')->willReturn('');

$tmpOrderMock = $this->createMock(TmpOrder::class);
$tmpOrderMock->expects($this->once())->method('getTmpOrderByOxOrderId')->with('sessionOrderId')->willReturn($orderMock);

$this->tmpOrderService = $this->getMockBuilder(TmpOrderService::class)
->setMethods(['getTmpOrder'])
->getMock();

$this->tmpOrderService
->expects($this->any())
->method('getTmpOrder')
->willReturn($tmpOrderMock);

$result = $this->tmpOrderService->getPaymentType('sessionOrderId', $orderMock);

$this->assertSame('', $result);
}

public function testGetOrderCurrencyReturnsOrderCurrency(): void
{
$orderMock = $this->createMock(Order::class);
$orderMock->method('getFieldData')->with('oxcurrency')->willReturn('EUR');

$result = $this->tmpOrderService->getOrderCurrency('sessionOrderId', $orderMock, 'paymentType');

$this->assertSame('EUR', $result);
}

public function testGetOrderCurrencyFallsBackToTmpOrder(): void
{
$orderMock = $this->createMock(Order::class);
$orderMock->method('getFieldData')->with('oxcurrency')->willReturn(null);

$tmpOrderMock = $this->createMock(TmpOrder::class);
$tmpOrderMock->expects($this->once())->method('getTmpOrderByOxOrderId')->with('sessionOrderId')->willReturn($orderMock);

$this->tmpOrderService = $this->getMockBuilder(TmpOrderService::class)
->setMethods(['getTmpOrder'])
->getMock();

$this->tmpOrderService
->expects($this->any())
->method('getTmpOrder')
->willReturn($tmpOrderMock);

$result = $this->tmpOrderService->getOrderCurrency('sessionOrderId', $orderMock, 'paymentType');

$this->assertNull($result);
}
}
3 changes: 1 addition & 2 deletions Tests/Unit/Service/UnzerSDKLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ protected function getSut($moduleSettingValues): UnzerSDKLoader
$debugHandler = $this->getMockBuilder(DebugHandler::class)
->setConstructorArgs([$this->createMock(Logger::class)])
->getMock();
$session = $this->createConfiguredMock(Session::class, []);

return new UnzerSDKLoader($moduleSettings, $debugHandler, $session);
return new UnzerSDKLoader($moduleSettings, $debugHandler);
}
}
47 changes: 1 addition & 46 deletions Tests/Unit/Service/UnzerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use OxidSolutionCatalysts\Unzer\Service\ModuleSettings;
use OxidSolutionCatalysts\Unzer\Service\Payment;
use OxidSolutionCatalysts\Unzer\Service\PaymentExtensionLoader;
use OxidSolutionCatalysts\Unzer\Service\TmpOrderServiceInterface;
use OxidSolutionCatalysts\Unzer\Service\Transaction;
use OxidSolutionCatalysts\Unzer\Service\Translator;
use OxidSolutionCatalysts\Unzer\Service\Unzer;
Expand Down Expand Up @@ -106,52 +107,6 @@ public function getPaymentProcedureDataProvider(): array
];
}

public function testIfImmediatePostAuthCollectTrue(): void
{
$moduleSettings = $this->createPartialMock(ModuleSettings::class, ['getPaymentProcedureSetting']);
$moduleSettings->method('getPaymentProcedureSetting')
->willReturn(ModuleSettings::PAYMENT_CHARGE);
$sut = $this->getSut([ModuleSettings::class => $moduleSettings]);
$paymentService = $this->getPaymentServiceMock($sut);

$this->assertTrue($sut->ifImmediatePostAuthCollect($paymentService));
}

public function testIfImmediatePostAuthCollectFalse(): void
{
$moduleSettings = $this->createPartialMock(ModuleSettings::class, ['getPaymentProcedureSetting']);
$moduleSettings->method('getPaymentProcedureSetting')
->willReturn(ModuleSettings::PAYMENT_AUTHORIZE);
$sut = $this->getSut([ModuleSettings::class => $moduleSettings]);
$paymentService = $this->getPaymentServiceMock($sut);

$paymentService->method('getUnzerOrderId')
->willReturn('666');

$sql = "INSERT INTO oxorder SET OXID=9999, OXPAYMENTTYPE='oscunzer_paypal', OXUNZERORDERNR=666";
DatabaseProvider::getDb()->execute($sql);

$this->assertFalse($sut->ifImmediatePostAuthCollect($paymentService));
}

private function getPaymentServiceMock($sut)
{
return $this->getMockBuilder(Payment::class)
->setConstructorArgs(
[
$this->createMock(Session::class),
$this->createMock(PaymentExtensionLoader::class),
$this->createMock(Translator::class),
$sut,
$this->createMock(UnzerSDKLoader::class),
$this->createMock(Transaction::class),
$this->createMock(TransactionService::class)
]
)
->getMock();
}


public function testGetPaymentProcedureAuthorizeForListedPayment(): void
{
$paymentType = 'paypal';
Expand Down

0 comments on commit 7306823

Please sign in to comment.