Skip to content

Commit 7fe6ea4

Browse files
committed
test: update tests for new thepay/api-client config structure
Rewrite DITest to verify new flat config (merchantId, projectId, apiPassword, apiUrl, gateUrl, language) and demo endpoint switching. Remove TpPaymentTest that tested deleted Payment/MerchantConfig classes. Fix before callback to handle missing demo key.
1 parent e1a5576 commit 7fe6ea4

File tree

3 files changed

+49
-68
lines changed

3 files changed

+49
-68
lines changed

src/DI/ThePayExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public function getConfigSchema(): Schema
2626
{
2727
return Expect::from($this->config)->before(
2828
function (array $config): array {
29-
if ($config['demo'] === true) {
29+
if (($config['demo'] ?? false) === true) {
3030
$this->config->setDemo();
3131
$config['apiUrl'] = $this->config->apiUrl;
3232
$config['gateUrl'] = $this->config->gateUrl;

tests/Cases/DITest.phpt

Lines changed: 48 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ Toolkit::test(function (): void {
1818
[
1919
'thepay' => [
2020
'demo' => true,
21+
'merchantId' => 'test-merchant-id',
22+
'projectId' => 3,
23+
'apiPassword' => 'secret',
2124
],
2225
]
2326
);
@@ -26,13 +29,12 @@ Toolkit::test(function (): void {
2629
$thePayConfig = $thePayExtension->getConfig();
2730

2831
Assert::same(true, $thePayConfig->demo);
29-
Assert::same('https://www.thepay.cz/demo-gate/', $thePayConfig->merchant->gateUrl);
30-
Assert::same(1, $thePayConfig->merchant->merchantId);
31-
Assert::same(1, $thePayConfig->merchant->accountId);
32-
Assert::same('my$up3rsecr3tp4$$word', $thePayConfig->merchant->password);
33-
Assert::same('my$up3rsecr3tp4$$word', $thePayConfig->merchant->dataApiPassword);
34-
Assert::same('https://www.thepay.cz/demo-gate/api/gate-api-demo.wsdl', $thePayConfig->merchant->webServicesWsdl);
35-
Assert::same('https://www.thepay.cz/demo-gate/api/data-demo.wsdl', $thePayConfig->merchant->dataWebServicesWsdl);
32+
Assert::same('test-merchant-id', $thePayConfig->merchantId);
33+
Assert::same(3, $thePayConfig->projectId);
34+
Assert::same('secret', $thePayConfig->apiPassword);
35+
Assert::same('https://demo.api.thepay.cz/', $thePayConfig->apiUrl);
36+
Assert::same('https://demo.gate.thepay.cz/', $thePayConfig->gateUrl);
37+
Assert::same('cs', $thePayConfig->language);
3638
});
3739

3840
Toolkit::test(function (): void {
@@ -44,12 +46,9 @@ Toolkit::test(function (): void {
4446
[
4547
'thepay' => [
4648
'demo' => false,
47-
'merchant' => [
48-
'merchantId' => 10,
49-
'accountId' => 42,
50-
'password' => 'abc',
51-
'dataApiPassword' => 'def',
52-
],
49+
'merchantId' => 'prod-merchant-id',
50+
'projectId' => 10,
51+
'apiPassword' => 'prod-secret',
5352
],
5453
]
5554
);
@@ -58,11 +57,40 @@ Toolkit::test(function (): void {
5857
$thePayConfig = $thePayExtension->getConfig();
5958

6059
Assert::same(false, $thePayConfig->demo);
61-
Assert::same('https://www.thepay.cz/gate/', $thePayConfig->merchant->gateUrl);
62-
Assert::same(10, $thePayConfig->merchant->merchantId);
63-
Assert::same(42, $thePayConfig->merchant->accountId);
64-
Assert::same('abc', $thePayConfig->merchant->password);
65-
Assert::same('def', $thePayConfig->merchant->dataApiPassword);
66-
Assert::same('https://www.thepay.cz/gate/api/gate-api.wsdl', $thePayConfig->merchant->webServicesWsdl);
67-
Assert::same('https://www.thepay.cz/gate/api/data.wsdl', $thePayConfig->merchant->dataWebServicesWsdl);
60+
Assert::same('prod-merchant-id', $thePayConfig->merchantId);
61+
Assert::same(10, $thePayConfig->projectId);
62+
Assert::same('prod-secret', $thePayConfig->apiPassword);
63+
Assert::same('https://api.thepay.cz/', $thePayConfig->apiUrl);
64+
Assert::same('https://gate.thepay.cz/', $thePayConfig->gateUrl);
65+
Assert::same('cs', $thePayConfig->language);
66+
});
67+
68+
Toolkit::test(function (): void {
69+
$thePayExtension = new ThePayExtension();
70+
71+
$compiler = new Compiler();
72+
$compiler->addExtension('thepay', $thePayExtension);
73+
$compiler->addConfig(
74+
[
75+
'thepay' => [
76+
'merchantId' => 'custom-merchant',
77+
'projectId' => 5,
78+
'apiPassword' => 'pass',
79+
'apiUrl' => 'https://custom.api.thepay.cz/',
80+
'gateUrl' => 'https://custom.gate.thepay.cz/',
81+
'language' => 'en',
82+
],
83+
]
84+
);
85+
$compiler->processExtensions();
86+
87+
$thePayConfig = $thePayExtension->getConfig();
88+
89+
Assert::same(false, $thePayConfig->demo);
90+
Assert::same('custom-merchant', $thePayConfig->merchantId);
91+
Assert::same(5, $thePayConfig->projectId);
92+
Assert::same('pass', $thePayConfig->apiPassword);
93+
Assert::same('https://custom.api.thepay.cz/', $thePayConfig->apiUrl);
94+
Assert::same('https://custom.gate.thepay.cz/', $thePayConfig->gateUrl);
95+
Assert::same('en', $thePayConfig->language);
6896
});

tests/Cases/TpPaymentTest.phpt

Lines changed: 0 additions & 47 deletions
This file was deleted.

0 commit comments

Comments
 (0)