From efea515a996138e6f24ac8795369a18083480b3f Mon Sep 17 00:00:00 2001 From: LiHS Date: Thu, 6 Apr 2023 16:26:11 +0800 Subject: [PATCH 1/9] update composer.json for different phpunit version --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index bf5c7252..36437028 100644 --- a/composer.json +++ b/composer.json @@ -23,7 +23,7 @@ }, "require-dev": { "paragonie/random_compat": ">=2", - "phpunit/phpunit": "~4.0", + "phpunit/phpunit": "^4.8 || ^5.0 || ^6.0 || ^7.0 || ^8.0 || ^9.3.4", "squizlabs/php_codesniffer": "~3.6" }, "autoload": { From 949367076c9fc36927695c4d93d5064a7112313a Mon Sep 17 00:00:00 2001 From: LiHS Date: Thu, 6 Apr 2023 16:26:26 +0800 Subject: [PATCH 2/9] change test base class --- tests/Qiniu/Tests/AuthTest.php | 4 +++- tests/Qiniu/Tests/Base64Test.php | 4 +++- tests/Qiniu/Tests/BucketTest.php | 4 +++- tests/Qiniu/Tests/CdnManagerTest.php | 4 +++- tests/Qiniu/Tests/ConfigTest.php | 4 +++- tests/Qiniu/Tests/Crc32Test.php | 4 +++- tests/Qiniu/Tests/DownloadTest.php | 4 +++- tests/Qiniu/Tests/EntryTest.php | 4 +++- tests/Qiniu/Tests/EtagTest.php | 4 +++- tests/Qiniu/Tests/FopTest.php | 4 +++- tests/Qiniu/Tests/FormUpTest.php | 4 +++- tests/Qiniu/Tests/HeaderTest.php | 4 +++- tests/Qiniu/Tests/HttpTest.php | 4 +++- tests/Qiniu/Tests/ImageUrlBuilderTest.php | 4 +++- tests/Qiniu/Tests/PfopTest.php | 4 +++- tests/Qiniu/Tests/ResumeUpTest.php | 4 +++- tests/Qiniu/Tests/ZoneTest.php | 4 +++- 17 files changed, 51 insertions(+), 17 deletions(-) diff --git a/tests/Qiniu/Tests/AuthTest.php b/tests/Qiniu/Tests/AuthTest.php index bf4387f4..e86bd850 100755 --- a/tests/Qiniu/Tests/AuthTest.php +++ b/tests/Qiniu/Tests/AuthTest.php @@ -11,12 +11,14 @@ function time() } namespace Qiniu\Tests { + use PHPUnit\Framework\TestCase; + use Qiniu\Auth; use Qiniu\Http\Header; // @codingStandardsIgnoreEnd - class AuthTest extends \PHPUnit_Framework_TestCase + class AuthTest extends TestCase { public function testSign() diff --git a/tests/Qiniu/Tests/Base64Test.php b/tests/Qiniu/Tests/Base64Test.php index 6d633530..fed3da07 100755 --- a/tests/Qiniu/Tests/Base64Test.php +++ b/tests/Qiniu/Tests/Base64Test.php @@ -1,9 +1,11 @@ array('200'), diff --git a/tests/Qiniu/Tests/HttpTest.php b/tests/Qiniu/Tests/HttpTest.php index 2342f962..bbd65ca9 100755 --- a/tests/Qiniu/Tests/HttpTest.php +++ b/tests/Qiniu/Tests/HttpTest.php @@ -1,10 +1,12 @@ */ -class ImageUrlBuilderTest extends \PHPUnit_Framework_TestCase +class ImageUrlBuilderTest extends TestCase { /** * 缩略图测试 diff --git a/tests/Qiniu/Tests/PfopTest.php b/tests/Qiniu/Tests/PfopTest.php index d03b3f6e..19bacc00 100755 --- a/tests/Qiniu/Tests/PfopTest.php +++ b/tests/Qiniu/Tests/PfopTest.php @@ -1,10 +1,12 @@ Date: Thu, 6 Apr 2023 16:39:34 +0800 Subject: [PATCH 3/9] use annotations instead overriding method --- tests/Qiniu/Tests/BucketTest.php | 5 ++++- tests/Qiniu/Tests/CdnManagerTest.php | 5 ++++- tests/Qiniu/Tests/ConfigTest.php | 5 ++++- tests/Qiniu/Tests/FormUpTest.php | 5 ++++- tests/Qiniu/Tests/ResumeUpTest.php | 20 ++++++++++++++------ tests/Qiniu/Tests/ZoneTest.php | 5 ++++- 6 files changed, 34 insertions(+), 11 deletions(-) diff --git a/tests/Qiniu/Tests/BucketTest.php b/tests/Qiniu/Tests/BucketTest.php index 648b1261..9827314d 100755 --- a/tests/Qiniu/Tests/BucketTest.php +++ b/tests/Qiniu/Tests/BucketTest.php @@ -16,7 +16,10 @@ class BucketTest extends TestCase protected $key2; protected $customCallbackURL; - protected function setUp() + /** + * @before + */ + protected function setUpBucketManager() { global $bucketName; global $key; diff --git a/tests/Qiniu/Tests/CdnManagerTest.php b/tests/Qiniu/Tests/CdnManagerTest.php index 40a8fc6d..baa9486c 100755 --- a/tests/Qiniu/Tests/CdnManagerTest.php +++ b/tests/Qiniu/Tests/CdnManagerTest.php @@ -26,7 +26,10 @@ class CdnManagerTest extends TestCase protected $customDomain; protected $customDomain2; - protected function setUp() + /** + * @before + */ + protected function setUpCdnManager() { global $testAuth; $this->cdnManager = new CdnManager($testAuth); diff --git a/tests/Qiniu/Tests/ConfigTest.php b/tests/Qiniu/Tests/ConfigTest.php index 25094669..796cb2d1 100644 --- a/tests/Qiniu/Tests/ConfigTest.php +++ b/tests/Qiniu/Tests/ConfigTest.php @@ -10,7 +10,10 @@ class ConfigTest extends TestCase protected $accessKey; protected $bucketName; - protected function setUp() + /** + * @before + */ + protected function setUpAkAndBucket() { global $accessKey; $this->accessKey = $accessKey; diff --git a/tests/Qiniu/Tests/FormUpTest.php b/tests/Qiniu/Tests/FormUpTest.php index 26aaf543..f9e9cb01 100755 --- a/tests/Qiniu/Tests/FormUpTest.php +++ b/tests/Qiniu/Tests/FormUpTest.php @@ -13,7 +13,10 @@ class FormUpTest extends TestCase protected $auth; protected $cfg; - protected function setUp() + /** + * @before + */ + protected function setUpConfigAndBucket() { global $bucketName; $this->bucketName = $bucketName; diff --git a/tests/Qiniu/Tests/ResumeUpTest.php b/tests/Qiniu/Tests/ResumeUpTest.php index 1137f078..2a9bef39 100755 --- a/tests/Qiniu/Tests/ResumeUpTest.php +++ b/tests/Qiniu/Tests/ResumeUpTest.php @@ -16,7 +16,10 @@ class ResumeUpTest extends TestCase { private static $keyToDelete = array(); - public static function tearDownAfterClass() + /** + * @afterClass + */ + public static function cleanupTestData() { global $bucketName; global $testAuth; @@ -30,7 +33,10 @@ public static function tearDownAfterClass() protected $bucketName; protected $auth; - protected function setUp() + /** + * @before + */ + protected function setUpAuthAndBucket() { global $bucketName; $this->bucketName = $bucketName; @@ -171,8 +177,9 @@ public function testResumeUploadWithParams() $response = Client::get("http://$domain/$key"); $this->assertEquals(200, $response->statusCode); $this->assertEquals(md5_file($tempFile, true), md5($response->body(), true)); - $this->assertEquals("val_1", $response->headers()["X-Qn-Meta-M1"]); - $this->assertEquals("val_2", $response->headers()["X-Qn-Meta-M2"]); + $headers = $response->headers(); + $this->assertEquals("val_1", $headers["X-Qn-Meta-M1"]); + $this->assertEquals("val_2", $headers["X-Qn-Meta-M2"]); unlink($tempFile); } @@ -245,8 +252,9 @@ public function testResumeUploadV2WithParams() $response = Client::get("http://$domain/$key"); $this->assertEquals(200, $response->statusCode); $this->assertEquals(md5_file($tempFile, true), md5($response->body(), true)); - $this->assertEquals("val_1", $response->headers()["X-Qn-Meta-M1"]); - $this->assertEquals("val_2", $response->headers()["X-Qn-Meta-M2"]); + $headers = $response->headers(); + $this->assertEquals("val_1", $headers["X-Qn-Meta-M1"]); + $this->assertEquals("val_2", $headers["X-Qn-Meta-M2"]); unlink($tempFile); } diff --git a/tests/Qiniu/Tests/ZoneTest.php b/tests/Qiniu/Tests/ZoneTest.php index a44352a9..a1ae4591 100755 --- a/tests/Qiniu/Tests/ZoneTest.php +++ b/tests/Qiniu/Tests/ZoneTest.php @@ -19,7 +19,10 @@ class ZoneTest extends TestCase protected $bucketNameAS; - protected function setUp() + /** + * @before + */ + protected function setUpZoneAndBucket() { global $bucketName; $this->bucketName = $bucketName; From c88c4e79f53b4992aaefc303180d4809cda82452 Mon Sep 17 00:00:00 2001 From: LiHS Date: Thu, 6 Apr 2023 16:52:12 +0800 Subject: [PATCH 4/9] remove empty test case --- tests/Qiniu/Tests/AuthTest.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/tests/Qiniu/Tests/AuthTest.php b/tests/Qiniu/Tests/AuthTest.php index e86bd850..38b6eaed 100755 --- a/tests/Qiniu/Tests/AuthTest.php +++ b/tests/Qiniu/Tests/AuthTest.php @@ -67,10 +67,6 @@ public function testUploadToken() unset($_SERVER['override_qiniu_auth_time']); } - public function testVerifyCallback() - { - } - public function testSignQiniuAuthorization() { $auth = new Auth("ak", "sk"); From 15181ec77b03aa04b1c8e2b6d9a8cdacb4d28c4e Mon Sep 17 00:00:00 2001 From: LiHS Date: Thu, 6 Apr 2023 18:33:00 +0800 Subject: [PATCH 5/9] make myclabs/php-enum compatible --- composer.json | 2 +- src/Qiniu/Enum/QiniuEnum.php | 58 ++++++++++++++++++++---------------- 2 files changed, 34 insertions(+), 26 deletions(-) diff --git a/composer.json b/composer.json index 36437028..5608c0c8 100644 --- a/composer.json +++ b/composer.json @@ -19,7 +19,7 @@ ], "require": { "php": ">=5.3.3", - "myclabs/php-enum": "1.6.6" + "myclabs/php-enum": "~1.6.6 || ~1.7.7 || ~1.8.4" }, "require-dev": { "paragonie/random_compat": ">=2", diff --git a/src/Qiniu/Enum/QiniuEnum.php b/src/Qiniu/Enum/QiniuEnum.php index 28afac87..3b0190b4 100644 --- a/src/Qiniu/Enum/QiniuEnum.php +++ b/src/Qiniu/Enum/QiniuEnum.php @@ -1,41 +1,49 @@ Date: Fri, 7 Apr 2023 11:00:52 +0800 Subject: [PATCH 6/9] make compatible with php 8.x --- .github/workflows/test-ci.yml | 2 +- README.md | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/test-ci.yml b/.github/workflows/test-ci.yml index 86d5c865..e98983c9 100644 --- a/.github/workflows/test-ci.yml +++ b/.github/workflows/test-ci.yml @@ -10,7 +10,7 @@ jobs: fail-fast: false max-parallel: 1 matrix: - php-versions: ['5.4', '5.5', '5.6', '7.0'] + php-versions: ['5.4', '5.5', '5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2'] runs-on: ubuntu-latest steps: - name: Checkout diff --git a/README.md b/README.md index 447a07d9..784d735a 100644 --- a/README.md +++ b/README.md @@ -12,18 +12,18 @@ ## 安装 -* 推荐使用 `composer` 进行安装。可以使用 composer.json 声明依赖,或者运行下面的命令。SDK 包已经放到这里 [`qiniu/php-sdk`][install-packagist] 。 +推荐使用 `composer` 进行安装。可以使用 composer.json 声明依赖,或者运行下面的命令。SDK 包已经放到这里 [`qiniu/php-sdk`][install-packagist] 。 + ```bash $ composer require qiniu/php-sdk ``` -* 直接下载安装,SDK 没有依赖其他第三方库,但需要参照 composer 的 autoloader,增加一个自己的 autoloader 程序。 ## 运行环境 -| Qiniu SDK版本 | PHP 版本 | -|:--------------------:|:---------------------------:| -| 7.x | cURL extension, 5.3 - 5.6,7.0 | -| 6.x | cURL extension, 5.2 - 5.6 | +| Qiniu SDK版本 | PHP 版本 | +|:--------------------:|:-----------------------------------------------:| +| 7.x | cURL extension, 5.3 - 5.6, 7.0 - 7.4, 8.0-8.1 | +| 6.x | cURL extension, 5.2 - 5.6 | ## 使用方法 From 6e7df9cb07ff4d454157d6348e0e9558490d1a51 Mon Sep 17 00:00:00 2001 From: LiHS Date: Mon, 10 Apr 2023 11:39:26 +0800 Subject: [PATCH 7/9] fix compatibility with php 5.3 --- .github/workflows/test-ci.yml | 21 +++++++++-- composer.json | 4 +- src/Qiniu/Enum/QiniuEnum.php | 8 +++- src/Qiniu/Http/Header.php | 2 +- src/Qiniu/Storage/BucketManager.php | 57 ++++++++++++++++++++++------- src/Qiniu/functions.php | 19 ++++++++++ tests/Qiniu/Tests/ConfigTest.php | 1 + tests/Qiniu/Tests/ResumeUpTest.php | 4 +- 8 files changed, 91 insertions(+), 25 deletions(-) diff --git a/.github/workflows/test-ci.yml b/.github/workflows/test-ci.yml index e98983c9..cf44df92 100644 --- a/.github/workflows/test-ci.yml +++ b/.github/workflows/test-ci.yml @@ -10,12 +10,22 @@ jobs: fail-fast: false max-parallel: 1 matrix: - php-versions: ['5.4', '5.5', '5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2'] + php-versions: ['5.3', '5.4', '5.5', '5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2'] runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v2 + - name: Setup php for mock server + uses: shivammathur/setup-php@v2 + with: + php-version: '8.2' + + - name: Setup build-in server + run: | + nohup php -S localhost:9000 -t ./tests/mock-server/ > phpd.log 2>&1 & + echo $! > mock-server.pid + - name: Setup php uses: shivammathur/setup-php@v2 with: @@ -28,13 +38,11 @@ jobs: - name: Run cases run: | - nohup php -S localhost:9000 -t ./tests/mock-server/ > phpd.log 2>&1 & - export PHP_SERVER_PID=$! ./vendor/bin/phpcs --standard=PSR2 src ./vendor/bin/phpcs --standard=PSR2 examples ./vendor/bin/phpcs --standard=PSR2 tests ./vendor/bin/phpunit --coverage-clover=coverage.xml - kill $PHP_SERVER_PID + cat mock-server.pid | xargs kill env: QINIU_ACCESS_KEY: ${{ secrets.QINIU_ACCESS_KEY }} @@ -42,5 +50,10 @@ jobs: QINIU_TEST_BUCKET: ${{ secrets.QINIU_TEST_BUCKET }} QINIU_TEST_DOMAIN: ${{ secrets.QINIU_TEST_DOMAIN }} + - name: Print mock servion log + if: ${{ failure() }} + run: | + cat phpd.log + - name: After_success run: bash <(curl -s https://codecov.io/bash) diff --git a/composer.json b/composer.json index 5608c0c8..f32512f6 100644 --- a/composer.json +++ b/composer.json @@ -19,12 +19,12 @@ ], "require": { "php": ">=5.3.3", - "myclabs/php-enum": "~1.6.6 || ~1.7.7 || ~1.8.4" + "myclabs/php-enum": "~1.5.2 || ~1.6.6 || ~1.7.7 || ~1.8.4" }, "require-dev": { "paragonie/random_compat": ">=2", "phpunit/phpunit": "^4.8 || ^5.0 || ^6.0 || ^7.0 || ^8.0 || ^9.3.4", - "squizlabs/php_codesniffer": "~3.6" + "squizlabs/php_codesniffer": "^2.3 || ~3.6" }, "autoload": { "psr-4": { diff --git a/src/Qiniu/Enum/QiniuEnum.php b/src/Qiniu/Enum/QiniuEnum.php index 3b0190b4..8399b542 100644 --- a/src/Qiniu/Enum/QiniuEnum.php +++ b/src/Qiniu/Enum/QiniuEnum.php @@ -1,6 +1,6 @@ $cond 匹配条件,只有条件匹配才会设置成功,目前支持:hash、mime、fsize、putTime + * @param int $to_line_after_days 多少天后将文件转为低频存储。 + * 设置为 -1 表示取消已设置的转低频存储的生命周期规则; + * 0 表示不修改转低频生命周期规则。 + * @param int $to_archive_after_days 多少天后将文件转为归档存储。 + * -1 表示取消已设置的转归档存储的生命周期规则; + * 0 表示不修改转归档生命周期规则。 + * @param int $to_deep_archive_after_days 多少天后将文件转为深度归档存储。 + * -1 表示取消已设置的转深度归档存储的生命周期规则; + * 0 表示不修改转深度归档生命周期规则。 + * @param int $delete_after_days 多少天后将文件删除。 + * -1 表示取消已设置的删除存储的生命周期规则; + * 0 表示不修改删除存储的生命周期规则。 + * @param array $cond 匹配条件,只有条件匹配才会设置成功。 + * 目前支持:hash、mime、fsize、putTime * @return array */ public function setObjectLifecycleWithCond( @@ -1124,10 +1145,18 @@ public static function buildBatchDeleteAfterDays($bucket, $key_day_pairs) /** * @param string $bucket 空间名 * @param array $keys 目标资源 - * @param int $to_line_after_days 多少天后将文件转为低频存储,设置为 -1 表示取消已设置的转低频存储的生命周期规则, 0 表示不修改转低频生命周期规则。 - * @param int $to_archive_after_days 多少天后将文件转为归档存储,设置为 -1 表示取消已设置的转归档存储的生命周期规则, 0 表示不修改转归档生命周期规则。 - * @param int $to_deep_archive_after_days 多少天后将文件转为深度归档存储,设置为 -1 表示取消已设置的转深度归档存储的生命周期规则, 0 表示不修改转深度归档生命周期规则。 - * @param int $delete_after_days 多少天后将文件删除,设置为 -1 表示取消已设置的删除存储的生命周期规则, 0 表示不修改删除存储的生命周期规则。 + * @param int $to_line_after_days 多少天后将文件转为低频存储。 + * -1 表示取消已设置的转低频存储的生命周期规则; + * 0 表示不修改转低频生命周期规则。 + * @param int $to_archive_after_days 多少天后将文件转为归档存储。 + * -1 表示取消已设置的转归档存储的生命周期规则; + * 0 表示不修改转归档生命周期规则。 + * @param int $to_deep_archive_after_days 多少天后将文件转为深度归档存储。 + * -1 表示取消已设置的转深度归档存储的生命周期规则; + * 0 表示不修改转深度归档生命周期规则。 + * @param int $delete_after_days 多少天后将文件删除。 + * -1 表示取消已设置的删除存储的生命周期规则; + * 0 表示不修改删除存储的生命周期规则。 * * @retrun array */ diff --git a/src/Qiniu/functions.php b/src/Qiniu/functions.php index 9a768e6f..dba8af78 100644 --- a/src/Qiniu/functions.php +++ b/src/Qiniu/functions.php @@ -278,4 +278,23 @@ function explodeUpToken($upToken) $bucket = $scopeItems[0]; return array($accessKey, $bucket, null); } + + // polyfill ucwords for php version < 5.4.32 + if (phpversion() < "5.4.32") { + function ucwords($str, $delimiters = " \t\r\n\f\v") + { + $delims = preg_split('//u', $delimiters, -1, PREG_SPLIT_NO_EMPTY); + + foreach ($delims as $delim) { + $str = implode($delim, array_map('ucfirst', explode($delim, $str))); + } + + return $str; + } + } else { + function ucwords($str, $delimiters) + { + return \ucwords($str, $delimiters); + } + } } diff --git a/tests/Qiniu/Tests/ConfigTest.php b/tests/Qiniu/Tests/ConfigTest.php index 796cb2d1..c2b229cc 100644 --- a/tests/Qiniu/Tests/ConfigTest.php +++ b/tests/Qiniu/Tests/ConfigTest.php @@ -1,6 +1,7 @@ "val_1", "x:var_2" => "val_2", "x-qn-meta-m1" => "val_1", "x-qn-meta-m2" => "val_2"], + array("x:var_1" => "val_1", "x:var_2" => "val_2", "x-qn-meta-m1" => "val_1", "x-qn-meta-m2" => "val_2"), 'application/octet-stream', false, $resumeFile @@ -236,7 +236,7 @@ public function testResumeUploadV2WithParams() $token, $key, $tempFile, - ["x:var_1" => "val_1", "x:var_2" => "val_2", "x-qn-meta-m1" => "val_1", "x-qn-meta-m2" => "val_2"], + array("x:var_1" => "val_1", "x:var_2" => "val_2", "x-qn-meta-m1" => "val_1", "x-qn-meta-m2" => "val_2"), 'application/octet-stream', false, $resumeFile, From b7a6473eb96de24d20bd447612bce8b8b9cdeceb Mon Sep 17 00:00:00 2001 From: LiHS Date: Mon, 17 Apr 2023 11:08:38 +0800 Subject: [PATCH 8/9] fix php version compare --- src/Qiniu/functions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Qiniu/functions.php b/src/Qiniu/functions.php index dba8af78..e76fbf0b 100644 --- a/src/Qiniu/functions.php +++ b/src/Qiniu/functions.php @@ -280,7 +280,7 @@ function explodeUpToken($upToken) } // polyfill ucwords for php version < 5.4.32 - if (phpversion() < "5.4.32") { + if (version_compare(phpversion(), "5.4.32") < 0) { function ucwords($str, $delimiters = " \t\r\n\f\v") { $delims = preg_split('//u', $delimiters, -1, PREG_SPLIT_NO_EMPTY); From 605f8523631ff119c57e2af417cd5df99c19c2e2 Mon Sep 17 00:00:00 2001 From: LiHS Date: Mon, 17 Apr 2023 14:03:17 +0800 Subject: [PATCH 9/9] ucwords polyfill for php 5.5 --- src/Qiniu/functions.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Qiniu/functions.php b/src/Qiniu/functions.php index e76fbf0b..f8c19042 100644 --- a/src/Qiniu/functions.php +++ b/src/Qiniu/functions.php @@ -279,8 +279,13 @@ function explodeUpToken($upToken) return array($accessKey, $bucket, null); } - // polyfill ucwords for php version < 5.4.32 - if (version_compare(phpversion(), "5.4.32") < 0) { + // polyfill ucwords for `php version < 5.4.32` or `5.5.0 <= php version < 5.5.16` + if (version_compare(phpversion(), "5.4.32") < 0 || + ( + version_compare(phpversion(), "5.5.0") >= 0 && + version_compare(phpversion(), "5.5.16") < 0 + ) + ) { function ucwords($str, $delimiters = " \t\r\n\f\v") { $delims = preg_split('//u', $delimiters, -1, PREG_SPLIT_NO_EMPTY);