Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniil Tkachev committed Feb 17, 2025
1 parent 156b874 commit b05c61c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 35 deletions.
42 changes: 9 additions & 33 deletions src/Service/PaymentExtensionLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,60 +56,35 @@ class PaymentExtensionLoader
UnzerDefinitions::WECHATPAY_UNZER_PAYMENT_ID => WeChatPay::class,
];

/**
* @var UnzerSDKLoader
*/
private $unzerSdkLoader;

/**
* @var Unzer
*/
private $unzerService;
private UnzerSDKLoader $unzerSdkLoader;
private Unzer $unzerService;

private DebugHandler $logger;
private TmpOrderService $tmpOrderService;

/**
* @param UnzerSDKLoader $unzerSDKLoader
* @param Unzer $unzerService
*/
public function __construct(
UnzerSDKLoader $unzerSDKLoader,
Unzer $unzerService,
DebugHandler $logger
DebugHandler $logger,
TmpOrderService $tmpOrderService
) {
$this->unzerSdkLoader = $unzerSDKLoader;
$this->unzerService = $unzerService;
$this->logger = $logger;
$this->tmpOrderService = $tmpOrderService;
}

/**
* Please only use this method if you want to have static information about the payment method and do not
* need functions of the SDK. The SDK must always be loaded with the correct credentials. This is only
* guaranteed if method getPaymentExtensionByCustomerTypeAndCurrency is used, as only this loads the SDK
* with the correct credentials at all times
* @param PaymentModel $payment
* @return AbstractUnzerPayment
*/
public function getPaymentExtension(PaymentModel $payment): AbstractUnzerPayment
{
return oxNew(
self::UNZERCLASSNAMEMAPPING[$payment->getId()],
$this->unzerSdkLoader->getUnzerSDK(),
$this->unzerService,
$this->logger,
new TmpOrderService()
$this->tmpOrderService
);
}

/**
* Please only use this method if you need the SDK. This is the only way to load the SDK with the correct
* credentials. The getPaymentExtension method is only used to obtain static information about the payment
* method.
* @param PaymentModel $payment
* @param string $customerType
* @param string $currency
* @return AbstractUnzerPayment
*/
public function getPaymentExtensionByCustomerTypeAndCurrency(
PaymentModel $payment,
string $customerType,
Expand All @@ -123,7 +98,8 @@ public function getPaymentExtensionByCustomerTypeAndCurrency(
$customerType
),
$this->unzerService,
$this->logger
$this->logger,
$this->tmpOrderService
);
}
}
3 changes: 2 additions & 1 deletion tests/Integration/Service/PaymentExtensionLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ public function testPaymentTypeCanBeLoaded($paymentId, $paymentClass): void
$this->getMockBuilder(Unzer::class)
->disableOriginalConstructor()
->getMock(),
$this->logger
$this->logger,
new \OxidSolutionCatalysts\Unzer\Service\TmpOrderService()
);

$loadedPaymentType = $sut->getPaymentExtension($paymentStub);
Expand Down
4 changes: 3 additions & 1 deletion tests/Unit/Service/PaymentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use OxidSolutionCatalysts\Unzer\Exception\RedirectWithMessage;
use OxidSolutionCatalysts\Unzer\PaymentExtensions\UnzerPayment;
use OxidSolutionCatalysts\Unzer\Service\Payment as PaymentService;
use OxidSolutionCatalysts\Unzer\Service\TmpOrderService;
use OxidSolutionCatalysts\Unzer\Service\Unzer as UnzerService;
use OxidSolutionCatalysts\Unzer\Service\PaymentExtensionLoader;
use OxidSolutionCatalysts\Unzer\Service\Transaction as TransactionService;
Expand Down Expand Up @@ -212,7 +213,8 @@ protected function getExtensionLoaderMock(
->setConstructorArgs([
$this->getUnzerSDKLoaderMock(),
$this->getUnzerServiceMock(),
$this->getLoggerMock()
$this->getLoggerMock(),
new TmpOrderService()
])->onlyMethods(['getPaymentExtension', 'getPaymentExtensionByCustomerTypeAndCurrency'])
->getMock();

Expand Down

0 comments on commit b05c61c

Please sign in to comment.