Skip to content

Commit da40c7b

Browse files
authored
Merge pull request #5 from Kucoin/snapshot/2025.07.01
Add tests and improve PHP version compatibility #54
2 parents de77d01 + fa65640 commit da40c7b

File tree

13 files changed

+579
-15
lines changed

13 files changed

+579
-15
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ API documentation [Changelog](https://www.kucoin.com/docs-new/change-log)
44

55
Current synchronized API documentation version [20250529](https://www.kucoin.com/docs-new/change-log#20250529)
66

7+
## 2025-06-11(PHP 0.1.3-alpha)
8+
- Add compatibility for PHP versions from 7.4 to 8.x
9+
710
## 2025-06-11(1.3.0)
811
- Update the latest APIs, documentation, etc
912
- Introduced a new testing framework for all SDKs

Dockerfile

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,25 @@
1-
FROM php:8.1-cli
1+
ARG PHP_RUNTIME=8.1
22

3-
RUN apt-get update && apt-get install -y unzip git \
3+
FROM php:8.1-cli AS builder
4+
WORKDIR /src
5+
RUN apt-get update && apt-get install -y unzip git jq \
46
&& curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
7+
COPY . .
8+
ARG SDK_VERSION=0.0.1-alpha
59

6-
WORKDIR /app
7-
COPY src ./src
8-
COPY composer.json ./
9-
COPY example ./example
10-
RUN composer install
10+
RUN cp composer.json composer.json.bak \
11+
&& jq --arg ver "$SDK_VERSION" '. + {version: $ver}' composer.json.bak > composer.json
12+
RUN rm -f composer.lock
13+
RUN composer install --no-dev --optimize-autoloader && \
14+
mkdir -p /build_out && \
15+
composer archive --format=tar --dir=/build_out
1116

12-
WORKDIR /app/example
13-
#CMD ["php", "ExampleGetStarted.php"]
14-
CMD ["php", "ExampleWs.php"]
17+
FROM php:${PHP_RUNTIME}-cli
18+
WORKDIR /app
19+
RUN apt-get update && apt-get install -y unzip git libzip-dev \
20+
&& curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
21+
RUN docker-php-ext-install zip
22+
COPY . /src
23+
COPY example /app/example
24+
COPY script /app
25+
COPY --from=builder /build_out /tmp

Makefile

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
2+
.PHONY: build
3+
build:
4+
docker build -t php-sdk-image:latest .
5+
6+
.PHONY: auto-test
7+
auto-test: build
8+
docker run --rm php-sdk-image:latest bash /app/auto_test.sh
9+
10+
.PHONY: before-release-test
11+
before-release-test: build
12+
docker run --rm \
13+
-e API_KEY="$$API_KEY" \
14+
-e API_SECRET="$$API_SECRET" \
15+
-e API_PASSPHRASE="$$API_PASSPHRASE" \
16+
-e USE_LOCAL="true" \
17+
php-sdk-image:latest \
18+
bash /app/release_test.sh
19+
20+
.PHONY: after-release-test
21+
after-release-test: build
22+
docker run --rm \
23+
-e API_KEY="$$API_KEY" \
24+
-e API_SECRET="$$API_SECRET" \
25+
-e API_PASSPHRASE="$$API_PASSPHRASE" \
26+
php-sdk-image:latest \
27+
bash /app/release_test.sh
28+
29+
.PHONY: run-forever-test
30+
run-forever-test: build
31+
docker rm -f php-run-forever-test
32+
docker run -idt \
33+
-e API_KEY="$$API_KEY" \
34+
-e API_SECRET="$$API_SECRET" \
35+
-e API_PASSPHRASE="$$API_PASSPHRASE" \
36+
--name php-run-forever-test \
37+
php-sdk-image:latest \
38+
bash /app/run_forever_test.sh
39+
40+
.PHONY: reconnect-test
41+
reconnect-test: build
42+
docker rm -f php-reconnect-test
43+
docker run -idt \
44+
-e API_KEY="$$API_KEY" \
45+
-e API_SECRET="$$API_SECRET" \
46+
-e API_PASSPHRASE="$$API_PASSPHRASE" \
47+
--name php-reconnect-test --network isolated_net \
48+
php-sdk-image:latest \
49+
bash /app/ws_reconnect_test.sh
50+
51+
52+
VERSIONS = 7.4 8.0 8.1 8.2
53+
.PHONY: php-version-test
54+
php-version-test:
55+
@for v in $(VERSIONS); do \
56+
echo "---- PHP $$v ----"; \
57+
docker build --build-arg PHP_RUNTIME=$$v -t php-sdk-image:$$v . ; \
58+
docker run --rm \
59+
-e API_KEY="$$API_KEY" \
60+
-e API_SECRET="$$API_SECRET" \
61+
-e API_PASSPHRASE="$$API_PASSPHRASE" \
62+
-e USE_LOCAL="true" \
63+
php-sdk-image:$$v bash /app/release_test.sh || exit $$? ; \
64+
done

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ For an overview of the project and SDKs in other languages, refer to the [Main R
1313

1414
## 📦 Installation
1515

16-
### Latest Version: `0.1.2-alpha`
16+
### Latest Version: `0.1.3-alpha`
1717

1818
**Note**: This SDK is currently in the Alpha phase. We are actively iterating and improving its features, stability, and documentation. Feedback and contributions are highly encouraged to help us refine the SDK.
1919

2020
Install the SDK using `composer`:
2121

2222
```bash
23-
composer require kucoin/kucoin-universal-sdk=0.1.2-alpha
23+
composer require kucoin/kucoin-universal-sdk=0.1.3-alpha
2424
```
2525

2626
## 📖 Getting Started

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
}
2424
],
2525
"require": {
26-
"php": ">=7.4",
26+
"php": "^7.4 || ^8.0",
2727
"jms/serializer": "^3.32",
2828
"doctrine/annotations": "^2.0",
2929
"guzzlehttp/guzzle": "^7.9",

script/auto_test.sh

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#!/bin/bash
2+
3+
cd /src
4+
composer install
5+
6+
LOG_FILE="/src/test.log"
7+
[ -f "$LOG_FILE" ] && rm "$LOG_FILE"
8+
9+
overall_total=0
10+
overall_success=0
11+
overall_fail=0
12+
13+
{
14+
printf "%-20s | %-10s | %-10s | %-10s\n" "Directory" "Total" "Success" "Fail"
15+
printf "%-20s-+-%-10s-+-%-10s-+-%-10s\n" "--------------------" "----------" "----------" "----------"
16+
} | tee "$LOG_FILE"
17+
18+
for dir in src/Generate/*/; do
19+
dir_name=${dir%/}
20+
dir_name=${dir_name##*/}
21+
22+
test_output=$(vendor/bin/phpunit "$dir" --colors=never 2>&1 || true)
23+
echo "$test_output" >> "$LOG_FILE"
24+
25+
summary_line=$(echo "$test_output" | grep -E "OK \(|Tests:|No tests executed")
26+
27+
if [[ $summary_line == OK* ]]; then
28+
# OK (5 tests, 12 assertions)
29+
total_tests=$(echo "$summary_line" | grep -oE '[0-9]+' | head -n1)
30+
failed_tests=0
31+
elif [[ $summary_line == Tests:* ]]; then
32+
# Tests: 7, Assertions: 12, Failures: 2, Errors: 1
33+
total_tests=$(echo "$summary_line" | grep -oE 'Tests:[[:space:]]*[0-9]+' | grep -oE '[0-9]+')
34+
failed_tests=$(echo "$summary_line" | grep -oE 'Failures:[[:space:]]*[0-9]+' | grep -oE '[0-9]+')
35+
failed_tests=${failed_tests:-0}
36+
else
37+
# No tests executed!
38+
total_tests=0
39+
failed_tests=0
40+
fi
41+
42+
successful_tests=$((total_tests - failed_tests))
43+
44+
printf "%-20s | %-10d | %-10d | %-10d\n" \
45+
"$dir_name" "$total_tests" "$successful_tests" "$failed_tests" | tee -a "$LOG_FILE"
46+
47+
overall_total=$((overall_total + total_tests))
48+
overall_success=$((overall_success + successful_tests))
49+
overall_fail=$((overall_fail + failed_tests))
50+
done
51+
52+
{
53+
printf "%-20s-+-%-10s-+-%-10s-+-%-10s\n" "--------------------" "----------" "----------" "----------"
54+
printf "%-20s | %-10d | %-10d | %-10d\n" \
55+
"Overall Summary" "$overall_total" "$overall_success" "$overall_fail"
56+
} | tee -a "$LOG_FILE"
57+
58+
exit "$overall_fail"

script/release_test.sh

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/bin/bash
2+
set -e
3+
4+
echo "USE_LOCAL = ${USE_LOCAL:-<unset>}"
5+
6+
echo '{
7+
"name": "test/test",
8+
"description": "Test project",
9+
"type": "project",
10+
"require": {},
11+
"minimum-stability": "alpha",
12+
"prefer-stable": true
13+
}' > composer.json
14+
15+
16+
if [[ "${USE_LOCAL,,}" == "true" ]]; then
17+
echo "Installing local package(s)…"
18+
ls /tmp/*.tar 1>/dev/null 2>&1
19+
mkdir -p ./local-packages
20+
cp /tmp/*.tar ./local-packages/
21+
composer config repositories.local artifact ./local-packages
22+
composer require kucoin/kucoin-universal-sdk
23+
else
24+
echo "📦 Installing kucoin-universal-sdk from Packagist…"
25+
composer require kucoin/kucoin-universal-sdk
26+
fi
27+
28+
echo "Echo depends..."
29+
composer depends php
30+
31+
echo "Running service scripts..."
32+
cp /src/tests/regression/RunServiceTest.php /app
33+
composer require phpunit/phpunit
34+
composer require ramsey/uuid
35+
vendor/bin/phpunit --colors --bootstrap vendor/autoload.php RunServiceTest.php
36+
37+
echo "Running example scripts..."
38+
cd /app/example
39+
php ExampleAPI.php
40+
php ExampleGetStarted.php
41+
php ExampleSign.php
42+
php ExampleWs.php

script/run_forever_test.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/bin/bash
2+
set -e
3+
4+
echo "USE_LOCAL = ${USE_LOCAL:-<unset>}"
5+
6+
echo '{
7+
"name": "test/test",
8+
"description": "Test project",
9+
"type": "project",
10+
"require": {},
11+
"minimum-stability": "alpha",
12+
"prefer-stable": true
13+
}' > composer.json
14+
15+
16+
if [[ "${USE_LOCAL,,}" == "true" ]]; then
17+
echo "Installing local package(s)…"
18+
ls /tmp/*.tar 1>/dev/null 2>&1
19+
mkdir -p ./local-packages
20+
cp /tmp/*.tar ./local-packages/
21+
composer config repositories.local artifact ./local-packages
22+
composer require kucoin/kucoin-universal-sdk
23+
else
24+
echo "📦 Installing kucoin-universal-sdk from Packagist…"
25+
composer require kucoin/kucoin-universal-sdk
26+
fi
27+
28+
cat composer.json
29+
30+
echo "Running scripts..."
31+
cp /src/tests/regression/RunForeverTest.php /app
32+
php -d memory_limit=512M RunForeverTest.php

script/ws_reconnect_test.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/bin/bash
2+
set -e
3+
4+
echo "USE_LOCAL = ${USE_LOCAL:-<unset>}"
5+
6+
echo '{
7+
"name": "test/test",
8+
"description": "Test project",
9+
"type": "project",
10+
"require": {},
11+
"minimum-stability": "alpha",
12+
"prefer-stable": true
13+
}' > composer.json
14+
15+
16+
if [[ "${USE_LOCAL,,}" == "true" ]]; then
17+
echo "Installing local package(s)…"
18+
ls /tmp/*.tar 1>/dev/null 2>&1
19+
mkdir -p ./local-packages
20+
cp /tmp/*.tar ./local-packages/
21+
composer config repositories.local artifact ./local-packages
22+
composer require kucoin/kucoin-universal-sdk
23+
else
24+
echo "📦 Installing kucoin-universal-sdk from Packagist…"
25+
composer require kucoin/kucoin-universal-sdk
26+
fi
27+
28+
cat composer.json
29+
30+
echo "Running scripts..."
31+
cp /src/tests/regression/RunReconnectTest.php /app
32+
php -d memory_limit=512M RunReconnectTest.php

src/Generate/Version.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44

55
class Version
66
{
7-
const SDK_VERSION = "0.1.2-alpha";
8-
const SDK_GENERATE_DATE = "2025-06-11";
7+
const SDK_VERSION = "0.1.3-alpha";
8+
const SDK_GENERATE_DATE = "2025-07-01";
99
}

0 commit comments

Comments
 (0)