Skip to content

Commit b459cc7

Browse files
committed
Test class
1 parent eabd870 commit b459cc7

22 files changed

+214
-43
lines changed

.travis.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,5 @@ after_script:
2424

2525
env:
2626
global:
27-
- secure: "YoNsx6iMZ+YX2W5XIw9RXc/uYd5velr5HWFMPI0Oe67G8FVrQZwnu/3YZIa7FO2OBonCpbDAznIDUaGw2KxT3Yt6NgYTSn/6fcSXgxspCFsSjtUAAKbofbKDPc6r0HUVSZi5XN66SlgNGsHRne2gBSlEFs/AwCAnn0ijfWy9QUP2klWY15VLURGSv9rXt9vKNtNTGVtz1sBeR6WRi2TFcdJbjn5vrGwn5fLTWA78vnc8m7bmQKHO1Jmxm/nfeUiWvGomBRnl+dzRp4nd4Q8YnVjJthFMTeNGL4MEPf4rFo/d83+Hm6hIWskwDZn7VGAxRLBB4yvH3BTR8cM75bF8A5iQsM93DPYohKT/Fw1N0gXsNa8UvctmnUfNug4ou83nZBdQ1UWk8QLr0JWN+adfuVR4fa5N3Izy3Gwczkv5SNHlykq9Izxz2QDTknZuWA2z+V0RD029r+MFGRIp3qeOpcW/iYhKx2BBS2CTFA6awQnFw3BPgCQ2JUoos5wf+ifJMjn2TG4eCTMOLAsGkLryB4YGNHsrr2UrafHJiDJn+c8BxY+7vdoqOg3y2vY96/VqbUlM8uwIiFgTQnTkiGJHSgH8QHwvGXqWq7+NCTXFIjPAHi4FH2K0iBD2L+c/ANMUYDdhIxIjQbm78YkHBosbxaXcNjYSqYDJSUvMGeBiNvM="
28-
- accessKey=vHg2e7nOh7Jsucv2Azr5FH6omPgX22zoJRWa0FN5
27+
- secure: "V9BsntXQZwvO9EOD6itzaae2uq+GemzyTUTxMTJx1/jFoUNpCU2O2UAgjA2XSEr5sgci0KWDV4Krbzv3EBB4uplOFLMI3w32256UHbT9E0x3YjhfPJZk68MH1iS1be7X81LDHON7yveavK8987s3qzjeUcbfLSPgccT+cvf7+dc="
28+
- QINIU_ACCESS_KEY=vHg2e7nOh7Jsucv2Azr5FH6omPgX22zoJRWa0FN5

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"php": ">=5.3.3"
1717
},
1818
"require-dev": {
19-
"phpunit/phpunit": "~4.0",
19+
"phpunit/phpunit": "~8.0",
2020
"squizlabs/php_codesniffer": "~2.3"
2121
},
2222
"autoload": {

examples/put_bucketAccessMode.php

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
require_once __DIR__ . '/../autoload.php';
3+
4+
use Qiniu\Auth;
5+
6+
$accessKey = getenv('QINIU_ACCESS_KEY');
7+
$secretKey = getenv('QINIU_SECRET_KEY');
8+
9+
$auth = new Auth($accessKey, $secretKey);
10+
$config = new \Qiniu\Config();
11+
$bucketManager = new \Qiniu\Storage\BucketManager($auth, $config);
12+
13+
$bucket = 'xxxx';
14+
$private = 1;
15+
16+
list($Info, $err) = $bucketManager->putBucketAccessMode($bucket, $private);
17+
if ($err) {
18+
print_r($err);
19+
} else {
20+
print_r($Info);
21+
}

examples/put_referAntiLeech.php

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
require_once __DIR__ . '/../autoload.php';
3+
4+
use Qiniu\Auth;
5+
6+
$accessKey = getenv('QINIU_ACCESS_KEY');
7+
$secretKey = getenv('QINIU_SECRET_KEY');
8+
9+
$auth = new Auth($accessKey, $secretKey);
10+
$config = new \Qiniu\Config();
11+
$bucketManager = new \Qiniu\Storage\BucketManager($auth, $config);
12+
13+
$bucket = 'xxxx';
14+
$mode = 1;
15+
$norefer = "1";
16+
$pattern = "*.qiniu.com";
17+
18+
list($Info, $err) = $bucketManager->putReferAntiLeech($bucket, $mode, $norefer, $pattern);
19+
if ($err) {
20+
print_r($err);
21+
} else {
22+
print_r($Info);
23+
}

examples/rsf_v2list_bucket.php

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
require_once __DIR__ . '/../autoload.php';
3+
4+
use Qiniu\Auth;
5+
use Qiniu\Storage\BucketManager;
6+
7+
// http://developer.qiniu.com/docs/v6/api/reference/rs/list.html#list-description
8+
9+
$accessKey = getenv('QINIU_ACCESS_KEY');
10+
$secretKey = getenv('QINIU_SECRET_KEY');
11+
$bucket = 'xxxx';
12+
$auth = new Auth($accessKey, $secretKey);
13+
$bucketManager = new BucketManager($auth);
14+
15+
16+
// 要列取文件的公共前缀
17+
$prefix = '';
18+
19+
// 上次列举返回的位置标记,作为本次列举的起点信息。
20+
$marker = '';
21+
22+
// 本次列举的条目数
23+
$limit = 1000;
24+
25+
$delimiter = '';
26+
27+
list($ret, $err) = $bucketManager->listFilesv2($bucket, $prefix, $marker, $limit, $delimiter, true);
28+
29+
if ($err) {
30+
print_r($err);
31+
} else {
32+
print_r($ret);
33+
}

phpunit.xml.dist

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
convertWarningsToExceptions="true"
99
processIsolation="false"
1010
stopOnFailure="false"
11-
syntaxCheck="true"
1211
>
1312
<testsuites>
1413
<testsuite name="Qiniu SDK Tests">

src/Qiniu/Storage/BucketManager.php

+82-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public function listbuckets(
7373
*
7474
* @return mixed 成功返回NULL,失败返回对象Qiniu\Http\Error
7575
*/
76-
public function creatBucket($name, $region = 'z0')
76+
public function createBucket($name, $region = 'z0')
7777
{
7878
$path = '/mkbucketv2/'.$name.'/region/' . $region;
7979
return $this->rsPost($path, null);
@@ -172,6 +172,53 @@ public function listFiles(
172172
return $this->get($url);
173173
}
174174

175+
/**
176+
* 列取空间的文件列表
177+
*
178+
* @param $bucket 空间名
179+
* @param $prefix 列举前缀
180+
* @param $marker 列举标识符
181+
* @param $limit 单次列举个数限制
182+
* @param $delimiter 指定目录分隔符
183+
* @param $skipconfirm 是否跳过已删除条目的确认机制
184+
*
185+
* @return array 包含文件信息的数组,类似:[
186+
* {
187+
* "hash" => "<Hash string>",
188+
* "key" => "<Key string>",
189+
* "fsize" => "<file size>",
190+
* "putTime" => "<file modify time>"
191+
* },
192+
* ...
193+
* ]
194+
* @link http://developer.qiniu.com/docs/v6/api/reference/rs/list.html
195+
*/
196+
public function listFilesv2(
197+
$bucket,
198+
$prefix = null,
199+
$marker = null,
200+
$limit = 1000,
201+
$delimiter = null,
202+
$skipconfirm = true
203+
) {
204+
$query = array('bucket' => $bucket);
205+
\Qiniu\setWithoutEmpty($query, 'prefix', $prefix);
206+
\Qiniu\setWithoutEmpty($query, 'marker', $marker);
207+
\Qiniu\setWithoutEmpty($query, 'limit', $limit);
208+
\Qiniu\setWithoutEmpty($query, 'delimiter', $delimiter);
209+
\Qiniu\setWithoutEmpty($query, 'skipconfirm', $skipconfirm);
210+
$path = '/v2/list?' . http_build_query($query);
211+
$url = $this->getRsfHost() . $path;
212+
$headers = $this->auth->authorization($url, null, 'application/x-www-form-urlencoded');
213+
$ret = Client::post($url, null, $headers);
214+
if (!$ret->ok()) {
215+
return array(null, new Error($url, $ret));
216+
}
217+
$r = explode("\n", $ret->body);
218+
$pop = array_pop($r);
219+
return array($r, null);
220+
}
221+
175222
/**
176223
* 设置Referer防盗链
177224
*
@@ -539,6 +586,40 @@ public function putBucketAccessStyleMode($bucket, $mode)
539586
return $info;
540587
}
541588

589+
/**
590+
* 设置私有属性
591+
* private为0表示公开,为1表示私有
592+
*/
593+
public function putBucketAccessMode($bucket, $private)
594+
{
595+
$path = '/bucket/' . $bucket . '/private/' . $private;
596+
$info = $this->ucPost($path, null);
597+
return $info;
598+
}
599+
600+
/**
601+
* 设置referer防盗链
602+
* bucket=<BucketName>: bucket 名
603+
* mode=<AntiLeechMode>:
604+
* 0: 表示关闭Referer(使用此选项将会忽略以下参数并将恢复默认值);
605+
* 1: 表示设置Referer白名单; 2: 表示设置Referer黑名单
606+
* norefer=<NoRefer>: 0: 表示不允许空 Refer 访问;
607+
* 1: 表示允许空 Refer 访问
608+
* pattern=<Pattern>: 规则字符串, 当前允许格式分为三种:
609+
* 一种为空主机头域名, 比如 foo.com;
610+
* 一种是泛域名, 比如 *.bar.com; 一种是完全通配符, 即一个 *;
611+
* 多个规则之间用;隔开, 比如: foo.com;*.bar.com;sub.foo.com;*.sub.bar.com
612+
* 空主机头域名可以是多级域名,比如 foo.bar.com。
613+
* 多个域名之间不允许夹带空白字符。
614+
* source_enabled=:1
615+
*/
616+
public function putReferAntiLeech($bucket, $mode, $norefer, $pattern, $source_enabled=1)
617+
{
618+
$path = "/referAntiLeech?bucket=$bucket&mode=$mode&norefer=$norefer&pattern=$pattern&source_enabled=$source_enabled";
619+
$info = $this->ucPost($path, null);
620+
return $info;
621+
}
622+
542623
/**
543624
* 设置Bucket的maxAge
544625
* maxAge为0或者负数表示为默认值(31536000)

tests/Qiniu/Tests/AuthTest.php

+12-11
Original file line numberDiff line numberDiff line change
@@ -5,32 +5,33 @@
55
function time()
66
{
77
return isset($_SERVER['override_qiniu_auth_time'])
8-
? 1234567890
8+
? 2234567890
99
: \time();
1010
}
1111
}
1212

1313
namespace Qiniu\Tests {
1414
use Qiniu\Auth;
15+
use PHPUnit\Framework\TestCase;
1516

1617
// @codingStandardsIgnoreEnd
1718

18-
class AuthTest extends \PHPUnit_Framework_TestCase
19+
class AuthTest extends TestCase
1920
{
2021

2122
public function testSign()
2223
{
2324
global $dummyAuth;
2425
$token = $dummyAuth->sign('test');
25-
$this->assertEquals('vHg2e7nOh7Jsucv2Azr5FH6omPgX22zoJRWa0FN5:ctIk00JjhyKWX6DfmX-Rqy6e2U0=', $token);
26+
$this->assertEquals('abcdefghklmnopq:mSNBTR7uS2crJsyFr2Amwv1LaYg=', $token);
2627
}
2728

2829
public function testSignWithData()
2930
{
3031
global $dummyAuth;
3132
$token = $dummyAuth->signWithData('test');
3233
$this->assertEquals(
33-
'vHg2e7nOh7Jsucv2Azr5FH6omPgX22zoJRWa0FN5:D0TKcI_ZrPkfVcQf7jGDMEyIa-c=:dGVzdA==',
34+
'abcdefghklmnopq:-jP8eEV9v48MkYiBGs81aDxl60E=:dGVzdA==',
3435
$token
3536
);
3637
}
@@ -39,18 +40,21 @@ public function testSignRequest()
3940
{
4041
global $dummyAuth;
4142
$token = $dummyAuth->signRequest('http://www.qiniu.com?go=1', 'test', '');
42-
$this->assertEquals('vHg2e7nOh7Jsucv2Azr5FH6omPgX22zoJRWa0FN5:SUg7X6VuSkvoAtB7n7LmArDomzw=', $token);
43+
$this->assertEquals('abcdefghklmnopq:cFyRVoWrE3IugPIMP5YJFTO-O-Y=', $token);
4344
$ctype = 'application/x-www-form-urlencoded';
4445
$token = $dummyAuth->signRequest('http://www.qiniu.com?go=1', 'test', $ctype);
45-
$this->assertEquals($token, 'abcdefghklmnopq:svWRNcacOE-YMsc70nuIYdaa1e4=');
46+
$this->assertEquals(
47+
$token,
48+
'abcdefghklmnopq:svWRNcacOE-YMsc70nuIYdaa1e4='
49+
);
4650
}
4751

4852
public function testPrivateDownloadUrl()
4953
{
5054
global $dummyAuth;
5155
$_SERVER['override_qiniu_auth_time'] = true;
5256
$url = $dummyAuth->privateDownloadUrl('http://www.qiniu.com?go=1');
53-
$expect = 'http://www.qiniu.com?go=1&e=1234571490&token=vHg2e7nOh7Jsucv2Azr5FH6omPgX22zoJRWa0FN5';
57+
$expect = 'http://www.qiniu.com?go=1&e=2234571490&token=abcdefghklmnopq:Hvi3R79Sl6wZy1c331nv0iIFoJk=';
5458
$this->assertEquals($expect, $url);
5559
unset($_SERVER['override_qiniu_auth_time']);
5660
}
@@ -61,14 +65,11 @@ public function testUploadToken()
6165
$_SERVER['override_qiniu_auth_time'] = true;
6266
$token = $dummyAuth->uploadToken('1', '2', 3600, array('endUser' => 'y'));
6367
// @codingStandardsIgnoreStart
64-
$exp = 'vHg2e7nOh7Jsucv2Azr5FH6omPgX22zoJRWa0FN5:8KDwZ4Z1nDoww5XFn_9RafNWr2A=:eyJlbmRVc2VyIjoieSIsInNjb3BlIjoiMToyIiwiZGVhZGxpbmUiOjEyMzQ1NzE0OTB9';
68+
$exp = 'abcdefghklmnopq:GracWhW1iGwVL6haVH5dr4gjqeo=:eyJlbmRVc2VyIjoieSIsInNjb3BlIjoiMToyIiwiZGVhZGxpbmUiOjIyMzQ1NzE0OTB9';
6569
// @codingStandardsIgnoreEnd
6670
$this->assertEquals($exp, $token);
6771
unset($_SERVER['override_qiniu_auth_time']);
6872
}
6973

70-
public function testVerifyCallback()
71-
{
72-
}
7374
}
7475
}

tests/Qiniu/Tests/Base64Test.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
namespace Qiniu\Tests;
33

44
use Qiniu;
5+
use PHPUnit\Framework\TestCase;
56

6-
class Base64Test extends \PHPUnit_Framework_TestCase
7+
class Base64Test extends TestCase
78
{
89
public function testUrlSafe()
910
{

tests/Qiniu/Tests/BucketTest.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,17 @@
22
namespace Qiniu\Tests;
33

44
use Qiniu\Storage\BucketManager;
5+
use PHPUnit\Framework\TestCase;
56

6-
class BucketTest extends \PHPUnit_Framework_TestCase
7+
class BucketTest extends TestCase
78
{
89
protected $bucketManager;
910
protected $dummyBucketManager;
1011
protected $bucketName;
1112
protected $key;
1213
protected $key2;
1314

14-
protected function setUp()
15+
protected function setUp(): void
1516
{
1617
global $bucketName;
1718
global $key;

tests/Qiniu/Tests/CdnManagerTest.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,15 @@
1010

1111
use Qiniu\Cdn\CdnManager;
1212
use Qiniu\Http\Client;
13+
use PHPUnit\Framework\TestCase;
1314

14-
class CdnManagerTest extends \PHPUnit_Framework_TestCase
15+
class CdnManagerTest extends TestCase
1516
{
1617
protected $cdnManager;
1718
protected $encryptKey;
1819
protected $imgUrl;
1920

20-
protected function setUp()
21+
protected function setUp(): void
2122
{
2223
global $timestampAntiLeechEncryptKey;
2324
global $customDomain;

tests/Qiniu/Tests/Crc32Test.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
namespace Qiniu\Tests;
33

44
use Qiniu;
5+
use PHPUnit\Framework\TestCase;
56

6-
class Crc32Test extends \PHPUnit_Framework_TestCase
7+
class Crc32Test extends TestCase
78
{
89
public function testData()
910
{

tests/Qiniu/Tests/DownloadTest.php

+4-3
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22
namespace Qiniu\Tests;
33

44
use Qiniu\Http\Client;
5+
use PHPUnit\Framework\TestCase;
56

6-
class DownloadTest extends \PHPUnit_Framework_TestCase
7+
class DownloadTest extends TestCase
78
{
89
public function test()
910
{
1011
global $testAuth;
11-
$base_url = 'http://private-res.qiniudn.com/gogopher.jpg';
12+
$base_url = 'http://pojiwyou0.bkt.clouddn.com/demo.png';
1213
$private_url = $testAuth->privateDownloadUrl($base_url);
1314
$response = Client::get($private_url);
1415
$this->assertEquals(200, $response->statusCode);
@@ -17,7 +18,7 @@ public function test()
1718
public function testFop()
1819
{
1920
global $testAuth;
20-
$base_url = 'http://private-res.qiniudn.com/gogopher.jpg?exif';
21+
$base_url = 'http://pojiwyou0.bkt.clouddn.com/demo.png?imageInfo';
2122
$private_url = $testAuth->privateDownloadUrl($base_url);
2223
$response = Client::get($private_url);
2324
$this->assertEquals(200, $response->statusCode);

tests/Qiniu/Tests/EtagTest.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
namespace Qiniu\Tests;
33

44
use Qiniu\Etag;
5+
use PHPUnit\Framework\TestCase;
56

6-
class EtagTest extends \PHPUnit_Framework_TestCase
7+
class EtagTest extends TestCase
78
{
89
public function test0M()
910
{

tests/Qiniu/Tests/FopTest.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33

44
use Qiniu\Processing\Operation;
55
use Qiniu\Processing\PersistentFop;
6+
use PHPUnit\Framework\TestCase;
67

7-
class FopTest extends \PHPUnit_Framework_TestCase
8+
class FopTest extends TestCase
89
{
910
public function testExifPub()
1011
{

0 commit comments

Comments
 (0)