Skip to content

Commit a52aa74

Browse files
committed
SP-X Updating dependencies and tests, adding generated config files to gitignore
1 parent 0c6293b commit a52aa74

File tree

5 files changed

+86
-32
lines changed

5 files changed

+86
-32
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: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@
1212
],
1313
"homepage": "https://github.com/bitpay/php-bitpay-client-v2",
1414
"require": {
15-
"php": "^8.1 || ^8.2 || ^8.3 || ^8.4",
15+
"php": "*",
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": "^6.4",
2121
"netresearch/jsonmapper": "^5.0",
22-
"symfony/console": "^4.4 || ^5.4 || ^6.0"
22+
"symfony/console": "^6.4"
2323
},
2424
"authors": [
2525
{
@@ -28,7 +28,7 @@
2828
}
2929
],
3030
"require-dev": {
31-
"phpunit/phpunit": "^10.5 || ^11.5 || ^12.0"
31+
"phpunit/phpunit": "^10.5"
3232
},
3333
"scripts": {
3434
"setup": [

composer.lock

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

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: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,15 @@ 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+
$this->markTestSkipped(
40+
'No settlements found in test account. ' .
41+
'To test this functionality, ensure your test account has processed transactions.'
42+
);
43+
return;
44+
}
45+
3746
$settlement = $this->client->getSettlement($settlements[0]->getId());
3847

3948
self::assertNotNull($settlement);
@@ -50,12 +59,22 @@ public function testGetReconciliationReport(): void
5059
$currency = 'USD';
5160

5261
$settlements = $this->client->getSettlements($currency, $dateStart, $dateEnd, $status);
62+
63+
if (empty($settlements)) {
64+
$this->markTestSkipped(
65+
'No settlements found in test account. ' .
66+
'To test this functionality, ensure your test account has processed transactions.'
67+
);
68+
return;
69+
}
70+
5371
$settlement = $this->client->getSettlement($settlements[0]->getId());
54-
$settlement = $this->client->getSettlementReconciliationReport($settlement);
72+
$settlementId = $settlement->getId();
73+
$token = $settlement->getToken();
74+
$reconciliationReport = $this->client->getSettlementReconciliationReport($settlementId, $token);
5575

56-
self::assertEquals('processing', $settlement->getStatus());
57-
self::assertNotNull($settlement);
58-
self::assertEquals('USD', $settlement->getCurrency());
59-
self::assertEquals($status, $settlement->getStatus());
76+
self::assertNotNull($reconciliationReport);
77+
self::assertEquals($currency, $reconciliationReport->getCurrency());
78+
self::assertEquals($status, $reconciliationReport->getStatus());
6079
}
6180
}

0 commit comments

Comments
 (0)