@@ -7,138 +7,138 @@ discard block |
||
7 | 7 | require_once "PUnit.php"; |
8 | 8 | require_once "../lib/RequestCore.class.php"; |
9 | 9 | class SDKTest extends PUnit{ |
10 | - protected $bucket = "php-sdk-test"; |
|
11 | - protected $key = "test==中/文?"; |
|
12 | - protected $key_copy = "test中/文_copy?"; |
|
13 | - protected $accesskey = ""; |
|
14 | - protected $secrectkey = ""; |
|
15 | - protected $client; |
|
10 | + protected $bucket = "php-sdk-test"; |
|
11 | + protected $key = "test==中/文?"; |
|
12 | + protected $key_copy = "test中/文_copy?"; |
|
13 | + protected $accesskey = ""; |
|
14 | + protected $secrectkey = ""; |
|
15 | + protected $client; |
|
16 | 16 | protected $encryptionClient; |
17 | - protected $cachedir; |
|
17 | + protected $cachedir; |
|
18 | 18 | protected $sseckey; |
19 | - public function __construct(){ |
|
20 | - $this->client=new Ks3Client($this->accesskey,$this->secrectkey); |
|
21 | - $this->cachedir=KS3_API_PATH.DIRECTORY_SEPARATOR."unit".DIRECTORY_SEPARATOR."cache".DIRECTORY_SEPARATOR; |
|
19 | + public function __construct(){ |
|
20 | + $this->client=new Ks3Client($this->accesskey,$this->secrectkey); |
|
21 | + $this->cachedir=KS3_API_PATH.DIRECTORY_SEPARATOR."unit".DIRECTORY_SEPARATOR."cache".DIRECTORY_SEPARATOR; |
|
22 | 22 | $filename = "secret.key"; |
23 | 23 | $handle = fopen($filename, "r"); |
24 | 24 | $sseckey = fread($handle, filesize ($filename)); |
25 | 25 | fclose($handle); |
26 | 26 | $this->sseckey = $sseckey; |
27 | 27 | $this->encryptionClient = new Ks3EncryptionClient($this->accesskey,$this->secrectkey,$sseckey); |
28 | - } |
|
29 | - public function before(){ |
|
30 | - if($this->client->bucketExists(array("Bucket"=>$this->bucket))){ |
|
31 | - $keys = array(); |
|
32 | - $objects = $this->client->listObjects(array("Bucket"=>$this->bucket)); |
|
33 | - foreach ($objects["Contents"] as $object) { |
|
34 | - array_push($keys, $object["Key"]); |
|
35 | - } |
|
36 | - $this->client->deleteObjects(array("Bucket"=>$this->bucket,"DeleteKeys"=>$keys)); |
|
37 | - }else{ |
|
38 | - $this->client->createBucket(array("Bucket"=>$this->bucket)); |
|
39 | - } |
|
40 | - } |
|
41 | - public function testListBuckets(){ |
|
42 | - $buckets = $this->client->listBuckets(); |
|
43 | - $found = FALSE; |
|
44 | - foreach ($buckets as $bucket) { |
|
45 | - if($bucket["Name"] == $this->bucket) |
|
46 | - $found = TRUE; |
|
47 | - } |
|
48 | - if(!$found) |
|
49 | - throw new Exception("list buckets expected found ".$this->bucket.",but not found"); |
|
28 | + } |
|
29 | + public function before(){ |
|
30 | + if($this->client->bucketExists(array("Bucket"=>$this->bucket))){ |
|
31 | + $keys = array(); |
|
32 | + $objects = $this->client->listObjects(array("Bucket"=>$this->bucket)); |
|
33 | + foreach ($objects["Contents"] as $object) { |
|
34 | + array_push($keys, $object["Key"]); |
|
35 | + } |
|
36 | + $this->client->deleteObjects(array("Bucket"=>$this->bucket,"DeleteKeys"=>$keys)); |
|
37 | + }else{ |
|
38 | + $this->client->createBucket(array("Bucket"=>$this->bucket)); |
|
39 | + } |
|
40 | + } |
|
41 | + public function testListBuckets(){ |
|
42 | + $buckets = $this->client->listBuckets(); |
|
43 | + $found = FALSE; |
|
44 | + foreach ($buckets as $bucket) { |
|
45 | + if($bucket["Name"] == $this->bucket) |
|
46 | + $found = TRUE; |
|
47 | + } |
|
48 | + if(!$found) |
|
49 | + throw new Exception("list buckets expected found ".$this->bucket.",but not found"); |
|
50 | 50 | |
51 | - } |
|
52 | - public function testDeleteBucket(){ |
|
53 | - $this->client->putObjectByContent(array("Bucket"=>$this->bucket,"Key"=>"test","Content"=>"")); |
|
54 | - $ex = NULL; |
|
55 | - try{ |
|
56 | - $this->client->deleteBucket(array("Bucket"=>$this->bucket)); |
|
57 | - }catch(Exception $e){ |
|
58 | - $ex = $e; |
|
59 | - } |
|
60 | - if($ex == NULL||!($ex->errorCode === "BucketNotEmpty")){ |
|
61 | - throw new Exception("delete bucket expected BucketNotEmpty but ".$ex); |
|
62 | - } |
|
63 | - } |
|
64 | - public function testBucketCORS(){ |
|
65 | - $this->client->setBucketCORS($args = array( |
|
66 | - "Bucket"=>$this->bucket, |
|
67 | - "CORS"=>array( |
|
68 | - array( |
|
69 | - "AllowedMethod"=>array("GET","PUT"), |
|
70 | - "AllowedOrigin"=>array("http://www.kingsoft.com"), |
|
71 | - "AllowedHeader"=>array("*"), |
|
72 | - "ExposeHeader"=>array("*"), |
|
73 | - "MaxAgeSeconds"=>10 |
|
74 | - ), |
|
75 | - array( |
|
76 | - "AllowedMethod"=>array("GET","PUT"), |
|
77 | - "AllowedOrigin"=>array("*"), |
|
78 | - "AllowedHeader"=>array("*"), |
|
79 | - "ExposeHeader"=>array("*"), |
|
80 | - "MaxAgeSeconds"=>10 |
|
81 | - ) |
|
82 | - ))); |
|
83 | - $cors = $this->client->getBucketCORS(array("Bucket"=>$this->bucket)); |
|
84 | - $this->assertEquals(count($cors),2,"bucket cors count "); |
|
85 | - $this->client->deleteBucketCORS(array("Bucket"=>$this->bucket)); |
|
86 | - $cors = $this->client->getBucketCORS(array("Bucket"=>$this->bucket)); |
|
87 | - $this->assertEquals(count($cors),0,"bucket cors count "); |
|
88 | - } |
|
89 | - public function testCreateBucket(){ |
|
90 | - $ex = NULL; |
|
91 | - try{ |
|
92 | - $this->client->createBucket(array("Bucket"=>$this->bucket)); |
|
93 | - }catch(Exception $e){ |
|
94 | - $ex = $e; |
|
95 | - } |
|
96 | - if($ex == NULL||!($ex->errorCode === "BucketAlreadyExists")){ |
|
97 | - throw new Exception("create bucket expected BucketAlreadyExists but ".$ex); |
|
98 | - } |
|
99 | - } |
|
100 | - public function testACL(){ |
|
101 | - $this->client->setBucketAcl(array("Bucket"=>$this->bucket,"ACL"=>"public-read")); |
|
102 | - $acl = $this->client->getBucketAcl(array("Bucket"=>$this->bucket)); |
|
103 | - $this->assertEquals($acl,"public-read","bucket acl"); |
|
104 | - } |
|
105 | - public function testBucketLogging(){ |
|
106 | - $this->client->setBucketLogging(array( |
|
107 | - "Bucket"=>$this->bucket, |
|
108 | - "BucketLogging"=>array( |
|
109 | - "Enable"=>TRUE, |
|
110 | - "TargetBucket"=>$this->bucket, |
|
111 | - "TargetPrefix"=>"X-KSS" |
|
51 | + } |
|
52 | + public function testDeleteBucket(){ |
|
53 | + $this->client->putObjectByContent(array("Bucket"=>$this->bucket,"Key"=>"test","Content"=>"")); |
|
54 | + $ex = NULL; |
|
55 | + try{ |
|
56 | + $this->client->deleteBucket(array("Bucket"=>$this->bucket)); |
|
57 | + }catch(Exception $e){ |
|
58 | + $ex = $e; |
|
59 | + } |
|
60 | + if($ex == NULL||!($ex->errorCode === "BucketNotEmpty")){ |
|
61 | + throw new Exception("delete bucket expected BucketNotEmpty but ".$ex); |
|
62 | + } |
|
63 | + } |
|
64 | + public function testBucketCORS(){ |
|
65 | + $this->client->setBucketCORS($args = array( |
|
66 | + "Bucket"=>$this->bucket, |
|
67 | + "CORS"=>array( |
|
68 | + array( |
|
69 | + "AllowedMethod"=>array("GET","PUT"), |
|
70 | + "AllowedOrigin"=>array("http://www.kingsoft.com"), |
|
71 | + "AllowedHeader"=>array("*"), |
|
72 | + "ExposeHeader"=>array("*"), |
|
73 | + "MaxAgeSeconds"=>10 |
|
74 | + ), |
|
75 | + array( |
|
76 | + "AllowedMethod"=>array("GET","PUT"), |
|
77 | + "AllowedOrigin"=>array("*"), |
|
78 | + "AllowedHeader"=>array("*"), |
|
79 | + "ExposeHeader"=>array("*"), |
|
80 | + "MaxAgeSeconds"=>10 |
|
81 | + ) |
|
82 | + ))); |
|
83 | + $cors = $this->client->getBucketCORS(array("Bucket"=>$this->bucket)); |
|
84 | + $this->assertEquals(count($cors),2,"bucket cors count "); |
|
85 | + $this->client->deleteBucketCORS(array("Bucket"=>$this->bucket)); |
|
86 | + $cors = $this->client->getBucketCORS(array("Bucket"=>$this->bucket)); |
|
87 | + $this->assertEquals(count($cors),0,"bucket cors count "); |
|
88 | + } |
|
89 | + public function testCreateBucket(){ |
|
90 | + $ex = NULL; |
|
91 | + try{ |
|
92 | + $this->client->createBucket(array("Bucket"=>$this->bucket)); |
|
93 | + }catch(Exception $e){ |
|
94 | + $ex = $e; |
|
95 | + } |
|
96 | + if($ex == NULL||!($ex->errorCode === "BucketAlreadyExists")){ |
|
97 | + throw new Exception("create bucket expected BucketAlreadyExists but ".$ex); |
|
98 | + } |
|
99 | + } |
|
100 | + public function testACL(){ |
|
101 | + $this->client->setBucketAcl(array("Bucket"=>$this->bucket,"ACL"=>"public-read")); |
|
102 | + $acl = $this->client->getBucketAcl(array("Bucket"=>$this->bucket)); |
|
103 | + $this->assertEquals($acl,"public-read","bucket acl"); |
|
104 | + } |
|
105 | + public function testBucketLogging(){ |
|
106 | + $this->client->setBucketLogging(array( |
|
107 | + "Bucket"=>$this->bucket, |
|
108 | + "BucketLogging"=>array( |
|
109 | + "Enable"=>TRUE, |
|
110 | + "TargetBucket"=>$this->bucket, |
|
111 | + "TargetPrefix"=>"X-KSS" |
|
112 | 112 | ) |
113 | 113 | )); |
114 | - $logging = $this->client->getBucketLogging(array("Bucket"=>$this->bucket)); |
|
115 | - $this->assertEquals($logging["Enable"],TRUE,"bucket logging enable"); |
|
114 | + $logging = $this->client->getBucketLogging(array("Bucket"=>$this->bucket)); |
|
115 | + $this->assertEquals($logging["Enable"],TRUE,"bucket logging enable"); |
|
116 | 116 | |
117 | - $this->client->setBucketLogging(array( |
|
118 | - "Bucket"=>$this->bucket, |
|
119 | - "BucketLogging"=>array( |
|
120 | - "Enable"=>FALSE,//是否开启 |
|
121 | - ) |
|
122 | - )); |
|
123 | - $logging = $this->client->getBucketLogging(array("Bucket"=>$this->bucket)); |
|
124 | - $this->assertEquals($logging["Enable"],FALSE,"bucket logging enable"); |
|
125 | - } |
|
126 | - public function testBucketLocation(){ |
|
127 | - $location = $this->client->getBucketLocation(array("Bucket"=>$this->bucket)); |
|
128 | - $this->assertEquals($location,"HANGZHOU","bucket location "); |
|
129 | - } |
|
130 | - public function testPutObjectByContentAndGetObjectContent(){ |
|
131 | - $args = array( |
|
132 | - "Bucket"=>$this->bucket, |
|
133 | - "Key"=>$this->key, |
|
134 | - "Content"=>"1234",//要上传的内容 |
|
135 | - "ACL"=>"public-read",//可以设置访问权限,合法值,private、public-read |
|
136 | - "ObjectMeta"=>array( |
|
137 | - "Content-Type"=>"application/xml", |
|
138 | - "Content-Length"=>3 |
|
117 | + $this->client->setBucketLogging(array( |
|
118 | + "Bucket"=>$this->bucket, |
|
119 | + "BucketLogging"=>array( |
|
120 | + "Enable"=>FALSE,//是否开启 |
|
121 | + ) |
|
122 | + )); |
|
123 | + $logging = $this->client->getBucketLogging(array("Bucket"=>$this->bucket)); |
|
124 | + $this->assertEquals($logging["Enable"],FALSE,"bucket logging enable"); |
|
125 | + } |
|
126 | + public function testBucketLocation(){ |
|
127 | + $location = $this->client->getBucketLocation(array("Bucket"=>$this->bucket)); |
|
128 | + $this->assertEquals($location,"HANGZHOU","bucket location "); |
|
129 | + } |
|
130 | + public function testPutObjectByContentAndGetObjectContent(){ |
|
131 | + $args = array( |
|
132 | + "Bucket"=>$this->bucket, |
|
133 | + "Key"=>$this->key, |
|
134 | + "Content"=>"1234",//要上传的内容 |
|
135 | + "ACL"=>"public-read",//可以设置访问权限,合法值,private、public-read |
|
136 | + "ObjectMeta"=>array( |
|
137 | + "Content-Type"=>"application/xml", |
|
138 | + "Content-Length"=>3 |
|
139 | 139 | ), |
140 | - "UserMeta"=>array(//可以设置object的用户元数据,需要以x-kss-meta-开头 |
|
141 | - "x-kss-meta-test"=>"test" |
|
140 | + "UserMeta"=>array(//可以设置object的用户元数据,需要以x-kss-meta-开头 |
|
141 | + "x-kss-meta-test"=>"test" |
|
142 | 142 | ) |
143 | 143 | ); |
144 | 144 | $this->client->putObjectByContent($args); |
@@ -156,21 +156,21 @@ discard block |
||
156 | 156 | $this->assertEquals($meta["ObjectMeta"]["Content-Type"],"application/xml","Content-Type"); |
157 | 157 | $this->assertEquals($meta["ObjectMeta"]["Content-Length"],3,"Content-Length"); |
158 | 158 | |
159 | - } |
|
160 | - public function testPutObjectByFile(){ |
|
161 | - $args = array( |
|
162 | - "Bucket"=>$this->bucket, |
|
163 | - "Key"=>$this->key, |
|
164 | - "Content"=>array( |
|
165 | - "content"=>$this->cachedir."test_file" |
|
166 | - ),//要上传的内容 |
|
167 | - "ACL"=>"public-read",//可以设置访问权限,合法值,private、public-read |
|
168 | - "ObjectMeta"=>array( |
|
169 | - "Content-Type"=>"application/xml", |
|
170 | - "Content-Length"=>100 |
|
159 | + } |
|
160 | + public function testPutObjectByFile(){ |
|
161 | + $args = array( |
|
162 | + "Bucket"=>$this->bucket, |
|
163 | + "Key"=>$this->key, |
|
164 | + "Content"=>array( |
|
165 | + "content"=>$this->cachedir."test_file" |
|
166 | + ),//要上传的内容 |
|
167 | + "ACL"=>"public-read",//可以设置访问权限,合法值,private、public-read |
|
168 | + "ObjectMeta"=>array( |
|
169 | + "Content-Type"=>"application/xml", |
|
170 | + "Content-Length"=>100 |
|
171 | 171 | ), |
172 | - "UserMeta"=>array(//可以设置object的用户元数据,需要以x-kss-meta-开头 |
|
173 | - "x-kss-meta-test"=>"test" |
|
172 | + "UserMeta"=>array(//可以设置object的用户元数据,需要以x-kss-meta-开头 |
|
173 | + "x-kss-meta-test"=>"test" |
|
174 | 174 | ) |
175 | 175 | ); |
176 | 176 | $this->client->putObjectByFile($args); |
@@ -180,47 +180,47 @@ discard block |
||
180 | 180 | $this->assertEquals($meta["ObjectMeta"]["Content-Type"],"application/xml","Content-Type"); |
181 | 181 | $this->assertEquals($meta["ObjectMeta"]["Content-Length"],100,"Content-Length"); |
182 | 182 | $this->assertEquals($this->client->getObjectAcl(array("Bucket"=>$this->bucket,"Key"=>$this->key)),"public-read","object acl "); |
183 | - } |
|
184 | - public function testObjectAcl(){ |
|
185 | - $this->client->putObjectByContent(array("Bucket"=>$this->bucket,"Key"=>$this->key, |
|
183 | + } |
|
184 | + public function testObjectAcl(){ |
|
185 | + $this->client->putObjectByContent(array("Bucket"=>$this->bucket,"Key"=>$this->key, |
|
186 | 186 | "Content"=>"1234","ACL"=>"private")); |
187 | - $this->assertEquals($this->client->getObjectAcl(array("Bucket"=>$this->bucket,"Key"=>$this->key)),"private","object acl"); |
|
188 | - $this->client->setObjectAcl(array("Bucket"=>$this->bucket,"Key"=>$this->key,"ACL"=>"public-read")); |
|
189 | - $this->assertEquals($this->client->getObjectAcl(array("Bucket"=>$this->bucket,"Key"=>$this->key)),"public-read","object acl"); |
|
190 | - } |
|
191 | - public function testDeleteObject(){ |
|
192 | - $this->client->putObjectByContent(array("Bucket"=>$this->bucket,"Key"=>$this->key, |
|
187 | + $this->assertEquals($this->client->getObjectAcl(array("Bucket"=>$this->bucket,"Key"=>$this->key)),"private","object acl"); |
|
188 | + $this->client->setObjectAcl(array("Bucket"=>$this->bucket,"Key"=>$this->key,"ACL"=>"public-read")); |
|
189 | + $this->assertEquals($this->client->getObjectAcl(array("Bucket"=>$this->bucket,"Key"=>$this->key)),"public-read","object acl"); |
|
190 | + } |
|
191 | + public function testDeleteObject(){ |
|
192 | + $this->client->putObjectByContent(array("Bucket"=>$this->bucket,"Key"=>$this->key, |
|
193 | 193 | "Content"=>"1234")); |
194 | - $this->client->deleteObject(array("Bucket"=>$this->bucket,"Key"=>$this->key)); |
|
195 | - $this->assertEquals($this->client->objectExists(array("Bucket"=>$this->bucket,"Key"=>$this->key)),FALSE,"object exits"); |
|
196 | - } |
|
197 | - public function testDeleteObjects(){ |
|
198 | - $this->client->putObjectByContent(array("Bucket"=>$this->bucket,"Key"=>$this->key, |
|
194 | + $this->client->deleteObject(array("Bucket"=>$this->bucket,"Key"=>$this->key)); |
|
195 | + $this->assertEquals($this->client->objectExists(array("Bucket"=>$this->bucket,"Key"=>$this->key)),FALSE,"object exits"); |
|
196 | + } |
|
197 | + public function testDeleteObjects(){ |
|
198 | + $this->client->putObjectByContent(array("Bucket"=>$this->bucket,"Key"=>$this->key, |
|
199 | 199 | "Content"=>"1234")); |
200 | - $this->client->deleteObjects(array("Bucket"=>$this->bucket,"DeleteKeys"=>array($this->key))); |
|
201 | - $this->assertEquals($this->client->objectExists(array("Bucket"=>$this->bucket,"Key"=>$this->key)),FALSE,"object exits"); |
|
202 | - } |
|
203 | - public function testCopyObject(){ |
|
204 | - $this->client->putObjectByContent(array("Bucket"=>$this->bucket,"Key"=>$this->key, |
|
200 | + $this->client->deleteObjects(array("Bucket"=>$this->bucket,"DeleteKeys"=>array($this->key))); |
|
201 | + $this->assertEquals($this->client->objectExists(array("Bucket"=>$this->bucket,"Key"=>$this->key)),FALSE,"object exits"); |
|
202 | + } |
|
203 | + public function testCopyObject(){ |
|
204 | + $this->client->putObjectByContent(array("Bucket"=>$this->bucket,"Key"=>$this->key, |
|
205 | 205 | "Content"=>"1234")); |
206 | - $this->client->copyObject(array("Bucket"=>$this->bucket,"Key"=>$this->key_copy,"CopySource"=>array("Bucket"=>$this->bucket,"Key"=>$this->key))); |
|
207 | - $this->assertEquals($this->client->objectExists(array("Bucket"=>$this->bucket,"Key"=>$this->key)),TRUE,"object exits"); |
|
208 | - $this->assertEquals($this->client->objectExists(array("Bucket"=>$this->bucket,"Key"=>$this->key_copy)),TRUE |
|
209 | - ,"object exits"); |
|
210 | - } |
|
211 | - public function testPutAndGetObject(){ |
|
212 | - $args = array( |
|
213 | - "Bucket"=>$this->bucket, |
|
214 | - "Key"=>$this->key, |
|
215 | - "Content"=>array( |
|
216 | - "content"=>$this->cachedir."test_file" |
|
217 | - ),//要上传的内容 |
|
218 | - "ACL"=>"public-read",//可以设置访问权限,合法值,private、public-read |
|
219 | - "ObjectMeta"=>array( |
|
220 | - "Content-Type"=>"application/xml", |
|
206 | + $this->client->copyObject(array("Bucket"=>$this->bucket,"Key"=>$this->key_copy,"CopySource"=>array("Bucket"=>$this->bucket,"Key"=>$this->key))); |
|
207 | + $this->assertEquals($this->client->objectExists(array("Bucket"=>$this->bucket,"Key"=>$this->key)),TRUE,"object exits"); |
|
208 | + $this->assertEquals($this->client->objectExists(array("Bucket"=>$this->bucket,"Key"=>$this->key_copy)),TRUE |
|
209 | + ,"object exits"); |
|
210 | + } |
|
211 | + public function testPutAndGetObject(){ |
|
212 | + $args = array( |
|
213 | + "Bucket"=>$this->bucket, |
|
214 | + "Key"=>$this->key, |
|
215 | + "Content"=>array( |
|
216 | + "content"=>$this->cachedir."test_file" |
|
217 | + ),//要上传的内容 |
|
218 | + "ACL"=>"public-read",//可以设置访问权限,合法值,private、public-read |
|
219 | + "ObjectMeta"=>array( |
|
220 | + "Content-Type"=>"application/xml", |
|
221 | 221 | ), |
222 | - "UserMeta"=>array(//可以设置object的用户元数据,需要以x-kss-meta-开头 |
|
223 | - "x-kss-meta-test"=>"test" |
|
222 | + "UserMeta"=>array(//可以设置object的用户元数据,需要以x-kss-meta-开头 |
|
223 | + "x-kss-meta-test"=>"test" |
|
224 | 224 | ) |
225 | 225 | ); |
226 | 226 | $this->client->putObjectByFile($args); |
@@ -229,49 +229,49 @@ discard block |
||
229 | 229 | $md5pre = md5_file($this->cachedir."test_file"); |
230 | 230 | @unlink($this->cachedir."down"); |
231 | 231 | $this->assertEquals($md5,$md5pre,"contentmd5"); |
232 | - } |
|
233 | - public function testPutAndGetObjectRanges(){ |
|
234 | - $args = array( |
|
235 | - "Bucket"=>$this->bucket, |
|
236 | - "Key"=>$this->key, |
|
237 | - "Content"=>array( |
|
238 | - "content"=>$this->cachedir."test_file" |
|
239 | - ),//要上传的内容 |
|
240 | - "ACL"=>"public-read",//可以设置访问权限,合法值,private、public-read |
|
241 | - "ObjectMeta"=>array( |
|
242 | - "Content-Type"=>"application/xml", |
|
232 | + } |
|
233 | + public function testPutAndGetObjectRanges(){ |
|
234 | + $args = array( |
|
235 | + "Bucket"=>$this->bucket, |
|
236 | + "Key"=>$this->key, |
|
237 | + "Content"=>array( |
|
238 | + "content"=>$this->cachedir."test_file" |
|
239 | + ),//要上传的内容 |
|
240 | + "ACL"=>"public-read",//可以设置访问权限,合法值,private、public-read |
|
241 | + "ObjectMeta"=>array( |
|
242 | + "Content-Type"=>"application/xml", |
|
243 | 243 | ), |
244 | - "UserMeta"=>array(//可以设置object的用户元数据,需要以x-kss-meta-开头 |
|
245 | - "x-kss-meta-test"=>"test" |
|
244 | + "UserMeta"=>array(//可以设置object的用户元数据,需要以x-kss-meta-开头 |
|
245 | + "x-kss-meta-test"=>"test" |
|
246 | 246 | ) |
247 | 247 | ); |
248 | 248 | $this->client->putObjectByFile($args); |
249 | 249 | rangeGetAndCheckMd5($this->client,$this->bucket,$this->key,$this->cachedir."down",md5_file($this->cachedir."test_file")); |
250 | - } |
|
251 | - public function testInitAndAbortMultipart(){ |
|
252 | - $initResult = $this->client->initMultipartUpload(array("Bucket"=>$this->bucket,"Key"=>$this->key)); |
|
253 | - $uid = $initResult["UploadId"]; |
|
254 | - $listParts = $this->client->listParts(array("Bucket"=>$this->bucket,"Key"=>$this->key,"Options"=>array("uploadId"=>$uid))); |
|
255 | - $this->client->abortMultipartUpload(array("Bucket"=>$this->bucket,"Key"=>$this->key,"Options"=>array("uploadId"=>$uid))); |
|
256 | - $ex = NULL; |
|
257 | - try{ |
|
258 | - $this->client->listParts(array("Bucket"=>$this->bucket,"Key"=>$this->key,"Options"=>array("uploadId"=>$uid))); |
|
259 | - }catch(Exception $e){ |
|
260 | - $ex = $e; |
|
261 | - } |
|
262 | - if($ex == NULL||!($ex->errorCode === "NoSuchUpload")){ |
|
263 | - throw new Exception("create bucket expected NoSuchUpload but ".$ex); |
|
264 | - } |
|
265 | - } |
|
266 | - public function testMultipartUpload(){ |
|
267 | - generateFile(1024*1024,$this->cachedir."multi"); |
|
268 | - //初始化分开上传,获取uploadid |
|
250 | + } |
|
251 | + public function testInitAndAbortMultipart(){ |
|
252 | + $initResult = $this->client->initMultipartUpload(array("Bucket"=>$this->bucket,"Key"=>$this->key)); |
|
253 | + $uid = $initResult["UploadId"]; |
|
254 | + $listParts = $this->client->listParts(array("Bucket"=>$this->bucket,"Key"=>$this->key,"Options"=>array("uploadId"=>$uid))); |
|
255 | + $this->client->abortMultipartUpload(array("Bucket"=>$this->bucket,"Key"=>$this->key,"Options"=>array("uploadId"=>$uid))); |
|
256 | + $ex = NULL; |
|
257 | + try{ |
|
258 | + $this->client->listParts(array("Bucket"=>$this->bucket,"Key"=>$this->key,"Options"=>array("uploadId"=>$uid))); |
|
259 | + }catch(Exception $e){ |
|
260 | + $ex = $e; |
|
261 | + } |
|
262 | + if($ex == NULL||!($ex->errorCode === "NoSuchUpload")){ |
|
263 | + throw new Exception("create bucket expected NoSuchUpload but ".$ex); |
|
264 | + } |
|
265 | + } |
|
266 | + public function testMultipartUpload(){ |
|
267 | + generateFile(1024*1024,$this->cachedir."multi"); |
|
268 | + //初始化分开上传,获取uploadid |
|
269 | 269 | $args = array( |
270 | 270 | "Bucket"=>$this->bucket, |
271 | 271 | "Key"=>$this->key, |
272 | 272 | "ACL"=>"public-read", |
273 | 273 | "UserMeta"=>array( |
274 | - "x-kss-meta-test"=>"example" |
|
274 | + "x-kss-meta-test"=>"example" |
|
275 | 275 | ), |
276 | 276 | "ObjectMeta"=>array( |
277 | 277 | "Content-Type"=>"application/xml" |
@@ -323,21 +323,21 @@ discard block |
||
323 | 323 | $this->assertEquals($meta["UserMeta"]["x-kss-meta-test"],"example","x-kss-meta-test"); |
324 | 324 | rangeGetAndCheckMd5($this->client,$this->bucket,$this->key,$this->cachedir."down",md5_file($this->cachedir."multi")); |
325 | 325 | @unlink($this->cachedir."multi"); |
326 | - } |
|
327 | - public function testListBucketsPresignedUrl(){ |
|
328 | - $url = $this->client->generatePresignedUrl( |
|
329 | - array( |
|
330 | - "Method"=>"GET", |
|
331 | - "Options"=>array("Expires"=>60*10), |
|
332 | - "Headers"=>array("Content-Type"=>"text/plain") |
|
333 | - )); |
|
334 | - $httpRequest = new RequestCore($url); |
|
335 | - $httpRequest->set_method("GET"); |
|
326 | + } |
|
327 | + public function testListBucketsPresignedUrl(){ |
|
328 | + $url = $this->client->generatePresignedUrl( |
|
329 | + array( |
|
330 | + "Method"=>"GET", |
|
331 | + "Options"=>array("Expires"=>60*10), |
|
332 | + "Headers"=>array("Content-Type"=>"text/plain") |
|
333 | + )); |
|
334 | + $httpRequest = new RequestCore($url); |
|
335 | + $httpRequest->set_method("GET"); |
|
336 | 336 | $httpRequest->add_header("Content-Type","text/plain"); |
337 | - $httpRequest->send_request(); |
|
338 | - $body = $httpRequest->get_response_body (); |
|
339 | - $this->assertEquals($httpRequest->get_response_code()." body:".$body,200,"list buckets status code"); |
|
340 | - } |
|
337 | + $httpRequest->send_request(); |
|
338 | + $body = $httpRequest->get_response_body (); |
|
339 | + $this->assertEquals($httpRequest->get_response_code()." body:".$body,200,"list buckets status code"); |
|
340 | + } |
|
341 | 341 | public function testHeadBucketPresignedUrl(){ |
342 | 342 | $url = $this->client->generatePresignedUrl( |
343 | 343 | array( |
@@ -618,16 +618,16 @@ discard block |
||
618 | 618 | "Bucket"=>$this->bucket, |
619 | 619 | "Key"=>$this->key, |
620 | 620 | "Content"=>"12345",//要上传的内容 |
621 | - "ACL"=>"public-read",//可以设置访问权限,合法值,private、public-read |
|
622 | - "ObjectMeta"=>array(//设置object的元数据,可以设置"Cache-Control","Content-Disposition","Content-Encoding","Content-Length","Content-MD5","Content-Type","Expires"。当设置了Content-Length时,请勿大于实际长度,如果小于实际长度,将只上传部分内容。 |
|
621 | + "ACL"=>"public-read",//可以设置访问权限,合法值,private、public-read |
|
622 | + "ObjectMeta"=>array(//设置object的元数据,可以设置"Cache-Control","Content-Disposition","Content-Encoding","Content-Length","Content-MD5","Content-Type","Expires"。当设置了Content-Length时,请勿大于实际长度,如果小于实际长度,将只上传部分内容。 |
|
623 | 623 | "Content-Type"=>"binay/ocet-stream" |
624 | 624 | ), |
625 | 625 | "UserMeta"=>array(//可以设置object的用户元数据,需要以x-kss-meta-开头 |
626 | - "x-kss-meta-test"=>"test" |
|
626 | + "x-kss-meta-test"=>"test" |
|
627 | 627 | ), |
628 | 628 | "SSE"=>array( |
629 | 629 | "Algm"=>"AES256"//暂时支持AES256 |
630 | - ) |
|
630 | + ) |
|
631 | 631 | ); |
632 | 632 | $result = $this->client->putObjectByContent($args); |
633 | 633 | $this->assertEquals($result["SSEAlgm"],"AES256"); |
@@ -645,16 +645,16 @@ discard block |
||
645 | 645 | "Bucket"=>$this->bucket, |
646 | 646 | "Key"=>$this->key, |
647 | 647 | "Content"=>"12345",//要上传的内容 |
648 | - "ACL"=>"public-read",//可以设置访问权限,合法值,private、public-read |
|
649 | - "ObjectMeta"=>array(//设置object的元数据,可以设置"Cache-Control","Content-Disposition","Content-Encoding","Content-Length","Content-MD5","Content-Type","Expires"。当设置了Content-Length时,请勿大于实际长度,如果小于实际长度,将只上传部分内容。 |
|
648 | + "ACL"=>"public-read",//可以设置访问权限,合法值,private、public-read |
|
649 | + "ObjectMeta"=>array(//设置object的元数据,可以设置"Cache-Control","Content-Disposition","Content-Encoding","Content-Length","Content-MD5","Content-Type","Expires"。当设置了Content-Length时,请勿大于实际长度,如果小于实际长度,将只上传部分内容。 |
|
650 | 650 | "Content-Type"=>"binay/ocet-stream" |
651 | 651 | ), |
652 | 652 | "UserMeta"=>array(//可以设置object的用户元数据,需要以x-kss-meta-开头 |
653 | - "x-kss-meta-test"=>"test" |
|
653 | + "x-kss-meta-test"=>"test" |
|
654 | 654 | ), |
655 | 655 | "SSEC"=>array( |
656 | 656 | "Key"=>$this->sseckey |
657 | - ) |
|
657 | + ) |
|
658 | 658 | ); |
659 | 659 | $result = $this->client->putObjectByContent($args); |
660 | 660 | $this->assertEquals($result["SSECAlgm"],"AES256"); |
@@ -665,7 +665,7 @@ discard block |
||
665 | 665 | "Key"=>$this->key, |
666 | 666 | "SSEC"=>array( |
667 | 667 | "Key"=>$this->sseckey |
668 | - ) |
|
668 | + ) |
|
669 | 669 | ); |
670 | 670 | $result = $this->client->getObjectMeta($args); |
671 | 671 | $this->assertEquals($result["ObjectMeta"]["SSECAlgm"],"AES256"); |
@@ -677,7 +677,7 @@ discard block |
||
677 | 677 | "WriteTo"=>$this->cachedir."down", //文件保存路径,必须提供。可以是resource |
678 | 678 | "SSEC"=>array( |
679 | 679 | "Key"=>$this->sseckey |
680 | - ) |
|
680 | + ) |
|
681 | 681 | ); |
682 | 682 | $this->client->getObject($args); |
683 | 683 | $this->assertEquals("12345",file_get_contents($this->cachedir."down")); |
@@ -779,16 +779,16 @@ discard block |
||
779 | 779 | "Bucket"=>$this->bucket, |
780 | 780 | "Key"=>$this->key, |
781 | 781 | "Content"=>"12345",//要上传的内容 |
782 | - "ACL"=>"public-read",//可以设置访问权限,合法值,private、public-read |
|
783 | - "ObjectMeta"=>array(//设置object的元数据,可以设置"Cache-Control","Content-Disposition","Content-Encoding","Content-Length","Content-MD5","Content-Type","Expires"。当设置了Content-Length时,请勿大于实际长度,如果小于实际长度,将只上传部分内容。 |
|
782 | + "ACL"=>"public-read",//可以设置访问权限,合法值,private、public-read |
|
783 | + "ObjectMeta"=>array(//设置object的元数据,可以设置"Cache-Control","Content-Disposition","Content-Encoding","Content-Length","Content-MD5","Content-Type","Expires"。当设置了Content-Length时,请勿大于实际长度,如果小于实际长度,将只上传部分内容。 |
|
784 | 784 | "Content-Type"=>"binay/ocet-stream" |
785 | 785 | ), |
786 | 786 | "UserMeta"=>array(//可以设置object的用户元数据,需要以x-kss-meta-开头 |
787 | - "x-kss-meta-test"=>"test" |
|
787 | + "x-kss-meta-test"=>"test" |
|
788 | 788 | ), |
789 | 789 | "SSEC"=>array( |
790 | 790 | "Key"=>$this->sseckey |
791 | - ) |
|
791 | + ) |
|
792 | 792 | ); |
793 | 793 | $result = $this->client->putObjectByContent($args); |
794 | 794 | |
@@ -799,10 +799,10 @@ discard block |
||
799 | 799 | "Bucket"=>$this->bucket, |
800 | 800 | "Key"=>$this->key |
801 | 801 | ), |
802 | - "SSECSource"=>array( |
|
802 | + "SSECSource"=>array( |
|
803 | 803 | "Key"=>$this->sseckey |
804 | 804 | ), |
805 | - "SSEC"=>array( |
|
805 | + "SSEC"=>array( |
|
806 | 806 | "Key"=>$this->sseckey |
807 | 807 | ) |
808 | 808 | ); |
@@ -821,7 +821,7 @@ discard block |
||
821 | 821 | ); |
822 | 822 | $this->encryptionClient->putObjectByContent($args); |
823 | 823 | rangeGetAndCheckMd5($this->encryptionClient,$this->bucket,$this->key, |
824 | - $this->cachedir."down",md5($args["Content"])); |
|
824 | + $this->cachedir."down",md5($args["Content"])); |
|
825 | 825 | } |
826 | 826 | } |
827 | 827 | public function testPutObjectByFileAndGetObjectUsingEncyptionMeta(){ |
@@ -835,7 +835,7 @@ discard block |
||
835 | 835 | ); |
836 | 836 | $this->encryptionClient->putObjectByFile($args); |
837 | 837 | rangeGetAndCheckMd5($this->encryptionClient,$this->bucket,$this->key, |
838 | - $this->cachedir."down",md5_file($this->cachedir."test_file")); |
|
838 | + $this->cachedir."down",md5_file($this->cachedir."test_file")); |
|
839 | 839 | } |
840 | 840 | public function testMultipartUploadUsingEncyptionMeta(){ |
841 | 841 | generateFile(1024*1024,$this->cachedir."multi"); |
@@ -1,12 +1,12 @@ discard block |
||
1 | 1 | <?php |
2 | -define("ENCRYPTPTION_STORAGE_MODE","InstructionFile"); |
|
2 | +define("ENCRYPTPTION_STORAGE_MODE", "InstructionFile"); |
|
3 | 3 | require_once "../encryption/EncryptionUtil.php"; |
4 | 4 | require_once "../Ks3Client.class.php"; |
5 | 5 | require_once "../Ks3EncryptionClient.class.php"; |
6 | 6 | require_once "TestUtil.php"; |
7 | 7 | require_once "PUnit.php"; |
8 | 8 | require_once "../lib/RequestCore.class.php"; |
9 | -class SDKTest extends PUnit{ |
|
9 | +class SDKTest extends PUnit { |
|
10 | 10 | protected $bucket = "php-sdk-test"; |
11 | 11 | protected $key = "test==中/文?"; |
12 | 12 | protected $key_copy = "test中/文_copy?"; |
@@ -16,64 +16,64 @@ discard block |
||
16 | 16 | protected $encryptionClient; |
17 | 17 | protected $cachedir; |
18 | 18 | protected $sseckey; |
19 | - public function __construct(){ |
|
20 | - $this->client=new Ks3Client($this->accesskey,$this->secrectkey); |
|
21 | - $this->cachedir=KS3_API_PATH.DIRECTORY_SEPARATOR."unit".DIRECTORY_SEPARATOR."cache".DIRECTORY_SEPARATOR; |
|
19 | + public function __construct() { |
|
20 | + $this->client = new Ks3Client($this->accesskey, $this->secrectkey); |
|
21 | + $this->cachedir = KS3_API_PATH.DIRECTORY_SEPARATOR."unit".DIRECTORY_SEPARATOR."cache".DIRECTORY_SEPARATOR; |
|
22 | 22 | $filename = "secret.key"; |
23 | 23 | $handle = fopen($filename, "r"); |
24 | - $sseckey = fread($handle, filesize ($filename)); |
|
24 | + $sseckey = fread($handle, filesize($filename)); |
|
25 | 25 | fclose($handle); |
26 | 26 | $this->sseckey = $sseckey; |
27 | - $this->encryptionClient = new Ks3EncryptionClient($this->accesskey,$this->secrectkey,$sseckey); |
|
27 | + $this->encryptionClient = new Ks3EncryptionClient($this->accesskey, $this->secrectkey, $sseckey); |
|
28 | 28 | } |
29 | - public function before(){ |
|
30 | - if($this->client->bucketExists(array("Bucket"=>$this->bucket))){ |
|
29 | + public function before() { |
|
30 | + if ($this->client->bucketExists(array("Bucket"=>$this->bucket))) { |
|
31 | 31 | $keys = array(); |
32 | 32 | $objects = $this->client->listObjects(array("Bucket"=>$this->bucket)); |
33 | 33 | foreach ($objects["Contents"] as $object) { |
34 | 34 | array_push($keys, $object["Key"]); |
35 | 35 | } |
36 | - $this->client->deleteObjects(array("Bucket"=>$this->bucket,"DeleteKeys"=>$keys)); |
|
37 | - }else{ |
|
36 | + $this->client->deleteObjects(array("Bucket"=>$this->bucket, "DeleteKeys"=>$keys)); |
|
37 | + }else { |
|
38 | 38 | $this->client->createBucket(array("Bucket"=>$this->bucket)); |
39 | 39 | } |
40 | 40 | } |
41 | - public function testListBuckets(){ |
|
41 | + public function testListBuckets() { |
|
42 | 42 | $buckets = $this->client->listBuckets(); |
43 | 43 | $found = FALSE; |
44 | 44 | foreach ($buckets as $bucket) { |
45 | - if($bucket["Name"] == $this->bucket) |
|
45 | + if ($bucket["Name"] == $this->bucket) |
|
46 | 46 | $found = TRUE; |
47 | 47 | } |
48 | - if(!$found) |
|
48 | + if (!$found) |
|
49 | 49 | throw new Exception("list buckets expected found ".$this->bucket.",but not found"); |
50 | 50 | |
51 | 51 | } |
52 | - public function testDeleteBucket(){ |
|
53 | - $this->client->putObjectByContent(array("Bucket"=>$this->bucket,"Key"=>"test","Content"=>"")); |
|
52 | + public function testDeleteBucket() { |
|
53 | + $this->client->putObjectByContent(array("Bucket"=>$this->bucket, "Key"=>"test", "Content"=>"")); |
|
54 | 54 | $ex = NULL; |
55 | - try{ |
|
55 | + try { |
|
56 | 56 | $this->client->deleteBucket(array("Bucket"=>$this->bucket)); |
57 | - }catch(Exception $e){ |
|
57 | + } catch (Exception $e) { |
|
58 | 58 | $ex = $e; |
59 | 59 | } |
60 | - if($ex == NULL||!($ex->errorCode === "BucketNotEmpty")){ |
|
60 | + if ($ex == NULL || !($ex->errorCode === "BucketNotEmpty")) { |
|
61 | 61 | throw new Exception("delete bucket expected BucketNotEmpty but ".$ex); |
62 | 62 | } |
63 | 63 | } |
64 | - public function testBucketCORS(){ |
|
64 | + public function testBucketCORS() { |
|
65 | 65 | $this->client->setBucketCORS($args = array( |
66 | 66 | "Bucket"=>$this->bucket, |
67 | 67 | "CORS"=>array( |
68 | 68 | array( |
69 | - "AllowedMethod"=>array("GET","PUT"), |
|
69 | + "AllowedMethod"=>array("GET", "PUT"), |
|
70 | 70 | "AllowedOrigin"=>array("http://www.kingsoft.com"), |
71 | 71 | "AllowedHeader"=>array("*"), |
72 | 72 | "ExposeHeader"=>array("*"), |
73 | 73 | "MaxAgeSeconds"=>10 |
74 | 74 | ), |
75 | 75 | array( |
76 | - "AllowedMethod"=>array("GET","PUT"), |
|
76 | + "AllowedMethod"=>array("GET", "PUT"), |
|
77 | 77 | "AllowedOrigin"=>array("*"), |
78 | 78 | "AllowedHeader"=>array("*"), |
79 | 79 | "ExposeHeader"=>array("*"), |
@@ -81,28 +81,28 @@ discard block |
||
81 | 81 | ) |
82 | 82 | ))); |
83 | 83 | $cors = $this->client->getBucketCORS(array("Bucket"=>$this->bucket)); |
84 | - $this->assertEquals(count($cors),2,"bucket cors count "); |
|
84 | + $this->assertEquals(count($cors), 2, "bucket cors count "); |
|
85 | 85 | $this->client->deleteBucketCORS(array("Bucket"=>$this->bucket)); |
86 | 86 | $cors = $this->client->getBucketCORS(array("Bucket"=>$this->bucket)); |
87 | - $this->assertEquals(count($cors),0,"bucket cors count "); |
|
87 | + $this->assertEquals(count($cors), 0, "bucket cors count "); |
|
88 | 88 | } |
89 | - public function testCreateBucket(){ |
|
89 | + public function testCreateBucket() { |
|
90 | 90 | $ex = NULL; |
91 | - try{ |
|
91 | + try { |
|
92 | 92 | $this->client->createBucket(array("Bucket"=>$this->bucket)); |
93 | - }catch(Exception $e){ |
|
93 | + } catch (Exception $e) { |
|
94 | 94 | $ex = $e; |
95 | 95 | } |
96 | - if($ex == NULL||!($ex->errorCode === "BucketAlreadyExists")){ |
|
96 | + if ($ex == NULL || !($ex->errorCode === "BucketAlreadyExists")) { |
|
97 | 97 | throw new Exception("create bucket expected BucketAlreadyExists but ".$ex); |
98 | 98 | } |
99 | 99 | } |
100 | - public function testACL(){ |
|
101 | - $this->client->setBucketAcl(array("Bucket"=>$this->bucket,"ACL"=>"public-read")); |
|
100 | + public function testACL() { |
|
101 | + $this->client->setBucketAcl(array("Bucket"=>$this->bucket, "ACL"=>"public-read")); |
|
102 | 102 | $acl = $this->client->getBucketAcl(array("Bucket"=>$this->bucket)); |
103 | - $this->assertEquals($acl,"public-read","bucket acl"); |
|
103 | + $this->assertEquals($acl, "public-read", "bucket acl"); |
|
104 | 104 | } |
105 | - public function testBucketLogging(){ |
|
105 | + public function testBucketLogging() { |
|
106 | 106 | $this->client->setBucketLogging(array( |
107 | 107 | "Bucket"=>$this->bucket, |
108 | 108 | "BucketLogging"=>array( |
@@ -112,27 +112,27 @@ discard block |
||
112 | 112 | ) |
113 | 113 | )); |
114 | 114 | $logging = $this->client->getBucketLogging(array("Bucket"=>$this->bucket)); |
115 | - $this->assertEquals($logging["Enable"],TRUE,"bucket logging enable"); |
|
115 | + $this->assertEquals($logging["Enable"], TRUE, "bucket logging enable"); |
|
116 | 116 | |
117 | 117 | $this->client->setBucketLogging(array( |
118 | 118 | "Bucket"=>$this->bucket, |
119 | 119 | "BucketLogging"=>array( |
120 | - "Enable"=>FALSE,//是否开启 |
|
120 | + "Enable"=>FALSE, //是否开启 |
|
121 | 121 | ) |
122 | 122 | )); |
123 | 123 | $logging = $this->client->getBucketLogging(array("Bucket"=>$this->bucket)); |
124 | - $this->assertEquals($logging["Enable"],FALSE,"bucket logging enable"); |
|
124 | + $this->assertEquals($logging["Enable"], FALSE, "bucket logging enable"); |
|
125 | 125 | } |
126 | - public function testBucketLocation(){ |
|
126 | + public function testBucketLocation() { |
|
127 | 127 | $location = $this->client->getBucketLocation(array("Bucket"=>$this->bucket)); |
128 | - $this->assertEquals($location,"HANGZHOU","bucket location "); |
|
128 | + $this->assertEquals($location, "HANGZHOU", "bucket location "); |
|
129 | 129 | } |
130 | - public function testPutObjectByContentAndGetObjectContent(){ |
|
130 | + public function testPutObjectByContentAndGetObjectContent() { |
|
131 | 131 | $args = array( |
132 | 132 | "Bucket"=>$this->bucket, |
133 | 133 | "Key"=>$this->key, |
134 | - "Content"=>"1234",//要上传的内容 |
|
135 | - "ACL"=>"public-read",//可以设置访问权限,合法值,private、public-read |
|
134 | + "Content"=>"1234", //要上传的内容 |
|
135 | + "ACL"=>"public-read", //可以设置访问权限,合法值,private、public-read |
|
136 | 136 | "ObjectMeta"=>array( |
137 | 137 | "Content-Type"=>"application/xml", |
138 | 138 | "Content-Length"=>3 |
@@ -142,29 +142,29 @@ discard block |
||
142 | 142 | ) |
143 | 143 | ); |
144 | 144 | $this->client->putObjectByContent($args); |
145 | - $this->assertEquals($this->client->objectExists(array("Bucket"=>$this->bucket,"Key"=>$this->key)),TRUE,"object exists "); |
|
146 | - $meta = $this->client->getObjectMeta(array("Bucket"=>$this->bucket,"Key"=>$this->key)); |
|
147 | - $this->assertEquals($meta["UserMeta"]["x-kss-meta-test"],"test","x-kss-meta-test"); |
|
148 | - $this->assertEquals($meta["ObjectMeta"]["Content-Type"],"application/xml","Content-Type"); |
|
149 | - $this->assertEquals($meta["ObjectMeta"]["Content-Length"],3,"Content-Length"); |
|
150 | - $this->assertEquals($this->client->getObjectAcl(array("Bucket"=>$this->bucket,"Key"=>$this->key)),"public-read","object acl "); |
|
145 | + $this->assertEquals($this->client->objectExists(array("Bucket"=>$this->bucket, "Key"=>$this->key)), TRUE, "object exists "); |
|
146 | + $meta = $this->client->getObjectMeta(array("Bucket"=>$this->bucket, "Key"=>$this->key)); |
|
147 | + $this->assertEquals($meta["UserMeta"]["x-kss-meta-test"], "test", "x-kss-meta-test"); |
|
148 | + $this->assertEquals($meta["ObjectMeta"]["Content-Type"], "application/xml", "Content-Type"); |
|
149 | + $this->assertEquals($meta["ObjectMeta"]["Content-Length"], 3, "Content-Length"); |
|
150 | + $this->assertEquals($this->client->getObjectAcl(array("Bucket"=>$this->bucket, "Key"=>$this->key)), "public-read", "object acl "); |
|
151 | 151 | |
152 | - $s3Object = $this->client->getObject(array("Bucket"=>$this->bucket,"Key"=>$this->key)); |
|
153 | - $this->assertEquals($s3Object["Content"],"123","s3 object content"); |
|
152 | + $s3Object = $this->client->getObject(array("Bucket"=>$this->bucket, "Key"=>$this->key)); |
|
153 | + $this->assertEquals($s3Object["Content"], "123", "s3 object content"); |
|
154 | 154 | $meta = $s3Object["Meta"]; |
155 | - $this->assertEquals($meta["UserMeta"]["x-kss-meta-test"],"test","x-kss-meta-test"); |
|
156 | - $this->assertEquals($meta["ObjectMeta"]["Content-Type"],"application/xml","Content-Type"); |
|
157 | - $this->assertEquals($meta["ObjectMeta"]["Content-Length"],3,"Content-Length"); |
|
155 | + $this->assertEquals($meta["UserMeta"]["x-kss-meta-test"], "test", "x-kss-meta-test"); |
|
156 | + $this->assertEquals($meta["ObjectMeta"]["Content-Type"], "application/xml", "Content-Type"); |
|
157 | + $this->assertEquals($meta["ObjectMeta"]["Content-Length"], 3, "Content-Length"); |
|
158 | 158 | |
159 | 159 | } |
160 | - public function testPutObjectByFile(){ |
|
160 | + public function testPutObjectByFile() { |
|
161 | 161 | $args = array( |
162 | 162 | "Bucket"=>$this->bucket, |
163 | 163 | "Key"=>$this->key, |
164 | 164 | "Content"=>array( |
165 | 165 | "content"=>$this->cachedir."test_file" |
166 | - ),//要上传的内容 |
|
167 | - "ACL"=>"public-read",//可以设置访问权限,合法值,private、public-read |
|
166 | + ), //要上传的内容 |
|
167 | + "ACL"=>"public-read", //可以设置访问权限,合法值,private、public-read |
|
168 | 168 | "ObjectMeta"=>array( |
169 | 169 | "Content-Type"=>"application/xml", |
170 | 170 | "Content-Length"=>100 |
@@ -174,48 +174,48 @@ discard block |
||
174 | 174 | ) |
175 | 175 | ); |
176 | 176 | $this->client->putObjectByFile($args); |
177 | - $this->assertEquals($this->client->objectExists(array("Bucket"=>$this->bucket,"Key"=>$this->key)),TRUE,"object exists "); |
|
178 | - $meta = $this->client->getObjectMeta(array("Bucket"=>$this->bucket,"Key"=>$this->key)); |
|
179 | - $this->assertEquals($meta["UserMeta"]["x-kss-meta-test"],"test","x-kss-meta-test"); |
|
180 | - $this->assertEquals($meta["ObjectMeta"]["Content-Type"],"application/xml","Content-Type"); |
|
181 | - $this->assertEquals($meta["ObjectMeta"]["Content-Length"],100,"Content-Length"); |
|
182 | - $this->assertEquals($this->client->getObjectAcl(array("Bucket"=>$this->bucket,"Key"=>$this->key)),"public-read","object acl "); |
|
177 | + $this->assertEquals($this->client->objectExists(array("Bucket"=>$this->bucket, "Key"=>$this->key)), TRUE, "object exists "); |
|
178 | + $meta = $this->client->getObjectMeta(array("Bucket"=>$this->bucket, "Key"=>$this->key)); |
|
179 | + $this->assertEquals($meta["UserMeta"]["x-kss-meta-test"], "test", "x-kss-meta-test"); |
|
180 | + $this->assertEquals($meta["ObjectMeta"]["Content-Type"], "application/xml", "Content-Type"); |
|
181 | + $this->assertEquals($meta["ObjectMeta"]["Content-Length"], 100, "Content-Length"); |
|
182 | + $this->assertEquals($this->client->getObjectAcl(array("Bucket"=>$this->bucket, "Key"=>$this->key)), "public-read", "object acl "); |
|
183 | 183 | } |
184 | - public function testObjectAcl(){ |
|
185 | - $this->client->putObjectByContent(array("Bucket"=>$this->bucket,"Key"=>$this->key, |
|
186 | -"Content"=>"1234","ACL"=>"private")); |
|
187 | - $this->assertEquals($this->client->getObjectAcl(array("Bucket"=>$this->bucket,"Key"=>$this->key)),"private","object acl"); |
|
188 | - $this->client->setObjectAcl(array("Bucket"=>$this->bucket,"Key"=>$this->key,"ACL"=>"public-read")); |
|
189 | - $this->assertEquals($this->client->getObjectAcl(array("Bucket"=>$this->bucket,"Key"=>$this->key)),"public-read","object acl"); |
|
184 | + public function testObjectAcl() { |
|
185 | + $this->client->putObjectByContent(array("Bucket"=>$this->bucket, "Key"=>$this->key, |
|
186 | +"Content"=>"1234", "ACL"=>"private")); |
|
187 | + $this->assertEquals($this->client->getObjectAcl(array("Bucket"=>$this->bucket, "Key"=>$this->key)), "private", "object acl"); |
|
188 | + $this->client->setObjectAcl(array("Bucket"=>$this->bucket, "Key"=>$this->key, "ACL"=>"public-read")); |
|
189 | + $this->assertEquals($this->client->getObjectAcl(array("Bucket"=>$this->bucket, "Key"=>$this->key)), "public-read", "object acl"); |
|
190 | 190 | } |
191 | - public function testDeleteObject(){ |
|
192 | - $this->client->putObjectByContent(array("Bucket"=>$this->bucket,"Key"=>$this->key, |
|
191 | + public function testDeleteObject() { |
|
192 | + $this->client->putObjectByContent(array("Bucket"=>$this->bucket, "Key"=>$this->key, |
|
193 | 193 | "Content"=>"1234")); |
194 | - $this->client->deleteObject(array("Bucket"=>$this->bucket,"Key"=>$this->key)); |
|
195 | - $this->assertEquals($this->client->objectExists(array("Bucket"=>$this->bucket,"Key"=>$this->key)),FALSE,"object exits"); |
|
194 | + $this->client->deleteObject(array("Bucket"=>$this->bucket, "Key"=>$this->key)); |
|
195 | + $this->assertEquals($this->client->objectExists(array("Bucket"=>$this->bucket, "Key"=>$this->key)), FALSE, "object exits"); |
|
196 | 196 | } |
197 | - public function testDeleteObjects(){ |
|
198 | - $this->client->putObjectByContent(array("Bucket"=>$this->bucket,"Key"=>$this->key, |
|
197 | + public function testDeleteObjects() { |
|
198 | + $this->client->putObjectByContent(array("Bucket"=>$this->bucket, "Key"=>$this->key, |
|
199 | 199 | "Content"=>"1234")); |
200 | - $this->client->deleteObjects(array("Bucket"=>$this->bucket,"DeleteKeys"=>array($this->key))); |
|
201 | - $this->assertEquals($this->client->objectExists(array("Bucket"=>$this->bucket,"Key"=>$this->key)),FALSE,"object exits"); |
|
200 | + $this->client->deleteObjects(array("Bucket"=>$this->bucket, "DeleteKeys"=>array($this->key))); |
|
201 | + $this->assertEquals($this->client->objectExists(array("Bucket"=>$this->bucket, "Key"=>$this->key)), FALSE, "object exits"); |
|
202 | 202 | } |
203 | - public function testCopyObject(){ |
|
204 | - $this->client->putObjectByContent(array("Bucket"=>$this->bucket,"Key"=>$this->key, |
|
203 | + public function testCopyObject() { |
|
204 | + $this->client->putObjectByContent(array("Bucket"=>$this->bucket, "Key"=>$this->key, |
|
205 | 205 | "Content"=>"1234")); |
206 | - $this->client->copyObject(array("Bucket"=>$this->bucket,"Key"=>$this->key_copy,"CopySource"=>array("Bucket"=>$this->bucket,"Key"=>$this->key))); |
|
207 | - $this->assertEquals($this->client->objectExists(array("Bucket"=>$this->bucket,"Key"=>$this->key)),TRUE,"object exits"); |
|
208 | - $this->assertEquals($this->client->objectExists(array("Bucket"=>$this->bucket,"Key"=>$this->key_copy)),TRUE |
|
206 | + $this->client->copyObject(array("Bucket"=>$this->bucket, "Key"=>$this->key_copy, "CopySource"=>array("Bucket"=>$this->bucket, "Key"=>$this->key))); |
|
207 | + $this->assertEquals($this->client->objectExists(array("Bucket"=>$this->bucket, "Key"=>$this->key)), TRUE, "object exits"); |
|
208 | + $this->assertEquals($this->client->objectExists(array("Bucket"=>$this->bucket, "Key"=>$this->key_copy)), TRUE |
|
209 | 209 | ,"object exits"); |
210 | 210 | } |
211 | - public function testPutAndGetObject(){ |
|
211 | + public function testPutAndGetObject() { |
|
212 | 212 | $args = array( |
213 | 213 | "Bucket"=>$this->bucket, |
214 | 214 | "Key"=>$this->key, |
215 | 215 | "Content"=>array( |
216 | 216 | "content"=>$this->cachedir."test_file" |
217 | - ),//要上传的内容 |
|
218 | - "ACL"=>"public-read",//可以设置访问权限,合法值,private、public-read |
|
217 | + ), //要上传的内容 |
|
218 | + "ACL"=>"public-read", //可以设置访问权限,合法值,private、public-read |
|
219 | 219 | "ObjectMeta"=>array( |
220 | 220 | "Content-Type"=>"application/xml", |
221 | 221 | ), |
@@ -224,20 +224,20 @@ discard block |
||
224 | 224 | ) |
225 | 225 | ); |
226 | 226 | $this->client->putObjectByFile($args); |
227 | - $this->client->getObject(array("Bucket"=>$this->bucket,"Key"=>$this->key,"WriteTo"=>$this->cachedir."down")); |
|
227 | + $this->client->getObject(array("Bucket"=>$this->bucket, "Key"=>$this->key, "WriteTo"=>$this->cachedir."down")); |
|
228 | 228 | $md5 = md5_file($this->cachedir."down"); |
229 | 229 | $md5pre = md5_file($this->cachedir."test_file"); |
230 | 230 | @unlink($this->cachedir."down"); |
231 | - $this->assertEquals($md5,$md5pre,"contentmd5"); |
|
231 | + $this->assertEquals($md5, $md5pre, "contentmd5"); |
|
232 | 232 | } |
233 | - public function testPutAndGetObjectRanges(){ |
|
233 | + public function testPutAndGetObjectRanges() { |
|
234 | 234 | $args = array( |
235 | 235 | "Bucket"=>$this->bucket, |
236 | 236 | "Key"=>$this->key, |
237 | 237 | "Content"=>array( |
238 | 238 | "content"=>$this->cachedir."test_file" |
239 | - ),//要上传的内容 |
|
240 | - "ACL"=>"public-read",//可以设置访问权限,合法值,private、public-read |
|
239 | + ), //要上传的内容 |
|
240 | + "ACL"=>"public-read", //可以设置访问权限,合法值,private、public-read |
|
241 | 241 | "ObjectMeta"=>array( |
242 | 242 | "Content-Type"=>"application/xml", |
243 | 243 | ), |
@@ -246,25 +246,25 @@ discard block |
||
246 | 246 | ) |
247 | 247 | ); |
248 | 248 | $this->client->putObjectByFile($args); |
249 | - rangeGetAndCheckMd5($this->client,$this->bucket,$this->key,$this->cachedir."down",md5_file($this->cachedir."test_file")); |
|
249 | + rangeGetAndCheckMd5($this->client, $this->bucket, $this->key, $this->cachedir."down", md5_file($this->cachedir."test_file")); |
|
250 | 250 | } |
251 | - public function testInitAndAbortMultipart(){ |
|
252 | - $initResult = $this->client->initMultipartUpload(array("Bucket"=>$this->bucket,"Key"=>$this->key)); |
|
251 | + public function testInitAndAbortMultipart() { |
|
252 | + $initResult = $this->client->initMultipartUpload(array("Bucket"=>$this->bucket, "Key"=>$this->key)); |
|
253 | 253 | $uid = $initResult["UploadId"]; |
254 | - $listParts = $this->client->listParts(array("Bucket"=>$this->bucket,"Key"=>$this->key,"Options"=>array("uploadId"=>$uid))); |
|
255 | - $this->client->abortMultipartUpload(array("Bucket"=>$this->bucket,"Key"=>$this->key,"Options"=>array("uploadId"=>$uid))); |
|
254 | + $listParts = $this->client->listParts(array("Bucket"=>$this->bucket, "Key"=>$this->key, "Options"=>array("uploadId"=>$uid))); |
|
255 | + $this->client->abortMultipartUpload(array("Bucket"=>$this->bucket, "Key"=>$this->key, "Options"=>array("uploadId"=>$uid))); |
|
256 | 256 | $ex = NULL; |
257 | - try{ |
|
258 | - $this->client->listParts(array("Bucket"=>$this->bucket,"Key"=>$this->key,"Options"=>array("uploadId"=>$uid))); |
|
259 | - }catch(Exception $e){ |
|
257 | + try { |
|
258 | + $this->client->listParts(array("Bucket"=>$this->bucket, "Key"=>$this->key, "Options"=>array("uploadId"=>$uid))); |
|
259 | + } catch (Exception $e) { |
|
260 | 260 | $ex = $e; |
261 | 261 | } |
262 | - if($ex == NULL||!($ex->errorCode === "NoSuchUpload")){ |
|
262 | + if ($ex == NULL || !($ex->errorCode === "NoSuchUpload")) { |
|
263 | 263 | throw new Exception("create bucket expected NoSuchUpload but ".$ex); |
264 | 264 | } |
265 | 265 | } |
266 | - public function testMultipartUpload(){ |
|
267 | - generateFile(1024*1024,$this->cachedir."multi"); |
|
266 | + public function testMultipartUpload() { |
|
267 | + generateFile(1024*1024, $this->cachedir."multi"); |
|
268 | 268 | //初始化分开上传,获取uploadid |
269 | 269 | $args = array( |
270 | 270 | "Bucket"=>$this->bucket, |
@@ -278,18 +278,18 @@ discard block |
||
278 | 278 | ) |
279 | 279 | ); |
280 | 280 | $uploadid = $this->client->initMultipartUpload($args); |
281 | - $uploadid = $uploadid["UploadId"];//获取到uploadid |
|
281 | + $uploadid = $uploadid["UploadId"]; //获取到uploadid |
|
282 | 282 | //开始上传 |
283 | - $file = $this->cachedir."multi";//要上传的文件 |
|
283 | + $file = $this->cachedir."multi"; //要上传的文件 |
|
284 | 284 | $partsize = 1024*100; |
285 | - $resource = fopen($file,"r"); |
|
285 | + $resource = fopen($file, "r"); |
|
286 | 286 | $stat = fstat($resource); |
287 | - $total = $stat["size"];//获取文件的总大小 |
|
287 | + $total = $stat["size"]; //获取文件的总大小 |
|
288 | 288 | fclose($resource); |
289 | - $count = (int)(($total-1)/$partsize)+1;;//计算文件需要分几块上传 |
|
290 | - for($i = 0;$i < $count;$i++){ |
|
289 | + $count = (int)(($total-1)/$partsize)+1; ;//计算文件需要分几块上传 |
|
290 | + for ($i = 0; $i < $count; $i++) { |
|
291 | 291 | //依次上传每一块 |
292 | - $args=array( |
|
292 | + $args = array( |
|
293 | 293 | "Bucket"=>$this->bucket, |
294 | 294 | "Key"=>$this->key, |
295 | 295 | "Options"=>array( |
@@ -297,7 +297,7 @@ discard block |
||
297 | 297 | "uploadId"=>$uploadid |
298 | 298 | ), |
299 | 299 | "ObjectMeta"=>array( |
300 | - "Content-Length"=>min($partsize,$total-$partsize*$i)//每次上传$partsize大小 |
|
300 | + "Content-Length"=>min($partsize, $total-$partsize*$i)//每次上传$partsize大小 |
|
301 | 301 | ), |
302 | 302 | "Content"=>array( |
303 | 303 | "content"=>$file, |
@@ -307,24 +307,24 @@ discard block |
||
307 | 307 | $etag = $this->client->uploadPart($args); |
308 | 308 | $etag = $etag["ETag"]; |
309 | 309 | } |
310 | - $parts = $this->client->listParts(array("Bucket"=>$this->bucket,"Key"=>$this->key,"Options"=>array("uploadId"=>$uploadid))); |
|
310 | + $parts = $this->client->listParts(array("Bucket"=>$this->bucket, "Key"=>$this->key, "Options"=>array("uploadId"=>$uploadid))); |
|
311 | 311 | //结束上传 |
312 | - $args=array( |
|
312 | + $args = array( |
|
313 | 313 | "Bucket"=>$this->bucket, |
314 | 314 | "Key"=>$this->key, |
315 | 315 | "Options"=>array("uploadId"=>$uploadid), |
316 | 316 | "Parts"=>$parts["Parts"]//使用之前列出的块完成分开上传 |
317 | 317 | ); |
318 | 318 | $result = $this->client->completeMultipartUpload($args); |
319 | - $this->assertEquals($this->client->getObjectAcl(array("Bucket"=>$this->bucket,"Key"=>$this->key)),"public-read","object acl"); |
|
320 | - $meta = $this->client->getObjectMeta(array("Bucket"=>$this->bucket,"Key"=>$this->key)); |
|
321 | - $this->assertEquals($meta["ObjectMeta"]["Content-Type"],"application/xml","Content-Type"); |
|
322 | - $this->assertEquals($meta["ObjectMeta"]["Content-Length"],filesize($this->cachedir."multi"),"Content-Length"); |
|
323 | - $this->assertEquals($meta["UserMeta"]["x-kss-meta-test"],"example","x-kss-meta-test"); |
|
324 | - rangeGetAndCheckMd5($this->client,$this->bucket,$this->key,$this->cachedir."down",md5_file($this->cachedir."multi")); |
|
319 | + $this->assertEquals($this->client->getObjectAcl(array("Bucket"=>$this->bucket, "Key"=>$this->key)), "public-read", "object acl"); |
|
320 | + $meta = $this->client->getObjectMeta(array("Bucket"=>$this->bucket, "Key"=>$this->key)); |
|
321 | + $this->assertEquals($meta["ObjectMeta"]["Content-Type"], "application/xml", "Content-Type"); |
|
322 | + $this->assertEquals($meta["ObjectMeta"]["Content-Length"], filesize($this->cachedir."multi"), "Content-Length"); |
|
323 | + $this->assertEquals($meta["UserMeta"]["x-kss-meta-test"], "example", "x-kss-meta-test"); |
|
324 | + rangeGetAndCheckMd5($this->client, $this->bucket, $this->key, $this->cachedir."down", md5_file($this->cachedir."multi")); |
|
325 | 325 | @unlink($this->cachedir."multi"); |
326 | 326 | } |
327 | - public function testListBucketsPresignedUrl(){ |
|
327 | + public function testListBucketsPresignedUrl() { |
|
328 | 328 | $url = $this->client->generatePresignedUrl( |
329 | 329 | array( |
330 | 330 | "Method"=>"GET", |
@@ -333,12 +333,12 @@ discard block |
||
333 | 333 | )); |
334 | 334 | $httpRequest = new RequestCore($url); |
335 | 335 | $httpRequest->set_method("GET"); |
336 | - $httpRequest->add_header("Content-Type","text/plain"); |
|
336 | + $httpRequest->add_header("Content-Type", "text/plain"); |
|
337 | 337 | $httpRequest->send_request(); |
338 | - $body = $httpRequest->get_response_body (); |
|
339 | - $this->assertEquals($httpRequest->get_response_code()." body:".$body,200,"list buckets status code"); |
|
338 | + $body = $httpRequest->get_response_body(); |
|
339 | + $this->assertEquals($httpRequest->get_response_code()." body:".$body, 200, "list buckets status code"); |
|
340 | 340 | } |
341 | - public function testHeadBucketPresignedUrl(){ |
|
341 | + public function testHeadBucketPresignedUrl() { |
|
342 | 342 | $url = $this->client->generatePresignedUrl( |
343 | 343 | array( |
344 | 344 | "Method"=>"HEAD", |
@@ -349,12 +349,12 @@ discard block |
||
349 | 349 | ); |
350 | 350 | $httpRequest = new RequestCore($url); |
351 | 351 | $httpRequest->set_method("HEAD"); |
352 | - $httpRequest->add_header("Content-Type","text/plain"); |
|
352 | + $httpRequest->add_header("Content-Type", "text/plain"); |
|
353 | 353 | $httpRequest->send_request(); |
354 | - $body = $httpRequest->get_response_body (); |
|
355 | - $this->assertEquals($httpRequest->get_response_code()." body:".$body,200,"head bucket status code"); |
|
354 | + $body = $httpRequest->get_response_body(); |
|
355 | + $this->assertEquals($httpRequest->get_response_code()." body:".$body, 200, "head bucket status code"); |
|
356 | 356 | } |
357 | - public function testDeleteBucketPresignedUrl(){ |
|
357 | + public function testDeleteBucketPresignedUrl() { |
|
358 | 358 | $this->client->putObjectByContent(array( |
359 | 359 | "Bucket"=>$this->bucket, |
360 | 360 | "Key"=>$this->key, |
@@ -371,28 +371,28 @@ discard block |
||
371 | 371 | ); |
372 | 372 | $httpRequest = new RequestCore($url); |
373 | 373 | $httpRequest->set_method("DELETE"); |
374 | - $httpRequest->add_header("Content-Type","text/plain"); |
|
374 | + $httpRequest->add_header("Content-Type", "text/plain"); |
|
375 | 375 | $httpRequest->send_request(); |
376 | - $body = $httpRequest->get_response_body (); |
|
377 | - $this->assertEquals($httpRequest->get_response_code()." body:".$body,409,"delete bucket status code"); |
|
376 | + $body = $httpRequest->get_response_body(); |
|
377 | + $this->assertEquals($httpRequest->get_response_code()." body:".$body, 409, "delete bucket status code"); |
|
378 | 378 | } |
379 | - public function testGetBucketAclPresignedUrl(){ |
|
379 | + public function testGetBucketAclPresignedUrl() { |
|
380 | 380 | $url = $this->client->generatePresignedUrl( |
381 | 381 | array( |
382 | 382 | "Method"=>"GET", |
383 | 383 | "Bucket"=>$this->bucket, |
384 | - "Options"=>array("Expires"=>60*10,"acl"=>NULL), |
|
384 | + "Options"=>array("Expires"=>60*10, "acl"=>NULL), |
|
385 | 385 | "Headers"=>array("Content-Type"=>"text/plain") |
386 | 386 | ) |
387 | 387 | ); |
388 | 388 | $httpRequest = new RequestCore($url); |
389 | 389 | $httpRequest->set_method("GET"); |
390 | - $httpRequest->add_header("Content-Type","text/plain"); |
|
390 | + $httpRequest->add_header("Content-Type", "text/plain"); |
|
391 | 391 | $httpRequest->send_request(); |
392 | - $body = $httpRequest->get_response_body (); |
|
393 | - $this->assertEquals($httpRequest->get_response_code()." body:".$body,200,"get bucket acl status code"); |
|
392 | + $body = $httpRequest->get_response_body(); |
|
393 | + $this->assertEquals($httpRequest->get_response_code()." body:".$body, 200, "get bucket acl status code"); |
|
394 | 394 | } |
395 | - public function testPutBucketPresignedUrl(){ |
|
395 | + public function testPutBucketPresignedUrl() { |
|
396 | 396 | $url = $this->client->generatePresignedUrl( |
397 | 397 | array( |
398 | 398 | "Method"=>"PUT", |
@@ -403,96 +403,96 @@ discard block |
||
403 | 403 | ); |
404 | 404 | $httpRequest = new RequestCore($url); |
405 | 405 | $httpRequest->set_method("PUT"); |
406 | - $httpRequest->add_header("Content-Type","text/plain"); |
|
406 | + $httpRequest->add_header("Content-Type", "text/plain"); |
|
407 | 407 | $httpRequest->send_request(); |
408 | - $body = $httpRequest->get_response_body (); |
|
409 | - $this->assertEquals($httpRequest->get_response_code()." body:".$body,409,"delete bucket status code"); |
|
408 | + $body = $httpRequest->get_response_body(); |
|
409 | + $this->assertEquals($httpRequest->get_response_code()." body:".$body, 409, "delete bucket status code"); |
|
410 | 410 | } |
411 | - public function testPutBucketAclPresignedUrl(){ |
|
411 | + public function testPutBucketAclPresignedUrl() { |
|
412 | 412 | $url = $this->client->generatePresignedUrl( |
413 | 413 | array( |
414 | 414 | "Method"=>"PUT", |
415 | 415 | "Bucket"=>$this->bucket, |
416 | - "Options"=>array("Expires"=>60*10,"acl"=>NULL), |
|
417 | - "Headers"=>array("Content-Type"=>"text/plain","x-kss-acl"=>"public-read") |
|
416 | + "Options"=>array("Expires"=>60*10, "acl"=>NULL), |
|
417 | + "Headers"=>array("Content-Type"=>"text/plain", "x-kss-acl"=>"public-read") |
|
418 | 418 | ) |
419 | 419 | ); |
420 | 420 | $httpRequest = new RequestCore($url); |
421 | 421 | $httpRequest->set_method("PUT"); |
422 | - $httpRequest->add_header("Content-Type","text/plain"); |
|
423 | - $httpRequest->add_header("x-kss-acl","public-read"); |
|
422 | + $httpRequest->add_header("Content-Type", "text/plain"); |
|
423 | + $httpRequest->add_header("x-kss-acl", "public-read"); |
|
424 | 424 | $httpRequest->send_request(); |
425 | - $body = $httpRequest->get_response_body (); |
|
426 | - $this->assertEquals($httpRequest->get_response_code()." body:".$body,200,"put bucket acl status code"); |
|
427 | - $this->assertEquals($this->client->getBucketAcl(array("Bucket"=>$this->bucket)),"public-read","bucket acl"); |
|
425 | + $body = $httpRequest->get_response_body(); |
|
426 | + $this->assertEquals($httpRequest->get_response_code()." body:".$body, 200, "put bucket acl status code"); |
|
427 | + $this->assertEquals($this->client->getBucketAcl(array("Bucket"=>$this->bucket)), "public-read", "bucket acl"); |
|
428 | 428 | } |
429 | - public function testListObjectsPresignedUrl(){ |
|
429 | + public function testListObjectsPresignedUrl() { |
|
430 | 430 | $url = $this->client->generatePresignedUrl(array( |
431 | 431 | "Method"=>"GET", |
432 | 432 | "Bucket"=>$this->bucket, |
433 | - "Options"=>array("Expires"=>60*10,"delimiter"=>"/"), |
|
433 | + "Options"=>array("Expires"=>60*10, "delimiter"=>"/"), |
|
434 | 434 | "Headers"=>array("Content-Type"=>"text/plain") |
435 | 435 | ) |
436 | 436 | ); |
437 | 437 | $httpRequest = new RequestCore($url); |
438 | 438 | $httpRequest->set_method("GET"); |
439 | - $httpRequest->add_header("Content-Type","text/plain"); |
|
439 | + $httpRequest->add_header("Content-Type", "text/plain"); |
|
440 | 440 | $httpRequest->send_request(); |
441 | - $body = $httpRequest->get_response_body (); |
|
442 | - $this->assertEquals($httpRequest->get_response_code()." body:".$body,200,"list objects status code"); |
|
441 | + $body = $httpRequest->get_response_body(); |
|
442 | + $this->assertEquals($httpRequest->get_response_code()." body:".$body, 200, "list objects status code"); |
|
443 | 443 | } |
444 | - public function testGetBucketLoggingPresignedUrl(){ |
|
444 | + public function testGetBucketLoggingPresignedUrl() { |
|
445 | 445 | $url = $this->client->generatePresignedUrl(array( |
446 | 446 | "Method"=>"GET", |
447 | 447 | "Bucket"=>$this->bucket, |
448 | - "Options"=>array("Expires"=>60*10,"logging"=>""), |
|
448 | + "Options"=>array("Expires"=>60*10, "logging"=>""), |
|
449 | 449 | "Headers"=>array("Content-Type"=>"text/plain") |
450 | 450 | ) |
451 | 451 | ); |
452 | 452 | $httpRequest = new RequestCore($url); |
453 | 453 | $httpRequest->set_method("GET"); |
454 | - $httpRequest->add_header("Content-Type","text/plain"); |
|
454 | + $httpRequest->add_header("Content-Type", "text/plain"); |
|
455 | 455 | $httpRequest->send_request(); |
456 | - $body = $httpRequest->get_response_body (); |
|
457 | - $this->assertEquals($httpRequest->get_response_code()." body:".$body,200,"get bucket logging status code"); |
|
456 | + $body = $httpRequest->get_response_body(); |
|
457 | + $this->assertEquals($httpRequest->get_response_code()." body:".$body, 200, "get bucket logging status code"); |
|
458 | 458 | } |
459 | - public function testPutBucketLoggingPresignedUrl(){ |
|
459 | + public function testPutBucketLoggingPresignedUrl() { |
|
460 | 460 | $xml = new SimpleXmlElement('<BucketLoggingStatus xmlns="http://s3.amazonaws.com/doc/2006-03-01/" />'); |
461 | 461 | $xml = $xml->asXml(); |
462 | 462 | $url = $this->client->generatePresignedUrl( |
463 | 463 | array( |
464 | 464 | "Method"=>"PUT", |
465 | 465 | "Bucket"=>$this->bucket, |
466 | - "Options"=>array("Expires"=>60*10,"logging"=>NULL), |
|
466 | + "Options"=>array("Expires"=>60*10, "logging"=>NULL), |
|
467 | 467 | "Headers"=>array("Content-Type"=>"application/xml") |
468 | 468 | ) |
469 | 469 | ); |
470 | 470 | $httpRequest = new RequestCore($url); |
471 | 471 | $httpRequest->set_method("PUT"); |
472 | - $httpRequest->add_header("Content-Type","application/xml"); |
|
473 | - $httpRequest->add_header("Content-Length",strlen($xml)); |
|
474 | - $httpRequest->request_body=$xml; |
|
472 | + $httpRequest->add_header("Content-Type", "application/xml"); |
|
473 | + $httpRequest->add_header("Content-Length", strlen($xml)); |
|
474 | + $httpRequest->request_body = $xml; |
|
475 | 475 | $httpRequest->send_request(); |
476 | - $body = $httpRequest->get_response_body (); |
|
477 | - $this->assertEquals($httpRequest->get_response_code()." body:".$body,200,"put bucket logging status code"); |
|
476 | + $body = $httpRequest->get_response_body(); |
|
477 | + $this->assertEquals($httpRequest->get_response_code()." body:".$body, 200, "put bucket logging status code"); |
|
478 | 478 | } |
479 | - public function testGetBucketLocationPresignedUrl(){ |
|
479 | + public function testGetBucketLocationPresignedUrl() { |
|
480 | 480 | $url = $this->client->generatePresignedUrl( |
481 | 481 | array( |
482 | 482 | "Method"=>"GET", |
483 | 483 | "Bucket"=>$this->bucket, |
484 | - "Options"=>array("Expires"=>60*10,"location"=>NULL), |
|
484 | + "Options"=>array("Expires"=>60*10, "location"=>NULL), |
|
485 | 485 | "Headers"=>array("Content-Type"=>"text/plain") |
486 | 486 | ) |
487 | 487 | ); |
488 | 488 | $httpRequest = new RequestCore($url); |
489 | 489 | $httpRequest->set_method("GET"); |
490 | - $httpRequest->add_header("Content-Type","text/plain"); |
|
490 | + $httpRequest->add_header("Content-Type", "text/plain"); |
|
491 | 491 | $httpRequest->send_request(); |
492 | - $body = $httpRequest->get_response_body (); |
|
493 | - $this->assertEquals($httpRequest->get_response_code()." body:".$body,200,"get bucket location status code"); |
|
492 | + $body = $httpRequest->get_response_body(); |
|
493 | + $this->assertEquals($httpRequest->get_response_code()." body:".$body, 200, "get bucket location status code"); |
|
494 | 494 | } |
495 | - public function testDeleteObjectPresignedUrl(){ |
|
495 | + public function testDeleteObjectPresignedUrl() { |
|
496 | 496 | $this->client->putObjectByContent(array( |
497 | 497 | "Bucket"=>$this->bucket, |
498 | 498 | "Key"=>$this->key, |
@@ -510,12 +510,12 @@ discard block |
||
510 | 510 | ); |
511 | 511 | $httpRequest = new RequestCore($url); |
512 | 512 | $httpRequest->set_method("DELETE"); |
513 | - $httpRequest->add_header("Content-Type","text/plain"); |
|
513 | + $httpRequest->add_header("Content-Type", "text/plain"); |
|
514 | 514 | $httpRequest->send_request(); |
515 | - $body = $httpRequest->get_response_body (); |
|
516 | - $this->assertEquals($httpRequest->get_response_code()." body:".$body,204,"delete object status code"); |
|
515 | + $body = $httpRequest->get_response_body(); |
|
516 | + $this->assertEquals($httpRequest->get_response_code()." body:".$body, 204, "delete object status code"); |
|
517 | 517 | } |
518 | - public function testGetObjectPresignedUrl(){ |
|
518 | + public function testGetObjectPresignedUrl() { |
|
519 | 519 | $this->client->putObjectByContent(array( |
520 | 520 | "Bucket"=>$this->bucket, |
521 | 521 | "Key"=>$this->key, |
@@ -532,13 +532,13 @@ discard block |
||
532 | 532 | ); |
533 | 533 | $httpRequest = new RequestCore($url); |
534 | 534 | $httpRequest->set_method("GET"); |
535 | - $httpRequest->add_header("Content-Type","text/plain"); |
|
535 | + $httpRequest->add_header("Content-Type", "text/plain"); |
|
536 | 536 | $httpRequest->send_request(); |
537 | - $body = $httpRequest->get_response_body (); |
|
538 | - $this->assertEquals($httpRequest->get_response_code()." body:".$body,200,"get object status code"); |
|
539 | - $this->assertEquals($body,"123","get object body"); |
|
537 | + $body = $httpRequest->get_response_body(); |
|
538 | + $this->assertEquals($httpRequest->get_response_code()." body:".$body, 200, "get object status code"); |
|
539 | + $this->assertEquals($body, "123", "get object body"); |
|
540 | 540 | } |
541 | - public function testPutObjectPresignedUrl(){ |
|
541 | + public function testPutObjectPresignedUrl() { |
|
542 | 542 | $body = "123"; |
543 | 543 | $url = $this->client->generatePresignedUrl( |
544 | 544 | array( |
@@ -551,14 +551,14 @@ discard block |
||
551 | 551 | ); |
552 | 552 | $httpRequest = new RequestCore($url); |
553 | 553 | $httpRequest->set_method("PUT"); |
554 | - $httpRequest->add_header("Content-Type","application/ocet-stream"); |
|
555 | - $httpRequest->add_header("Content-Length",strlen($body)); |
|
556 | - $httpRequest->request_body=$body; |
|
554 | + $httpRequest->add_header("Content-Type", "application/ocet-stream"); |
|
555 | + $httpRequest->add_header("Content-Length", strlen($body)); |
|
556 | + $httpRequest->request_body = $body; |
|
557 | 557 | $httpRequest->send_request(); |
558 | - $body = $httpRequest->get_response_body (); |
|
559 | - $this->assertEquals($httpRequest->get_response_code()." body:".$body,200,"put object status code"); |
|
558 | + $body = $httpRequest->get_response_body(); |
|
559 | + $this->assertEquals($httpRequest->get_response_code()." body:".$body, 200, "put object status code"); |
|
560 | 560 | } |
561 | - public function testHeadObjectPresignedUrl(){ |
|
561 | + public function testHeadObjectPresignedUrl() { |
|
562 | 562 | $this->testPutObjectPresignedUrl(); |
563 | 563 | $url = $this->client->generatePresignedUrl( |
564 | 564 | array( |
@@ -571,54 +571,54 @@ discard block |
||
571 | 571 | ); |
572 | 572 | $httpRequest = new RequestCore($url); |
573 | 573 | $httpRequest->set_method("HEAD"); |
574 | - $httpRequest->add_header("Content-Type","text/plain"); |
|
574 | + $httpRequest->add_header("Content-Type", "text/plain"); |
|
575 | 575 | $httpRequest->send_request(); |
576 | - $body = $httpRequest->get_response_body (); |
|
577 | - $this->assertEquals($httpRequest->get_response_code()." body:".$body,200,"head object status code"); |
|
576 | + $body = $httpRequest->get_response_body(); |
|
577 | + $this->assertEquals($httpRequest->get_response_code()." body:".$body, 200, "head object status code"); |
|
578 | 578 | } |
579 | - public function testGetObjectAclPresignedUrl(){ |
|
579 | + public function testGetObjectAclPresignedUrl() { |
|
580 | 580 | $this->testPutObjectPresignedUrl(); |
581 | 581 | $url = $this->client->generatePresignedUrl( |
582 | 582 | array( |
583 | 583 | "Method"=>"GET", |
584 | 584 | "Bucket"=>$this->bucket, |
585 | 585 | "Key"=>$this->key, |
586 | - "Options"=>array("Expires"=>60*10,"acl"=>NULL), |
|
586 | + "Options"=>array("Expires"=>60*10, "acl"=>NULL), |
|
587 | 587 | "Headers"=>array("Content-Type"=>"text/plain") |
588 | 588 | ) |
589 | 589 | ); |
590 | 590 | $httpRequest = new RequestCore($url); |
591 | 591 | $httpRequest->set_method("GET"); |
592 | - $httpRequest->add_header("Content-Type","text/plain"); |
|
592 | + $httpRequest->add_header("Content-Type", "text/plain"); |
|
593 | 593 | $httpRequest->send_request(); |
594 | - $body = $httpRequest->get_response_body (); |
|
595 | - $this->assertEquals($httpRequest->get_response_code()." body:".$body,200,"get object acl status code"); |
|
594 | + $body = $httpRequest->get_response_body(); |
|
595 | + $this->assertEquals($httpRequest->get_response_code()." body:".$body, 200, "get object acl status code"); |
|
596 | 596 | } |
597 | - public function testPutObjectAclPresignedUrl(){ |
|
597 | + public function testPutObjectAclPresignedUrl() { |
|
598 | 598 | $this->testPutObjectPresignedUrl(); |
599 | 599 | $url = $this->client->generatePresignedUrl( |
600 | 600 | array( |
601 | 601 | "Method"=>"PUT", |
602 | 602 | "Bucket"=>$this->bucket, |
603 | 603 | "Key"=>$this->key, |
604 | - "Options"=>array("Expires"=>60*10,"acl"=>NULL), |
|
605 | - "Headers"=>array("Content-Type"=>"text/plain","x-kss-acl"=>"public-read") |
|
604 | + "Options"=>array("Expires"=>60*10, "acl"=>NULL), |
|
605 | + "Headers"=>array("Content-Type"=>"text/plain", "x-kss-acl"=>"public-read") |
|
606 | 606 | ) |
607 | 607 | ); |
608 | 608 | $httpRequest = new RequestCore($url); |
609 | 609 | $httpRequest->set_method("PUT"); |
610 | - $httpRequest->add_header("Content-Type","text/plain"); |
|
611 | - $httpRequest->add_header("x-kss-acl","public-read"); |
|
610 | + $httpRequest->add_header("Content-Type", "text/plain"); |
|
611 | + $httpRequest->add_header("x-kss-acl", "public-read"); |
|
612 | 612 | $httpRequest->send_request(); |
613 | - $body = $httpRequest->get_response_body (); |
|
614 | - $this->assertEquals($httpRequest->get_response_code()." body:".$body,200,"put object acl status code"); |
|
613 | + $body = $httpRequest->get_response_body(); |
|
614 | + $this->assertEquals($httpRequest->get_response_code()." body:".$body, 200, "put object acl status code"); |
|
615 | 615 | } |
616 | - public function testPutObjectSSEAndGetHeadObject(){ |
|
616 | + public function testPutObjectSSEAndGetHeadObject() { |
|
617 | 617 | $args = array( |
618 | 618 | "Bucket"=>$this->bucket, |
619 | 619 | "Key"=>$this->key, |
620 | - "Content"=>"12345",//要上传的内容 |
|
621 | - "ACL"=>"public-read",//可以设置访问权限,合法值,private、public-read |
|
620 | + "Content"=>"12345", //要上传的内容 |
|
621 | + "ACL"=>"public-read", //可以设置访问权限,合法值,private、public-read |
|
622 | 622 | "ObjectMeta"=>array(//设置object的元数据,可以设置"Cache-Control","Content-Disposition","Content-Encoding","Content-Length","Content-MD5","Content-Type","Expires"。当设置了Content-Length时,请勿大于实际长度,如果小于实际长度,将只上传部分内容。 |
623 | 623 | "Content-Type"=>"binay/ocet-stream" |
624 | 624 | ), |
@@ -630,22 +630,22 @@ discard block |
||
630 | 630 | ) |
631 | 631 | ); |
632 | 632 | $result = $this->client->putObjectByContent($args); |
633 | - $this->assertEquals($result["SSEAlgm"],"AES256"); |
|
633 | + $this->assertEquals($result["SSEAlgm"], "AES256"); |
|
634 | 634 | |
635 | 635 | $args = array( |
636 | 636 | "Bucket"=>$this->bucket, |
637 | 637 | "Key"=>$this->key |
638 | 638 | ); |
639 | 639 | $result = $this->client->getObjectMeta($args); |
640 | - $this->assertEquals($result["ObjectMeta"]["SSEAlgm"],"AES256"); |
|
641 | - rangeGetAndCheckMd5($this->client,$this->bucket,$this->key,$this->cachedir."down",md5("12345")); |
|
640 | + $this->assertEquals($result["ObjectMeta"]["SSEAlgm"], "AES256"); |
|
641 | + rangeGetAndCheckMd5($this->client, $this->bucket, $this->key, $this->cachedir."down", md5("12345")); |
|
642 | 642 | } |
643 | - public function testPutObjectSSECAndGetHeadObject(){ |
|
643 | + public function testPutObjectSSECAndGetHeadObject() { |
|
644 | 644 | $args = array( |
645 | 645 | "Bucket"=>$this->bucket, |
646 | 646 | "Key"=>$this->key, |
647 | - "Content"=>"12345",//要上传的内容 |
|
648 | - "ACL"=>"public-read",//可以设置访问权限,合法值,private、public-read |
|
647 | + "Content"=>"12345", //要上传的内容 |
|
648 | + "ACL"=>"public-read", //可以设置访问权限,合法值,private、public-read |
|
649 | 649 | "ObjectMeta"=>array(//设置object的元数据,可以设置"Cache-Control","Content-Disposition","Content-Encoding","Content-Length","Content-MD5","Content-Type","Expires"。当设置了Content-Length时,请勿大于实际长度,如果小于实际长度,将只上传部分内容。 |
650 | 650 | "Content-Type"=>"binay/ocet-stream" |
651 | 651 | ), |
@@ -657,8 +657,8 @@ discard block |
||
657 | 657 | ) |
658 | 658 | ); |
659 | 659 | $result = $this->client->putObjectByContent($args); |
660 | - $this->assertEquals($result["SSECAlgm"],"AES256"); |
|
661 | - $this->assertEquals($result["SSECKeyMD5"],Utils::hex_to_base64(md5($this->sseckey))); |
|
660 | + $this->assertEquals($result["SSECAlgm"], "AES256"); |
|
661 | + $this->assertEquals($result["SSECKeyMD5"], Utils::hex_to_base64(md5($this->sseckey))); |
|
662 | 662 | |
663 | 663 | $args = array( |
664 | 664 | "Bucket"=>$this->bucket, |
@@ -668,8 +668,8 @@ discard block |
||
668 | 668 | ) |
669 | 669 | ); |
670 | 670 | $result = $this->client->getObjectMeta($args); |
671 | - $this->assertEquals($result["ObjectMeta"]["SSECAlgm"],"AES256"); |
|
672 | - $this->assertEquals($result["ObjectMeta"]["SSECKeyMD5"],Utils::hex_to_base64(md5($this->sseckey))); |
|
671 | + $this->assertEquals($result["ObjectMeta"]["SSECAlgm"], "AES256"); |
|
672 | + $this->assertEquals($result["ObjectMeta"]["SSECKeyMD5"], Utils::hex_to_base64(md5($this->sseckey))); |
|
673 | 673 | |
674 | 674 | $args = array( |
675 | 675 | "Bucket"=>$this->bucket, |
@@ -680,10 +680,10 @@ discard block |
||
680 | 680 | ) |
681 | 681 | ); |
682 | 682 | $this->client->getObject($args); |
683 | - $this->assertEquals("12345",file_get_contents($this->cachedir."down")); |
|
683 | + $this->assertEquals("12345", file_get_contents($this->cachedir."down")); |
|
684 | 684 | @unlink($this->cachedir."down"); |
685 | 685 | } |
686 | - public function testMultipartUploadSSE(){ |
|
686 | + public function testMultipartUploadSSE() { |
|
687 | 687 | $file = $this->cachedir."test_file"; |
688 | 688 | $args = array( |
689 | 689 | "Bucket"=>$this->bucket, |
@@ -694,11 +694,11 @@ discard block |
||
694 | 694 | ); |
695 | 695 | $uploadid = $this->client->initMultipartUpload($args); |
696 | 696 | |
697 | - $this->assertEquals($uploadid["SSEAlgm"],"AES256"); |
|
697 | + $this->assertEquals($uploadid["SSEAlgm"], "AES256"); |
|
698 | 698 | |
699 | 699 | $uploadid = $uploadid["UploadId"]; |
700 | 700 | //开始上传 |
701 | - $args=array( |
|
701 | + $args = array( |
|
702 | 702 | "Bucket"=>$this->bucket, |
703 | 703 | "Key"=>$this->key, |
704 | 704 | "Options"=>array( |
@@ -711,21 +711,21 @@ discard block |
||
711 | 711 | ); |
712 | 712 | $etag = $this->client->uploadPart($args); |
713 | 713 | |
714 | - $this->assertEquals($etag["SSEAlgm"],"AES256"); |
|
714 | + $this->assertEquals($etag["SSEAlgm"], "AES256"); |
|
715 | 715 | $etag = $etag["ETag"]; |
716 | 716 | |
717 | - $parts = $this->client->listParts(array("Bucket"=>$this->bucket,"Key"=>$this->key,"Options"=>array("uploadId"=>$uploadid))); |
|
717 | + $parts = $this->client->listParts(array("Bucket"=>$this->bucket, "Key"=>$this->key, "Options"=>array("uploadId"=>$uploadid))); |
|
718 | 718 | //结束上传 |
719 | - $args=array( |
|
719 | + $args = array( |
|
720 | 720 | "Bucket"=>$this->bucket, |
721 | 721 | "Key"=>$this->key, |
722 | 722 | "Options"=>array("uploadId"=>$uploadid), |
723 | 723 | "Parts"=>$parts["Parts"], |
724 | 724 | ); |
725 | 725 | $result = $this->client->completeMultipartUpload($args); |
726 | - $this->assertEquals($result["SSEAlgm"],"AES256"); |
|
726 | + $this->assertEquals($result["SSEAlgm"], "AES256"); |
|
727 | 727 | } |
728 | - public function testMultipartUploadSSEC(){ |
|
728 | + public function testMultipartUploadSSEC() { |
|
729 | 729 | $file = $this->cachedir."test_file"; |
730 | 730 | $args = array( |
731 | 731 | "Bucket"=>$this->bucket, |
@@ -736,12 +736,12 @@ discard block |
||
736 | 736 | ); |
737 | 737 | $uploadid = $this->client->initMultipartUpload($args); |
738 | 738 | |
739 | - $this->assertEquals($uploadid["SSECAlgm"],"AES256"); |
|
740 | - $this->assertEquals($uploadid["SSECKeyMD5"],Utils::hex_to_base64(md5($this->sseckey))); |
|
739 | + $this->assertEquals($uploadid["SSECAlgm"], "AES256"); |
|
740 | + $this->assertEquals($uploadid["SSECKeyMD5"], Utils::hex_to_base64(md5($this->sseckey))); |
|
741 | 741 | |
742 | 742 | $uploadid = $uploadid["UploadId"]; |
743 | 743 | //开始上传 |
744 | - $args=array( |
|
744 | + $args = array( |
|
745 | 745 | "Bucket"=>$this->bucket, |
746 | 746 | "Key"=>$this->key, |
747 | 747 | "Options"=>array( |
@@ -757,29 +757,29 @@ discard block |
||
757 | 757 | ); |
758 | 758 | $etag = $this->client->uploadPart($args); |
759 | 759 | |
760 | - $this->assertEquals($etag["SSECAlgm"],"AES256"); |
|
761 | - $this->assertEquals($etag["SSECKeyMD5"],Utils::hex_to_base64(md5($this->sseckey))); |
|
760 | + $this->assertEquals($etag["SSECAlgm"], "AES256"); |
|
761 | + $this->assertEquals($etag["SSECKeyMD5"], Utils::hex_to_base64(md5($this->sseckey))); |
|
762 | 762 | |
763 | 763 | $etag = $etag["ETag"]; |
764 | 764 | |
765 | - $parts = $this->client->listParts(array("Bucket"=>$this->bucket,"Key"=>$this->key,"Options"=>array("uploadId"=>$uploadid))); |
|
765 | + $parts = $this->client->listParts(array("Bucket"=>$this->bucket, "Key"=>$this->key, "Options"=>array("uploadId"=>$uploadid))); |
|
766 | 766 | //结束上传 |
767 | - $args=array( |
|
767 | + $args = array( |
|
768 | 768 | "Bucket"=>$this->bucket, |
769 | 769 | "Key"=>$this->key, |
770 | 770 | "Options"=>array("uploadId"=>$uploadid), |
771 | 771 | "Parts"=>$parts["Parts"], |
772 | 772 | ); |
773 | 773 | $result = $this->client->completeMultipartUpload($args); |
774 | - $this->assertEquals($result["SSECAlgm"],"AES256"); |
|
775 | - $this->assertEquals($result["SSECKeyMD5"],Utils::hex_to_base64(md5($this->sseckey))); |
|
774 | + $this->assertEquals($result["SSECAlgm"], "AES256"); |
|
775 | + $this->assertEquals($result["SSECKeyMD5"], Utils::hex_to_base64(md5($this->sseckey))); |
|
776 | 776 | } |
777 | - public function testCopySSECObject(){ |
|
777 | + public function testCopySSECObject() { |
|
778 | 778 | $args = array( |
779 | 779 | "Bucket"=>$this->bucket, |
780 | 780 | "Key"=>$this->key, |
781 | - "Content"=>"12345",//要上传的内容 |
|
782 | - "ACL"=>"public-read",//可以设置访问权限,合法值,private、public-read |
|
781 | + "Content"=>"12345", //要上传的内容 |
|
782 | + "ACL"=>"public-read", //可以设置访问权限,合法值,private、public-read |
|
783 | 783 | "ObjectMeta"=>array(//设置object的元数据,可以设置"Cache-Control","Content-Disposition","Content-Encoding","Content-Length","Content-MD5","Content-Type","Expires"。当设置了Content-Length时,请勿大于实际长度,如果小于实际长度,将只上传部分内容。 |
784 | 784 | "Content-Type"=>"binay/ocet-stream" |
785 | 785 | ), |
@@ -808,8 +808,8 @@ discard block |
||
808 | 808 | ); |
809 | 809 | $result = $this->client->copyObject($args); |
810 | 810 | } |
811 | - public function testPutObjectByContentAndGetObjectUsingEncyptionMeta(){ |
|
812 | - for($i = 45 ;$i < 60;$i++){ |
|
811 | + public function testPutObjectByContentAndGetObjectUsingEncyptionMeta() { |
|
812 | + for ($i = 45; $i < 60; $i++) { |
|
813 | 813 | |
814 | 814 | $content = EncryptionUtil::genereateOnceUsedKey($i); |
815 | 815 | |
@@ -820,11 +820,11 @@ discard block |
||
820 | 820 | "Content"=>$content |
821 | 821 | ); |
822 | 822 | $this->encryptionClient->putObjectByContent($args); |
823 | - rangeGetAndCheckMd5($this->encryptionClient,$this->bucket,$this->key, |
|
824 | - $this->cachedir."down",md5($args["Content"])); |
|
823 | + rangeGetAndCheckMd5($this->encryptionClient, $this->bucket, $this->key, |
|
824 | + $this->cachedir."down", md5($args["Content"])); |
|
825 | 825 | } |
826 | 826 | } |
827 | - public function testPutObjectByFileAndGetObjectUsingEncyptionMeta(){ |
|
827 | + public function testPutObjectByFileAndGetObjectUsingEncyptionMeta() { |
|
828 | 828 | $args = array( |
829 | 829 | "Bucket"=>$this->bucket, |
830 | 830 | "Key"=>$this->key, |
@@ -834,40 +834,40 @@ discard block |
||
834 | 834 | ) |
835 | 835 | ); |
836 | 836 | $this->encryptionClient->putObjectByFile($args); |
837 | - rangeGetAndCheckMd5($this->encryptionClient,$this->bucket,$this->key, |
|
838 | - $this->cachedir."down",md5_file($this->cachedir."test_file")); |
|
837 | + rangeGetAndCheckMd5($this->encryptionClient, $this->bucket, $this->key, |
|
838 | + $this->cachedir."down", md5_file($this->cachedir."test_file")); |
|
839 | 839 | } |
840 | - public function testMultipartUploadUsingEncyptionMeta(){ |
|
841 | - generateFile(1024*1024,$this->cachedir."multi"); |
|
840 | + public function testMultipartUploadUsingEncyptionMeta() { |
|
841 | + generateFile(1024*1024, $this->cachedir."multi"); |
|
842 | 842 | //初始化分开上传,获取uploadid |
843 | 843 | $args = array( |
844 | 844 | "Bucket"=>$this->bucket, |
845 | 845 | "Key"=>$this->key, |
846 | 846 | ); |
847 | 847 | $uploadid = $this->encryptionClient->initMultipartUpload($args); |
848 | - $uploadid = $uploadid["UploadId"];//获取到uploadid |
|
848 | + $uploadid = $uploadid["UploadId"]; //获取到uploadid |
|
849 | 849 | //开始上传 |
850 | 850 | |
851 | - $file = $this->cachedir."multi";//要上传的文件 |
|
851 | + $file = $this->cachedir."multi"; //要上传的文件 |
|
852 | 852 | $partsize = 1024*100; |
853 | - $resource = fopen($file,"r"); |
|
853 | + $resource = fopen($file, "r"); |
|
854 | 854 | $stat = fstat($resource); |
855 | - $total = $stat["size"];//获取文件的总大小 |
|
855 | + $total = $stat["size"]; //获取文件的总大小 |
|
856 | 856 | fclose($resource); |
857 | - $count = (int)(($total-1)/$partsize)+1;//计算文件需要分几块上传 |
|
858 | - for($i = 0;$i < $count;$i++){ |
|
857 | + $count = (int)(($total-1)/$partsize)+1; //计算文件需要分几块上传 |
|
858 | + for ($i = 0; $i < $count; $i++) { |
|
859 | 859 | //依次上传每一块 |
860 | 860 | echo "upload".$i."\r\n"; |
861 | - $args=array( |
|
861 | + $args = array( |
|
862 | 862 | "Bucket"=>$this->bucket, |
863 | 863 | "Key"=>$this->key, |
864 | - "LastPart"=>($i===$count-1), |
|
864 | + "LastPart"=>($i === $count-1), |
|
865 | 865 | "Options"=>array( |
866 | 866 | "partNumber"=>$i+1, |
867 | 867 | "uploadId"=>$uploadid |
868 | 868 | ), |
869 | 869 | "ObjectMeta"=>array( |
870 | - "Content-Length"=>min($partsize,$total-$partsize*$i)//每次上传$partsize大小 |
|
870 | + "Content-Length"=>min($partsize, $total-$partsize*$i)//每次上传$partsize大小 |
|
871 | 871 | ), |
872 | 872 | "Content"=>array( |
873 | 873 | "content"=>$file, |
@@ -877,9 +877,9 @@ discard block |
||
877 | 877 | $etag = $this->encryptionClient->uploadPart($args); |
878 | 878 | $etag = $etag["ETag"]; |
879 | 879 | } |
880 | - $parts = $this->encryptionClient->listParts(array("Bucket"=>$this->bucket,"Key"=>$this->key,"Options"=>array("uploadId"=>$uploadid))); |
|
880 | + $parts = $this->encryptionClient->listParts(array("Bucket"=>$this->bucket, "Key"=>$this->key, "Options"=>array("uploadId"=>$uploadid))); |
|
881 | 881 | //结束上传 |
882 | - $args=array( |
|
882 | + $args = array( |
|
883 | 883 | "Bucket"=>$this->bucket, |
884 | 884 | "Key"=>$this->key, |
885 | 885 | "Options"=>array("uploadId"=>$uploadid), |
@@ -887,11 +887,11 @@ discard block |
||
887 | 887 | ); |
888 | 888 | $result = $this->encryptionClient->completeMultipartUpload($args); |
889 | 889 | |
890 | - rangeGetAndCheckMd5($this->encryptionClient,$this->bucket,$this->key, |
|
891 | - $this->cachedir."down",md5_file($file)); |
|
890 | + rangeGetAndCheckMd5($this->encryptionClient, $this->bucket, $this->key, |
|
891 | + $this->cachedir."down", md5_file($file)); |
|
892 | 892 | @unlink($this->cachedir."multi"); |
893 | 893 | } |
894 | - public function testPutObjectByContentAndGetObject(){ |
|
894 | + public function testPutObjectByContentAndGetObject() { |
|
895 | 895 | @unlink($this->cachedir."down"); |
896 | 896 | $content = EncryptionUtil::genereateOnceUsedKey(500); |
897 | 897 | $args = array( |
@@ -901,15 +901,15 @@ discard block |
||
901 | 901 | "Content"=>$content |
902 | 902 | ); |
903 | 903 | $this->encryptionClient->putObjectByContent($args); |
904 | - $start = (int)rand(0,520); |
|
905 | - $end = (int)rand($start,520); |
|
904 | + $start = (int)rand(0, 520); |
|
905 | + $end = (int)rand($start, 520); |
|
906 | 906 | $s3Object = $this->encryptionClient->getObject( |
907 | - array("Bucket"=>$this->bucket,"Key"=>$this->key, |
|
907 | + array("Bucket"=>$this->bucket, "Key"=>$this->key, |
|
908 | 908 | "Range"=>"bytes=".$start."-".$end) |
909 | 909 | ); |
910 | - $this->assertEquals(substr($content,$start,$end-$start+1),$s3Object["Content"]); |
|
910 | + $this->assertEquals(substr($content, $start, $end-$start+1), $s3Object["Content"]); |
|
911 | 911 | } |
912 | - public function test01(){ |
|
912 | + public function test01() { |
|
913 | 913 | $this->client->listObjects(array("Bucket"=>$this->bucket)); |
914 | 914 | } |
915 | 915 | } |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | array_push($keys, $object["Key"]); |
35 | 35 | } |
36 | 36 | $this->client->deleteObjects(array("Bucket"=>$this->bucket,"DeleteKeys"=>$keys)); |
37 | - }else{ |
|
37 | + } else{ |
|
38 | 38 | $this->client->createBucket(array("Bucket"=>$this->bucket)); |
39 | 39 | } |
40 | 40 | } |
@@ -42,11 +42,13 @@ discard block |
||
42 | 42 | $buckets = $this->client->listBuckets(); |
43 | 43 | $found = FALSE; |
44 | 44 | foreach ($buckets as $bucket) { |
45 | - if($bucket["Name"] == $this->bucket) |
|
46 | - $found = TRUE; |
|
45 | + if($bucket["Name"] == $this->bucket) { |
|
46 | + $found = TRUE; |
|
47 | + } |
|
48 | + } |
|
49 | + if(!$found) { |
|
50 | + throw new Exception("list buckets expected found ".$this->bucket.",but not found"); |
|
47 | 51 | } |
48 | - if(!$found) |
|
49 | - throw new Exception("list buckets expected found ".$this->bucket.",but not found"); |
|
50 | 52 | |
51 | 53 | } |
52 | 54 | public function testDeleteBucket(){ |
@@ -54,7 +56,7 @@ discard block |
||
54 | 56 | $ex = NULL; |
55 | 57 | try{ |
56 | 58 | $this->client->deleteBucket(array("Bucket"=>$this->bucket)); |
57 | - }catch(Exception $e){ |
|
59 | + } catch(Exception $e){ |
|
58 | 60 | $ex = $e; |
59 | 61 | } |
60 | 62 | if($ex == NULL||!($ex->errorCode === "BucketNotEmpty")){ |
@@ -90,7 +92,7 @@ discard block |
||
90 | 92 | $ex = NULL; |
91 | 93 | try{ |
92 | 94 | $this->client->createBucket(array("Bucket"=>$this->bucket)); |
93 | - }catch(Exception $e){ |
|
95 | + } catch(Exception $e){ |
|
94 | 96 | $ex = $e; |
95 | 97 | } |
96 | 98 | if($ex == NULL||!($ex->errorCode === "BucketAlreadyExists")){ |
@@ -256,7 +258,7 @@ discard block |
||
256 | 258 | $ex = NULL; |
257 | 259 | try{ |
258 | 260 | $this->client->listParts(array("Bucket"=>$this->bucket,"Key"=>$this->key,"Options"=>array("uploadId"=>$uid))); |
259 | - }catch(Exception $e){ |
|
261 | + } catch(Exception $e){ |
|
260 | 262 | $ex = $e; |
261 | 263 | } |
262 | 264 | if($ex == NULL||!($ex->errorCode === "NoSuchUpload")){ |
@@ -1,53 +1,53 @@ |
||
1 | 1 | <?php |
2 | 2 | function rangeGetAndCheckMd5($client,$bucket,$key,$file,$expectedMd5){ |
3 | - $args = array("Bucket"=>$bucket,"Key"=>$key); |
|
4 | - $meta = $client->getObjectMeta($args); |
|
5 | - $contentlength = $meta["ObjectMeta"]["Content-Length"]; |
|
3 | + $args = array("Bucket"=>$bucket,"Key"=>$key); |
|
4 | + $meta = $client->getObjectMeta($args); |
|
5 | + $contentlength = $meta["ObjectMeta"]["Content-Length"]; |
|
6 | 6 | |
7 | - $filelist = array(); |
|
7 | + $filelist = array(); |
|
8 | 8 | |
9 | - for($begin = 0;$begin <$contentlength;){ |
|
10 | - $index = rand((int)($contentlength/20),(int)($contentlength/4)); |
|
11 | - $range = array("start"=>$begin,"end"=>$begin+$index); |
|
12 | - $destFile = $file.$begin."-".($begin+$index); |
|
13 | - array_push($filelist,$destFile); |
|
14 | - $begin += ($index+1); |
|
15 | - $args = array( |
|
16 | - "Bucket"=>$bucket, |
|
17 | - "Key"=>$key, |
|
18 | - "Range"=>$range, |
|
19 | - "WriteTo"=>$destFile |
|
20 | - ); |
|
21 | - $client->getObject($args); |
|
22 | - } |
|
9 | + for($begin = 0;$begin <$contentlength;){ |
|
10 | + $index = rand((int)($contentlength/20),(int)($contentlength/4)); |
|
11 | + $range = array("start"=>$begin,"end"=>$begin+$index); |
|
12 | + $destFile = $file.$begin."-".($begin+$index); |
|
13 | + array_push($filelist,$destFile); |
|
14 | + $begin += ($index+1); |
|
15 | + $args = array( |
|
16 | + "Bucket"=>$bucket, |
|
17 | + "Key"=>$key, |
|
18 | + "Range"=>$range, |
|
19 | + "WriteTo"=>$destFile |
|
20 | + ); |
|
21 | + $client->getObject($args); |
|
22 | + } |
|
23 | 23 | |
24 | - foreach ($filelist as $key => $value) { |
|
25 | - $handle = fopen($value,"r"); |
|
26 | - $size = filesize($value); |
|
27 | - if($size > 0){ |
|
28 | - $content = fread($handle,$size); |
|
29 | - file_put_contents($file,$content,FILE_APPEND); |
|
30 | - } |
|
31 | - fclose($handle); |
|
32 | - //@unlink($value); |
|
33 | - } |
|
34 | - $md5 = md5_file($file); |
|
35 | - //@unlink($file); |
|
36 | - if($md5 != $expectedMd5) |
|
37 | - throw new Exception("file md5 check error expected ".$expectedMd5." ,actual ".$md5, 1); |
|
38 | - foreach ($filelist as $key => $value) { |
|
39 | - @unlink($value); |
|
40 | - } |
|
41 | - @unlink($file); |
|
24 | + foreach ($filelist as $key => $value) { |
|
25 | + $handle = fopen($value,"r"); |
|
26 | + $size = filesize($value); |
|
27 | + if($size > 0){ |
|
28 | + $content = fread($handle,$size); |
|
29 | + file_put_contents($file,$content,FILE_APPEND); |
|
30 | + } |
|
31 | + fclose($handle); |
|
32 | + //@unlink($value); |
|
33 | + } |
|
34 | + $md5 = md5_file($file); |
|
35 | + //@unlink($file); |
|
36 | + if($md5 != $expectedMd5) |
|
37 | + throw new Exception("file md5 check error expected ".$expectedMd5." ,actual ".$md5, 1); |
|
38 | + foreach ($filelist as $key => $value) { |
|
39 | + @unlink($value); |
|
40 | + } |
|
41 | + @unlink($file); |
|
42 | 42 | } |
43 | 43 | function generateFile($sizeInBytes,$destFile){ |
44 | - for($i = 0;$i < $sizeInBytes/10;$i++){ |
|
45 | - $randpwd = ""; |
|
46 | - for ($j = 0; $j < 10; $j++) |
|
47 | - { |
|
48 | - $randpwd .= chr(mt_rand(33, 126)); |
|
49 | - } |
|
50 | - file_put_contents($destFile,$randpwd,FILE_APPEND); |
|
51 | - } |
|
44 | + for($i = 0;$i < $sizeInBytes/10;$i++){ |
|
45 | + $randpwd = ""; |
|
46 | + for ($j = 0; $j < 10; $j++) |
|
47 | + { |
|
48 | + $randpwd .= chr(mt_rand(33, 126)); |
|
49 | + } |
|
50 | + file_put_contents($destFile,$randpwd,FILE_APPEND); |
|
51 | + } |
|
52 | 52 | } |
53 | 53 | ?> |
54 | 54 | \ No newline at end of file |
@@ -1,16 +1,16 @@ discard block |
||
1 | 1 | <?php |
2 | -function rangeGetAndCheckMd5($client,$bucket,$key,$file,$expectedMd5){ |
|
3 | - $args = array("Bucket"=>$bucket,"Key"=>$key); |
|
2 | +function rangeGetAndCheckMd5($client, $bucket, $key, $file, $expectedMd5) { |
|
3 | + $args = array("Bucket"=>$bucket, "Key"=>$key); |
|
4 | 4 | $meta = $client->getObjectMeta($args); |
5 | 5 | $contentlength = $meta["ObjectMeta"]["Content-Length"]; |
6 | 6 | |
7 | 7 | $filelist = array(); |
8 | 8 | |
9 | - for($begin = 0;$begin <$contentlength;){ |
|
10 | - $index = rand((int)($contentlength/20),(int)($contentlength/4)); |
|
11 | - $range = array("start"=>$begin,"end"=>$begin+$index); |
|
9 | + for ($begin = 0; $begin < $contentlength;) { |
|
10 | + $index = rand((int)($contentlength/20), (int)($contentlength/4)); |
|
11 | + $range = array("start"=>$begin, "end"=>$begin+$index); |
|
12 | 12 | $destFile = $file.$begin."-".($begin+$index); |
13 | - array_push($filelist,$destFile); |
|
13 | + array_push($filelist, $destFile); |
|
14 | 14 | $begin += ($index+1); |
15 | 15 | $args = array( |
16 | 16 | "Bucket"=>$bucket, |
@@ -22,32 +22,32 @@ discard block |
||
22 | 22 | } |
23 | 23 | |
24 | 24 | foreach ($filelist as $key => $value) { |
25 | - $handle = fopen($value,"r"); |
|
25 | + $handle = fopen($value, "r"); |
|
26 | 26 | $size = filesize($value); |
27 | - if($size > 0){ |
|
28 | - $content = fread($handle,$size); |
|
29 | - file_put_contents($file,$content,FILE_APPEND); |
|
27 | + if ($size > 0) { |
|
28 | + $content = fread($handle, $size); |
|
29 | + file_put_contents($file, $content, FILE_APPEND); |
|
30 | 30 | } |
31 | 31 | fclose($handle); |
32 | 32 | //@unlink($value); |
33 | 33 | } |
34 | 34 | $md5 = md5_file($file); |
35 | 35 | //@unlink($file); |
36 | - if($md5 != $expectedMd5) |
|
36 | + if ($md5 != $expectedMd5) |
|
37 | 37 | throw new Exception("file md5 check error expected ".$expectedMd5." ,actual ".$md5, 1); |
38 | 38 | foreach ($filelist as $key => $value) { |
39 | 39 | @unlink($value); |
40 | 40 | } |
41 | 41 | @unlink($file); |
42 | 42 | } |
43 | -function generateFile($sizeInBytes,$destFile){ |
|
44 | - for($i = 0;$i < $sizeInBytes/10;$i++){ |
|
43 | +function generateFile($sizeInBytes, $destFile) { |
|
44 | + for ($i = 0; $i < $sizeInBytes/10; $i++) { |
|
45 | 45 | $randpwd = ""; |
46 | 46 | for ($j = 0; $j < 10; $j++) |
47 | 47 | { |
48 | 48 | $randpwd .= chr(mt_rand(33, 126)); |
49 | 49 | } |
50 | - file_put_contents($destFile,$randpwd,FILE_APPEND); |
|
50 | + file_put_contents($destFile, $randpwd, FILE_APPEND); |
|
51 | 51 | } |
52 | 52 | } |
53 | 53 | ?> |
54 | 54 | \ No newline at end of file |
@@ -33,8 +33,9 @@ |
||
33 | 33 | } |
34 | 34 | $md5 = md5_file($file); |
35 | 35 | //@unlink($file); |
36 | - if($md5 != $expectedMd5) |
|
37 | - throw new Exception("file md5 check error expected ".$expectedMd5." ,actual ".$md5, 1); |
|
36 | + if($md5 != $expectedMd5) { |
|
37 | + throw new Exception("file md5 check error expected ".$expectedMd5." ,actual ".$md5, 1); |
|
38 | + } |
|
38 | 39 | foreach ($filelist as $key => $value) { |
39 | 40 | @unlink($value); |
40 | 41 | } |
@@ -1,60 +1,60 @@ |
||
1 | 1 | <?php |
2 | 2 | require_once "../core/Logger.php"; |
3 | 3 | class PUnit{ |
4 | - function assertEquals($value,$expected,$info = NULL){ |
|
5 | - if($value != $expected){ |
|
6 | - throw new Exception($info." expected ".$expected." but ".$value); |
|
7 | - } |
|
8 | - } |
|
9 | - function run($torun = NULL){ |
|
10 | - $r = new ReflectionClass($this); |
|
11 | - foreach($r->getMethods() as $key=>$methodObj){ |
|
12 | - if($methodObj->isPrivate()) |
|
13 | - $methods[$key]['type'] = 'private'; |
|
14 | - elseif($methodObj->isProtected()) |
|
15 | - $methods[$key]['type'] = 'protected'; |
|
16 | - else |
|
17 | - $methods[$key]['type'] = 'public'; |
|
18 | - $methods[$key]['name'] = $methodObj->name; |
|
19 | - $methods[$key]['class'] = $methodObj->class; |
|
20 | - } |
|
4 | + function assertEquals($value,$expected,$info = NULL){ |
|
5 | + if($value != $expected){ |
|
6 | + throw new Exception($info." expected ".$expected." but ".$value); |
|
7 | + } |
|
8 | + } |
|
9 | + function run($torun = NULL){ |
|
10 | + $r = new ReflectionClass($this); |
|
11 | + foreach($r->getMethods() as $key=>$methodObj){ |
|
12 | + if($methodObj->isPrivate()) |
|
13 | + $methods[$key]['type'] = 'private'; |
|
14 | + elseif($methodObj->isProtected()) |
|
15 | + $methods[$key]['type'] = 'protected'; |
|
16 | + else |
|
17 | + $methods[$key]['type'] = 'public'; |
|
18 | + $methods[$key]['name'] = $methodObj->name; |
|
19 | + $methods[$key]['class'] = $methodObj->class; |
|
20 | + } |
|
21 | 21 | $before = NULL; |
22 | 22 | $after = NULL; |
23 | 23 | foreach ($methods as $method) { |
24 | - if($method["class"] != "PUnit"&&$method["name"] == "before"){ |
|
24 | + if($method["class"] != "PUnit"&&$method["name"] == "before"){ |
|
25 | 25 | $before = $method; |
26 | - } |
|
27 | - if($method["class"] != "PUnit"&&$method["name"] == "after"){ |
|
26 | + } |
|
27 | + if($method["class"] != "PUnit"&&$method["name"] == "after"){ |
|
28 | 28 | $after = $method; |
29 | - } |
|
29 | + } |
|
30 | 30 | } |
31 | - $error = array(); |
|
32 | - $success = array(); |
|
33 | - foreach ($methods as $method) { |
|
34 | - if($method["class"] != "PUnit"&&substr($method["name"],0,4) == "test"){ |
|
31 | + $error = array(); |
|
32 | + $success = array(); |
|
33 | + foreach ($methods as $method) { |
|
34 | + if($method["class"] != "PUnit"&&substr($method["name"],0,4) == "test"){ |
|
35 | 35 | if($torun !== NULL){ |
36 | - if(!in_array($method["name"],$torun)) |
|
36 | + if(!in_array($method["name"],$torun)) |
|
37 | 37 | continue; |
38 | 38 | } |
39 | - try{ |
|
40 | - if($method["type"] == "public"){ |
|
39 | + try{ |
|
40 | + if($method["type"] == "public"){ |
|
41 | 41 | $log = new Logger(); |
42 | 42 | $log->info("Run unit --->".$method["name"]); |
43 | 43 | if($before!=NULL) |
44 | - $this->$before["name"](); |
|
45 | - $this->$method["name"](); |
|
46 | - array_push($success,$method["name"]); |
|
47 | - } |
|
48 | - }catch(Exception $e){ |
|
49 | - $error[$method["name"]]="".$e; |
|
50 | - } |
|
51 | - } |
|
52 | - } |
|
53 | - echo "\r\nPHP Unit-----------error"."\r\n"; |
|
54 | - print_r($error); |
|
44 | + $this->$before["name"](); |
|
45 | + $this->$method["name"](); |
|
46 | + array_push($success,$method["name"]); |
|
47 | + } |
|
48 | + }catch(Exception $e){ |
|
49 | + $error[$method["name"]]="".$e; |
|
50 | + } |
|
51 | + } |
|
52 | + } |
|
53 | + echo "\r\nPHP Unit-----------error"."\r\n"; |
|
54 | + print_r($error); |
|
55 | 55 | echo "PHP Unit-----------result"."\r\n"; |
56 | 56 | echo "total:".(count($success)+count($error)).",success:".count($success).",error:".count($error)."\r\n"; |
57 | 57 | |
58 | - } |
|
58 | + } |
|
59 | 59 | } |
60 | 60 | ?> |
61 | 61 | \ No newline at end of file |
@@ -1,17 +1,17 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | require_once "../core/Logger.php"; |
3 | -class PUnit{ |
|
4 | - function assertEquals($value,$expected,$info = NULL){ |
|
5 | - if($value != $expected){ |
|
3 | +class PUnit { |
|
4 | + function assertEquals($value, $expected, $info = NULL) { |
|
5 | + if ($value != $expected) { |
|
6 | 6 | throw new Exception($info." expected ".$expected." but ".$value); |
7 | 7 | } |
8 | 8 | } |
9 | - function run($torun = NULL){ |
|
9 | + function run($torun = NULL) { |
|
10 | 10 | $r = new ReflectionClass($this); |
11 | - foreach($r->getMethods() as $key=>$methodObj){ |
|
12 | - if($methodObj->isPrivate()) |
|
11 | + foreach ($r->getMethods() as $key=>$methodObj) { |
|
12 | + if ($methodObj->isPrivate()) |
|
13 | 13 | $methods[$key]['type'] = 'private'; |
14 | - elseif($methodObj->isProtected()) |
|
14 | + elseif ($methodObj->isProtected()) |
|
15 | 15 | $methods[$key]['type'] = 'protected'; |
16 | 16 | else |
17 | 17 | $methods[$key]['type'] = 'public'; |
@@ -21,32 +21,32 @@ discard block |
||
21 | 21 | $before = NULL; |
22 | 22 | $after = NULL; |
23 | 23 | foreach ($methods as $method) { |
24 | - if($method["class"] != "PUnit"&&$method["name"] == "before"){ |
|
24 | + if ($method["class"] != "PUnit" && $method["name"] == "before") { |
|
25 | 25 | $before = $method; |
26 | 26 | } |
27 | - if($method["class"] != "PUnit"&&$method["name"] == "after"){ |
|
27 | + if ($method["class"] != "PUnit" && $method["name"] == "after") { |
|
28 | 28 | $after = $method; |
29 | 29 | } |
30 | 30 | } |
31 | 31 | $error = array(); |
32 | 32 | $success = array(); |
33 | 33 | foreach ($methods as $method) { |
34 | - if($method["class"] != "PUnit"&&substr($method["name"],0,4) == "test"){ |
|
35 | - if($torun !== NULL){ |
|
36 | - if(!in_array($method["name"],$torun)) |
|
34 | + if ($method["class"] != "PUnit" && substr($method["name"], 0, 4) == "test") { |
|
35 | + if ($torun !== NULL) { |
|
36 | + if (!in_array($method["name"], $torun)) |
|
37 | 37 | continue; |
38 | 38 | } |
39 | - try{ |
|
40 | - if($method["type"] == "public"){ |
|
39 | + try { |
|
40 | + if ($method["type"] == "public") { |
|
41 | 41 | $log = new Logger(); |
42 | 42 | $log->info("Run unit --->".$method["name"]); |
43 | - if($before!=NULL) |
|
43 | + if ($before != NULL) |
|
44 | 44 | $this->$before["name"](); |
45 | 45 | $this->$method["name"](); |
46 | - array_push($success,$method["name"]); |
|
46 | + array_push($success, $method["name"]); |
|
47 | 47 | } |
48 | - }catch(Exception $e){ |
|
49 | - $error[$method["name"]]="".$e; |
|
48 | + } catch (Exception $e) { |
|
49 | + $error[$method["name"]] = "".$e; |
|
50 | 50 | } |
51 | 51 | } |
52 | 52 | } |
@@ -9,12 +9,13 @@ discard block |
||
9 | 9 | function run($torun = NULL){ |
10 | 10 | $r = new ReflectionClass($this); |
11 | 11 | foreach($r->getMethods() as $key=>$methodObj){ |
12 | - if($methodObj->isPrivate()) |
|
13 | - $methods[$key]['type'] = 'private'; |
|
14 | - elseif($methodObj->isProtected()) |
|
15 | - $methods[$key]['type'] = 'protected'; |
|
16 | - else |
|
17 | - $methods[$key]['type'] = 'public'; |
|
12 | + if($methodObj->isPrivate()) { |
|
13 | + $methods[$key]['type'] = 'private'; |
|
14 | + } elseif($methodObj->isProtected()) { |
|
15 | + $methods[$key]['type'] = 'protected'; |
|
16 | + } else { |
|
17 | + $methods[$key]['type'] = 'public'; |
|
18 | + } |
|
18 | 19 | $methods[$key]['name'] = $methodObj->name; |
19 | 20 | $methods[$key]['class'] = $methodObj->class; |
20 | 21 | } |
@@ -33,19 +34,21 @@ discard block |
||
33 | 34 | foreach ($methods as $method) { |
34 | 35 | if($method["class"] != "PUnit"&&substr($method["name"],0,4) == "test"){ |
35 | 36 | if($torun !== NULL){ |
36 | - if(!in_array($method["name"],$torun)) |
|
37 | - continue; |
|
37 | + if(!in_array($method["name"],$torun)) { |
|
38 | + continue; |
|
39 | + } |
|
38 | 40 | } |
39 | 41 | try{ |
40 | 42 | if($method["type"] == "public"){ |
41 | 43 | $log = new Logger(); |
42 | 44 | $log->info("Run unit --->".$method["name"]); |
43 | - if($before!=NULL) |
|
44 | - $this->$before["name"](); |
|
45 | + if($before!=NULL) { |
|
46 | + $this->$before["name"](); |
|
47 | + } |
|
45 | 48 | $this->$method["name"](); |
46 | 49 | array_push($success,$method["name"]); |
47 | 50 | } |
48 | - }catch(Exception $e){ |
|
51 | + } catch(Exception $e){ |
|
49 | 52 | $error[$method["name"]]="".$e; |
50 | 53 | } |
51 | 54 | } |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | if (empty($this->accessKeyID) || empty($this->accessKeySecret) || empty($this->endpoint)) { |
82 | 82 | $this->getConfig(); |
83 | 83 | } |
84 | - require_once(__DIR__ . "/bin/Ks3Client.class.php"); |
|
84 | + require_once(__DIR__."/bin/Ks3Client.class.php"); |
|
85 | 85 | $client = new Ks3Client($this->accessKeyID, $this->accessKeySecret, $this->endpoint); |
86 | 86 | if (empty($this->bucket)) { |
87 | 87 | $this->getConfig(); |
@@ -92,10 +92,10 @@ discard block |
||
92 | 92 | "Key" => $object, |
93 | 93 | "Content" => [ |
94 | 94 | //要上传的内容 |
95 | - "content" => $content,//可以是文件路径或者resource,如果文件大于2G,请提供文件路径 |
|
95 | + "content" => $content, //可以是文件路径或者resource,如果文件大于2G,请提供文件路径 |
|
96 | 96 | "seek_position" => 0//跳过文件开头?个字节 |
97 | 97 | ], |
98 | - "ACL" => "public-read",//可以设置访问权限,合法值,private、public-read |
|
98 | + "ACL" => "public-read", //可以设置访问权限,合法值,private、public-read |
|
99 | 99 | "ObjectMeta" => [ |
100 | 100 | //设置object的元数据,可以设置"Cache-Control","Content-Disposition","Content-Encoding","Content-Length","Content-MD5","Content-Type","Expires"。当设置了Content-Length时,最后上传的为从seek_position开始向后Content-Length个字节的内容。当设置了Content-MD5时,系统会在服务端进行md5校验。 |
101 | 101 | "Content-Type" => "binay/ocet-stream" |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | ]; |
109 | 109 | try { |
110 | 110 | $client->putObjectByFile($args); |
111 | - return config('dtapp.ksyun.ks3.url', '') . $object; |
|
111 | + return config('dtapp.ksyun.ks3.url', '').$object; |
|
112 | 112 | } catch (Ks3ServiceException $e) { |
113 | 113 | return false; |
114 | 114 | } |
@@ -83,7 +83,7 @@ |
||
83 | 83 | $data['msgtype'] = $this->msg_type; |
84 | 84 | } |
85 | 85 | $result = HttpService::instance() |
86 | - ->url("{$this->oapi_url}robot/send?access_token=" . $this->access_token) |
|
86 | + ->url("{$this->oapi_url}robot/send?access_token=".$this->access_token) |
|
87 | 87 | ->data($data) |
88 | 88 | ->post() |
89 | 89 | ->toArray(); |
@@ -80,6 +80,6 @@ |
||
80 | 80 | $client = new Upyun($serviceConfig); |
81 | 81 | $file = fopen($filePath, 'r'); |
82 | 82 | $client->write($object, $file); |
83 | - return config('dtapp.upyun.uss.url', '') . $object; |
|
83 | + return config('dtapp.upyun.uss.url', '').$object; |
|
84 | 84 | } |
85 | 85 | } |
@@ -96,6 +96,6 @@ |
||
96 | 96 | $this->getConfig(); |
97 | 97 | } |
98 | 98 | $client->putObjectFromFile($this->bucket, $object, $filePath); |
99 | - return config('dtapp.baidu.bos.url', '') . $object; |
|
99 | + return config('dtapp.baidu.bos.url', '').$object; |
|
100 | 100 | } |
101 | 101 | } |
@@ -79,10 +79,10 @@ discard block |
||
79 | 79 | throw new DtaException('请检查配置文件是否配置了IP数据库文件存放位置'); |
80 | 80 | } |
81 | 81 | $this->fp = 0; |
82 | - if (($this->fp = fopen($this->ipPath . 'qqwry.dat', 'rb')) !== false) { |
|
82 | + if (($this->fp = fopen($this->ipPath.'qqwry.dat', 'rb')) !== false) { |
|
83 | 83 | $this->firstIp = $this->getLong(); |
84 | 84 | $this->lastIp = $this->getLong(); |
85 | - $this->totalIp = ($this->lastIp - $this->firstIp) / 7; |
|
85 | + $this->totalIp = ($this->lastIp-$this->firstIp)/7; |
|
86 | 86 | } |
87 | 87 | parent::__construct($app); |
88 | 88 | } |
@@ -163,49 +163,49 @@ discard block |
||
163 | 163 | // 如果数据文件没有被正确打开,则直接返回错误 |
164 | 164 | throw new DtaException('数据库文件不存在!'); |
165 | 165 | } |
166 | - $location['ip'] = $ip; // 将输入的域名转化为IP地址 |
|
167 | - $ip = $this->packIp($location['ip']); // 将输入的IP地址转化为可比较的IP地址 |
|
166 | + $location['ip'] = $ip; // 将输入的域名转化为IP地址 |
|
167 | + $ip = $this->packIp($location['ip']); // 将输入的IP地址转化为可比较的IP地址 |
|
168 | 168 | // 不合法的IP地址会被转化为255.255.255.255 |
169 | 169 | // 对分搜索 |
170 | - $l = 0; // 搜索的下边界 |
|
171 | - $u = $this->totalIp; // 搜索的上边界 |
|
172 | - $findip = $this->lastIp; // 如果没有找到就返回最后一条IP记录(QQWry.Dat的版本信息) |
|
170 | + $l = 0; // 搜索的下边界 |
|
171 | + $u = $this->totalIp; // 搜索的上边界 |
|
172 | + $findip = $this->lastIp; // 如果没有找到就返回最后一条IP记录(QQWry.Dat的版本信息) |
|
173 | 173 | while ($l <= $u) { // 当上边界小于下边界时,查找失败 |
174 | - $i = floor(($l + $u) / 2); // 计算近似中间记录 |
|
175 | - fseek($this->fp, $this->firstIp + $i * 7); |
|
176 | - $beginip = strrev(fread($this->fp, 4)); // 获取中间记录的开始IP地址 |
|
174 | + $i = floor(($l+$u)/2); // 计算近似中间记录 |
|
175 | + fseek($this->fp, $this->firstIp+$i*7); |
|
176 | + $beginip = strrev(fread($this->fp, 4)); // 获取中间记录的开始IP地址 |
|
177 | 177 | // strrev函数在这里的作用是将little-endian的压缩IP地址转化为big-endian的格式 |
178 | 178 | // 以便用于比较,后面相同。 |
179 | 179 | if ($ip < $beginip) { // 用户的IP小于中间记录的开始IP地址时 |
180 | - $u = $i - 1; // 将搜索的上边界修改为中间记录减一 |
|
181 | - } else { |
|
180 | + $u = $i-1; // 将搜索的上边界修改为中间记录减一 |
|
181 | + }else { |
|
182 | 182 | fseek($this->fp, $this->getLong3()); |
183 | - $endip = strrev(fread($this->fp, 4)); // 获取中间记录的结束IP地址 |
|
183 | + $endip = strrev(fread($this->fp, 4)); // 获取中间记录的结束IP地址 |
|
184 | 184 | if ($ip > $endip) { // 用户的IP大于中间记录的结束IP地址时 |
185 | - $l = $i + 1; // 将搜索的下边界修改为中间记录加一 |
|
186 | - } else { // 用户的IP在中间记录的IP范围内时 |
|
187 | - $findip = $this->firstIp + $i * 7; |
|
188 | - break; // 则表示找到结果,退出循环 |
|
185 | + $l = $i+1; // 将搜索的下边界修改为中间记录加一 |
|
186 | + }else { // 用户的IP在中间记录的IP范围内时 |
|
187 | + $findip = $this->firstIp+$i*7; |
|
188 | + break; // 则表示找到结果,退出循环 |
|
189 | 189 | } |
190 | 190 | } |
191 | 191 | } |
192 | 192 | //获取查找到的IP地理位置信息 |
193 | 193 | fseek($this->fp, $findip); |
194 | - $location['beginip'] = long2ip($this->getLong()); // 用户IP所在范围的开始地址 |
|
194 | + $location['beginip'] = long2ip($this->getLong()); // 用户IP所在范围的开始地址 |
|
195 | 195 | $offset = $this->getLong3(); |
196 | 196 | fseek($this->fp, $offset); |
197 | - $location['endip'] = long2ip($this->getLong()); // 用户IP所在范围的结束地址 |
|
198 | - $byte = fread($this->fp, 1); // 标志字节 |
|
197 | + $location['endip'] = long2ip($this->getLong()); // 用户IP所在范围的结束地址 |
|
198 | + $byte = fread($this->fp, 1); // 标志字节 |
|
199 | 199 | switch (ord($byte)) { |
200 | 200 | case 1: // 标志字节为1,表示国家和区域信息都被同时重定向 |
201 | - $countryOffset = $this->getLong3(); // 重定向地址 |
|
201 | + $countryOffset = $this->getLong3(); // 重定向地址 |
|
202 | 202 | fseek($this->fp, $countryOffset); |
203 | - $byte = fread($this->fp, 1); // 标志字节 |
|
203 | + $byte = fread($this->fp, 1); // 标志字节 |
|
204 | 204 | switch (ord($byte)) { |
205 | 205 | case 2: // 标志字节为2,表示国家信息又被重定向 |
206 | 206 | fseek($this->fp, $this->getLong3()); |
207 | 207 | $location['all'] = $this->getString(); |
208 | - fseek($this->fp, $countryOffset + 4); |
|
208 | + fseek($this->fp, $countryOffset+4); |
|
209 | 209 | $location['extend'] = $this->getExtendString(); |
210 | 210 | break; |
211 | 211 | default: // 否则,表示国家信息没有被重定向 |
@@ -217,7 +217,7 @@ discard block |
||
217 | 217 | case 2: // 标志字节为2,表示国家信息被重定向 |
218 | 218 | fseek($this->fp, $this->getLong3()); |
219 | 219 | $location['all'] = $this->getString(); |
220 | - fseek($this->fp, $offset + 8); |
|
220 | + fseek($this->fp, $offset+8); |
|
221 | 221 | $location['extend'] = $this->getExtendString(); |
222 | 222 | break; |
223 | 223 | default: // 否则,表示国家信息没有被重定向 |
@@ -275,14 +275,14 @@ discard block |
||
275 | 275 | if (count($preg) == 4) { //匹配 "浙江省杭州市" |
276 | 276 | $state = $preg[1] ? $preg[1] : ($preg[2] ? $preg[2] : $preg[3]); |
277 | 277 | $city = $preg[3]; |
278 | - } else if (count($preg) == 7) { //匹配 "浙江省杭州市江干区" |
|
278 | + }else if (count($preg) == 7) { //匹配 "浙江省杭州市江干区" |
|
279 | 279 | $state = $preg[1] ? $preg[1] : ($preg[2] ? $preg[2] : $preg[3]); |
280 | 280 | $city = $preg[3]; |
281 | 281 | $area = $preg[5]; |
282 | - } else if (count($preg) == 3) { //匹配 "香港" |
|
282 | + }else if (count($preg) == 3) { //匹配 "香港" |
|
283 | 283 | $state = $preg[1] ? $preg[1] : $preg[2]; |
284 | 284 | $city = $state; |
285 | - } else if (count($preg) == 2) { //匹配 "浙江省" |
|
285 | + }else if (count($preg) == 2) { //匹配 "浙江省" |
|
286 | 286 | $state = $preg[1] ? $preg[1] : $this->unknown; |
287 | 287 | } |
288 | 288 | } |
@@ -307,7 +307,7 @@ discard block |
||
307 | 307 | private function getLong3() |
308 | 308 | { |
309 | 309 | //将读取的little-endian编码的3个字节转化为长整型数 |
310 | - $result = unpack('Vlong', fread($this->fp, 3) . chr(0)); |
|
310 | + $result = unpack('Vlong', fread($this->fp, 3).chr(0)); |
|
311 | 311 | return $result['long']; |
312 | 312 | } |
313 | 313 | |
@@ -334,7 +334,7 @@ discard block |
||
334 | 334 | { |
335 | 335 | $char = fread($this->fp, 1); |
336 | 336 | while (ord($char) > 0) { // 字符串按照C格式保存,以\0结束 |
337 | - $data .= $char; // 将读取的字符连接到给定字符串之后 |
|
337 | + $data .= $char; // 将读取的字符连接到给定字符串之后 |
|
338 | 338 | $char = fread($this->fp, 1); |
339 | 339 | } |
340 | 340 | return $data; |
@@ -346,7 +346,7 @@ discard block |
||
346 | 346 | */ |
347 | 347 | private function getExtendString() |
348 | 348 | { |
349 | - $byte = fread($this->fp, 1); // 标志字节 |
|
349 | + $byte = fread($this->fp, 1); // 标志字节 |
|
350 | 350 | switch (ord($byte)) { |
351 | 351 | case 0: // 没有区域信息 |
352 | 352 | $area = ""; |
@@ -393,7 +393,7 @@ discard block |
||
393 | 393 | } |
394 | 394 | $IPParts[$i] = str_pad(decHex($IPPart), 2, '0', STR_PAD_LEFT); |
395 | 395 | } |
396 | - return '0000:0000:0000:0000:0000:ffff:' . $IPParts[1] . $IPParts[2] . ':' . $IPParts[3] . $IPParts[4]; |
|
396 | + return '0000:0000:0000:0000:0000:ffff:'.$IPParts[1].$IPParts[2].':'.$IPParts[3].$IPParts[4]; |
|
397 | 397 | } |
398 | 398 | return ''; |
399 | 399 | } |
@@ -425,7 +425,7 @@ discard block |
||
425 | 425 | $district['lng'] = ''; |
426 | 426 | |
427 | 427 | if (!empty($province_name)) { |
428 | - $json_province = json_decode(file_get_contents($this->ipPath . 'province.json'), true); |
|
428 | + $json_province = json_decode(file_get_contents($this->ipPath.'province.json'), true); |
|
429 | 429 | foreach ($json_province['rows'] as $key => $value) { |
430 | 430 | if ($value['name'] == $province_name) { |
431 | 431 | $province['name'] = $value['name']; |
@@ -436,7 +436,7 @@ discard block |
||
436 | 436 | } |
437 | 437 | } |
438 | 438 | if (!empty($city_name)) { |
439 | - $json_city = json_decode(file_get_contents($this->ipPath . 'city.json'), true); |
|
439 | + $json_city = json_decode(file_get_contents($this->ipPath.'city.json'), true); |
|
440 | 440 | foreach ($json_city['rows'] as $key => $value) { |
441 | 441 | if ($value['name'] == $city_name) { |
442 | 442 | $city['name'] = $value['name']; |
@@ -447,7 +447,7 @@ discard block |
||
447 | 447 | } |
448 | 448 | } |
449 | 449 | if (!empty($district_name)) { |
450 | - $json_district = json_decode(file_get_contents($this->ipPath . 'district.json'), true); |
|
450 | + $json_district = json_decode(file_get_contents($this->ipPath.'district.json'), true); |
|
451 | 451 | foreach ($json_district['rows'] as $key => $value) { |
452 | 452 | if ($value['name'] == $district_name) { |
453 | 453 | $district['name'] = $value['name']; |
@@ -135,7 +135,7 @@ discard block |
||
135 | 135 | $result = Db::table($this->table) |
136 | 136 | ->where('cache_name', $this->cache_name) |
137 | 137 | ->update([ |
138 | - 'cache_value' => $cache_value + $int |
|
138 | + 'cache_value' => $cache_value+$int |
|
139 | 139 | ]); |
140 | 140 | return $result ? true : false; |
141 | 141 | } |
@@ -153,7 +153,7 @@ discard block |
||
153 | 153 | $result = Db::table($this->table) |
154 | 154 | ->where('cache_name', $this->cache_name) |
155 | 155 | ->update([ |
156 | - 'cache_value' => $cache_value - $int |
|
156 | + 'cache_value' => $cache_value-$int |
|
157 | 157 | ]); |
158 | 158 | return $result ? true : false; |
159 | 159 | } |