Skip to content

Commit f36676e

Browse files
author
PenaFong
committed
Merge branch 'feature/testcase' into 'develop'
Feature/testcase 添加测试用例 @PenaFong See merge request !4
2 parents 6787a35 + b36e99f commit f36676e

File tree

5 files changed

+120
-0
lines changed

5 files changed

+120
-0
lines changed

phpunit.xml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<phpunit backupGlobals="true"
2+
backupStaticAttributes="false"
3+
colors="true"
4+
convertErrorsToExceptions="true"
5+
convertNoticesToExceptions="true"
6+
convertWarningsToExceptions="true"
7+
processIsolation="false"
8+
stopOnFailure="false"
9+
syntaxCheck="false"
10+
bootstrap="tests/bootstrap.php">
11+
<testsuites>
12+
<testsuite name="upyun test cases">
13+
<directory>./tests/</directory>
14+
</testsuite>
15+
</testsuites>
16+
<filter>
17+
<whitelist>
18+
<file>./upyun.class.php</file>
19+
</whitelist>
20+
</filter>
21+
</phpunit>
File renamed without changes.

tests/bootstrap.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
require_once './tests/config.php';
3+
require_once './upyun.class.php';
4+
5+
define('USER_NAME', $config['user_name']);
6+
define('PWD', $config['pwd']);
7+
define('BUCKET', $config['bucket']);
8+
9+
define('PIC_PATH' , $config['picture_path']);

tests/config.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
$config = array(
3+
'user_name' => 'tester',
4+
'pwd' => 'grjxv2mxELR3',
5+
'bucket' => 'sdkimg',
6+
'picture_path' => dirname(__FILE__) . '/assets/sample.jpeg'
7+
);

tests/upyunTest.php

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<?php
2+
3+
class unyunTest extends PHPUnit_Framework_TestCase
4+
{
5+
6+
public function setUp(){
7+
$this->upyun = new UpYun(BUCKET, USER_NAME, PWD);
8+
}
9+
10+
public function testMakeDir(){
11+
$rsp = $this->upyun->makeDir('/demo/');
12+
$this->assertTrue(true);
13+
}
14+
/**
15+
* 直接上传文件
16+
*/
17+
public function testDirectUpload()
18+
{
19+
$fh = fopen(PIC_PATH, 'rb');
20+
$rsp = $this->upyun->writeFile('/demo/sample_normal.jpeg', $fh, True); // 上传图片,自动创建目录
21+
fclose($fh);
22+
$this->assertTrue(true , is_array($rsp));
23+
}
24+
/**
25+
* 直接生成缩略图,不保存原图片,仅对图片文件有效
26+
*/
27+
public function testWriteFile1(){
28+
$opts = array(
29+
UpYun::X_GMKERL_TYPE => 'square', // 缩略图类型
30+
UpYun::X_GMKERL_VALUE => 150, // 缩略图大小
31+
UpYun::X_GMKERL_QUALITY => 95, // 缩略图压缩质量
32+
UpYun::X_GMKERL_UNSHARP => True // 是否进行锐化处理
33+
);
34+
$fh = fopen(PIC_PATH, 'rb');
35+
$rsp = $this->upyun->writeFile('/demo/sample_thumb_1.jpeg', $fh, True, $opts); // 上传图片,自动创建目录
36+
fclose($fh);
37+
$this->assertTrue(is_array($rsp));
38+
}
39+
/**
40+
* 按照预先设置的缩略图类型生成缩略图类型生成缩略图,不保存原图,仅对图片空间有效
41+
*/
42+
public function testWriteFile2(){
43+
$opts = array(
44+
UpYun::X_GMKERL_THUMBNAIL => 'thumbtype'
45+
);
46+
$fh = fopen(PIC_PATH, 'rb');
47+
$rsp = $this->upyun->writeFile('/demo/sample_thumb_2.jpeg', $fh, True, $opts); // 上传图片,自动创建目录
48+
fclose($fh);
49+
$this->assertTrue(is_array($rsp));
50+
}
51+
/**
52+
* 获取空间的使用情况
53+
*/
54+
public function testUsage(){
55+
$rsp = $this->upyun->getFolderUsage('/demo/');
56+
$this->assertTrue(is_float($rsp));
57+
}
58+
/**
59+
* 获取指定文件的目录信息
60+
*/
61+
public function testFileInfo(){
62+
$rsp = $this->upyun->getFolderUsage('/demo/sample_normal.jpeg');
63+
$this->assertTrue(is_float($rsp));
64+
}
65+
/**
66+
* 获取目录文件列表
67+
*/
68+
public function testList(){
69+
$rsp = $this->upyun->getList('/demo/');
70+
$this->assertTrue(is_array($rsp));
71+
}
72+
/**
73+
* 删除空间目录
74+
* @expectedException \Exception
75+
* @depends testMakeDir
76+
*/
77+
public function testDelete()
78+
{
79+
$rsp = $this->upyun->delete('/demo/');
80+
$this->assertTrue($rsp);
81+
}
82+
83+
}

0 commit comments

Comments
 (0)