Skip to content

Commit

Permalink
codestyle refinement
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniil Tkachev committed Dec 2, 2024
1 parent dbd2475 commit 1082fff
Show file tree
Hide file tree
Showing 42 changed files with 454 additions and 301 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
22 changes: 11 additions & 11 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 @@ -57,19 +60,16 @@ class_alias(
);

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


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

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

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

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
Expand Up @@ -5,11 +5,15 @@
* See LICENSE file for license details.
*/

declare(strict_types=1);

namespace OxidSolutionCatalysts\Unzer\Tests\Unit\Exception;

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
142 changes: 142 additions & 0 deletions Tests/Unit/Service/TmpOrderServiceTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
<?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->any())
->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->any())
->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->any())
->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->assertEquals('', $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);
}
}
Loading

0 comments on commit 1082fff

Please sign in to comment.