Skip to content

Commit 758ac3d

Browse files
authored
Merge pull request #381 from SUMO-Kwiatkowski/SP-X
Updating dependencies and tests, adding generated config files t…
2 parents 0c6293b + 956e1bf commit 758ac3d

File tree

6 files changed

+182
-34
lines changed

6 files changed

+182
-34
lines changed

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,8 @@ composer.phar
1212
.phpunit.result.cache
1313
test/unit/_html
1414

15-
PrivateKey.key
15+
PrivateKey.key
16+
BitPay.config.json
17+
**/BitPay.config.json
18+
BitPay.config.yml
19+
**/BitPay.config.yml

composer.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616
"ext-json": "*",
1717
"ext-reflection": "*",
1818
"bitpay/key-utils": "^2.1",
19-
"guzzlehttp/guzzle": "^7.0",
20-
"symfony/yaml": "^5.0 || ^6.0 || ^7.0",
19+
"guzzlehttp/guzzle": "^7.9",
20+
"symfony/yaml": "^5.4 || ^6.4 || ^7.0",
2121
"netresearch/jsonmapper": "^5.0",
22-
"symfony/console": "^4.4 || ^5.4 || ^6.0"
22+
"symfony/console": "^4.4 || ^5.4 || ^6.4"
2323
},
2424
"authors": [
2525
{
@@ -28,7 +28,8 @@
2828
}
2929
],
3030
"require-dev": {
31-
"phpunit/phpunit": "^10.5 || ^11.5 || ^12.0"
31+
"phpunit/phpunit": "^10.5 || ^11.5 || ^12.0",
32+
"squizlabs/php_codesniffer": "^3.13"
3233
},
3334
"scripts": {
3435
"setup": [
@@ -47,4 +48,4 @@
4748
"BitPaySDK\\Functional\\": "test/functional/BitPaySDK"
4849
}
4950
}
50-
}
51+
}

composer.lock

Lines changed: 115 additions & 23 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ruleset.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,8 @@
22
<ruleset name="BitPayStandard">
33
<description>BitPay coding standard, based on PSR-12, temporarily excluding some rules.</description>
44
<rule ref="PSR12"/>
5+
<exclude-pattern>*/vendor/*</exclude-pattern>
6+
<exclude-pattern>*/node_modules/*</exclude-pattern>
7+
<exclude-pattern>*.css</exclude-pattern>
8+
<exclude-pattern>*.js</exclude-pattern>
59
</ruleset>

test/functional/BitPaySDK/AbstractClientTestCase.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,36 @@ abstract class AbstractClientTestCase extends TestCase
1212
{
1313
protected Client $client;
1414

15+
// Default delay in seconds between API calls
16+
private const API_CALL_DELAY = 0.5;
17+
private static $lastApiCallTime = 0;
18+
1519
/**
1620
* @throws BitPayGenericException
1721
*/
1822
public function setUp(): void
1923
{
24+
// Add delay to respect rate limits
25+
$this->respectRateLimit();
26+
2027
$this->client = Client::createWithFile(
2128
Config::FUNCTIONAL_TEST_PATH . DIRECTORY_SEPARATOR . Config::BITPAY_CONFIG_FILE
2229
);
2330
}
31+
32+
/**
33+
* Delays execution if needed to respect rate limits
34+
*/
35+
protected function respectRateLimit(): void
36+
{
37+
$currentTime = microtime(true);
38+
$timeSinceLastCall = $currentTime - self::$lastApiCallTime;
39+
40+
if (self::$lastApiCallTime > 0 && $timeSinceLastCall < self::API_CALL_DELAY) {
41+
$sleepTime = (self::API_CALL_DELAY - $timeSinceLastCall);
42+
usleep((int)($sleepTime * 1000000)); // Convert to microseconds
43+
}
44+
45+
self::$lastApiCallTime = microtime(true);
46+
}
2447
}

test/functional/BitPaySDK/SettlementsClientTest.php

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,17 @@ public function testGetSettlement(): void
3434

3535
$settlements = $this->client->getSettlements($currency, $dateStart, $dateEnd, $status);
3636

37+
// Skip test if no settlements exist
38+
if (empty($settlements)) {
39+
error_log(PHP_EOL . 'No settlements found in test account. ' .
40+
'Skipping test. To test this functionality, ensure your test account has processed transactions.');
41+
$this->markTestSkipped(
42+
'No settlements found in test account. ' .
43+
'To test this functionality, ensure your test account has processed transactions.'
44+
);
45+
return;
46+
}
47+
3748
$settlement = $this->client->getSettlement($settlements[0]->getId());
3849

3950
self::assertNotNull($settlement);
@@ -50,12 +61,25 @@ public function testGetReconciliationReport(): void
5061
$currency = 'USD';
5162

5263
$settlements = $this->client->getSettlements($currency, $dateStart, $dateEnd, $status);
64+
65+
if (empty($settlements)) {
66+
error_log( PHP_EOL . 'No settlements found in test account. ' .
67+
'Skipping test. To test this functionality, ensure your test account has processed transactions.
68+
');
69+
$this->markTestSkipped(
70+
'No settlements found in test account. ' .
71+
'To test this functionality, ensure your test account has processed transactions.'
72+
);
73+
return;
74+
}
75+
5376
$settlement = $this->client->getSettlement($settlements[0]->getId());
54-
$settlement = $this->client->getSettlementReconciliationReport($settlement);
77+
$settlementId = $settlement->getId();
78+
$token = $settlement->getToken();
79+
$reconciliationReport = $this->client->getSettlementReconciliationReport($settlementId, $token);
5580

56-
self::assertEquals('processing', $settlement->getStatus());
57-
self::assertNotNull($settlement);
58-
self::assertEquals('USD', $settlement->getCurrency());
59-
self::assertEquals($status, $settlement->getStatus());
81+
self::assertNotNull($reconciliationReport);
82+
self::assertEquals($currency, $reconciliationReport->getCurrency());
83+
self::assertEquals($status, $reconciliationReport->getStatus());
6084
}
6185
}

0 commit comments

Comments
 (0)