Skip to content

Commit

Permalink
Merge pull request #17 from aliyun/travis-ci
Browse files Browse the repository at this point in the history
Setup Travis CI
  • Loading branch information
rockuw committed Mar 2, 2016
2 parents 57b3b1c + 00e053e commit 4f6839d
Show file tree
Hide file tree
Showing 25 changed files with 178 additions and 112 deletions.
2 changes: 2 additions & 0 deletions .coveralls.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
coverage_clover: coverage.xml
json_path: coverage.json
19 changes: 19 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
language: php
php:
- 5.6
- 5.5
- 5.4
- 5.3
install:
- composer self-update
- composer install --no-interaction
script:
- php vendor/bin/phpunit
after_success:
- php vendor/bin/coveralls -v
env:
global:
- secure: SzmQ854lQmhV6ZkAG7lQNTY3CkazrXnDSb6VMwPU/sdaLGxPO159AW3fJS5d0sO/XN1P8x5WNkoA4i9soDlLBRibEEISNUM/2EMnpszsRymZ9o97PrS2IgORXTUL/OF+rpATzyNVB2p+2l9hBLiGf17exMSA5iOeY7W6E+VKPGi8TFykgbGUnLKU0h1hV3rzmtfGjOXcSpvYU/hxeZD/J/+6m5Gic9b/pNS+AbfTj7Y7Ru9tNsnyUP29V/vtEYtpQir3ZxQiSiUv9idybgGnJBOMYydJofb/mpFYHhYLSWqtMKGNLpeawmqs4z8S1Tvx5U5uzW5+h/mpzhvBaFlWGpm8t89BQxun5LVX5NiYCrV7TqaLitGp1cSpMjMDnrnSTNzk1exVz+rWZZcWS7yB9ULYA681GA8StXWk167qB7Y30iK1dFK3+2mDN2cEY+qLs8+bupDowQ4eOM+eqfhxX8F8+ouKcKomETsjiIwL+CUsIe6wjvnYFWb1YlRhbsI75bblHApflohnt6gVSJ78ZPqID+u2oUMjmIWXLTnRR2Y2tgEW8uqHeIoQ8BBntLdQDmv0BO4FpnGQIwrUUwQYeNzEM0DOr3hWZhyDR6Xvl+9H0l52xjANaSqpuTZfC3zmeFTG7kIjydvxNePRrony6XAawL9BvI7aKW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QDwmoi2AKago4PsuDs4P6Y6CeuOVpcso731GwwMNhIJcyrJJivXprQNEGsEw+9wLjU1qNYs6IIA3S/gPzFrNbdX5Wf8vxt0vLpgYvBNtPnLMejMtknuyfVzf5iKuVVoGPDTEz+ajs06+jfoPfm/4sLTaLghuVH7Adm74OpF769JQNnQYKwJuu4bNlcbLJChulCEMBOx7myqo/9O6RCTuqzHaGmVWNot4RGqRFHgJGl/JJf0WpAVitbhbRH3kGoyKb6jFM74CJbPsE7OORlJLDC3cdD3C8Pk=
- secure: Qr5NR4CVzBKCQgRgMH0x772TPJ1+brx3UCvtRNu8fi4j3p8bz+HDMjBaBDSFmEB09nunLI55/8mj88/5GXmnpFs8+CPTkcW+QZOcxg3cxpI4SNmxoB12/ZawlFHAqSUaRRE7RUWVkY3KL8tIGjEZcFyUBQ1DVNX3OMpiKs3NLtHa7oUIknyBxdSokm4kpLhSXYe7WmO0vhuZbMZE0S1EISToiBS6AdhGUEbTLJ/vNsIDY07fu6+Vh3HxVbyUFPqUZGlkZpQ+2xMJ3kiqPBMrXtRF/IhhPjORDil6Ns9SQ8/AAlaCddvYvRaT4Pjv2/aX+t3l28qI1qmryPtWXpce5UXecWGYqdRpSJc6Y/pEt4m4FeeGoEFWnSPGIs7FRmeiis8q2rojGZ18i4vI/k4iHmqEBnTlMp3SWnRb9L1adJ8ZAWln8aC88gkQXm67w7+1CxLycerbYj9H1ugqHENuHcxv4uHUcZgEENX3EWatu8i9+K2IUuU/2zcmpu7qtsziYcoyW8DOOmYpJfXGMLtmF9+pqp/Tp6i0tltFSEfmY3N8o7xvv3enLvFHsjL+3ElFdd1blUPSrvZJHgA9M3lJ+QF1RJZCpJqgPlQ0XOZK1Bf4P46zpEj01wKaK4JQrkLPRXhbBOuIJn5O6WlFJyPX4+SaBfwTzb4AvM4aUg2TgTg=
30 changes: 17 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Aliyun OSS SDK for PHP

[![Latest Stable Version](https://poser.pugx.org/aliyuncs/oss-sdk-php/v/stable)](https://packagist.org/packages/aliyuncs/oss-sdk-php)
[![Build Status](https://travis-ci.org/aliyun/aliyun-oss-php-sdk.svg?branch=master)](https://travis-ci.org/aliyun/aliyun-oss-php-sdk)
[![Coverage Status](https://coveralls.io/repos/github/aliyun/aliyun-oss-php-sdk/badge.svg?branch=master)](https://coveralls.io/github/aliyun/aliyun-oss-php-sdk?branch=master)

## 概述

阿里云对象存储(Object Storage Service,简称OSS),是阿里云对外提供的海量、安全、低成本、高可靠的云存储服务。用户可以通过调用API,在任何应用、任何时间、任何地点上传和下载数据,也可以通过用户Web控制台对数据进行简单的管理。OSS适合存放任意文件类型,适合各种网站、开发企业及开发者使用。
Expand Down Expand Up @@ -57,9 +61,9 @@ $accessKeyId = "<您从OSS获得的AccessKeyId>"; ;
$accessKeySecret = "<您从OSS获得的AccessKeySecret>";
$endpoint = "<您选定的OSS数据中心访问域名,例如oss-cn-hangzhou.aliyuncs.com>";
try {
$ossClient = new OssClient($accessKeyId, $accessKeySecret, $endpoint);
$ossClient = new OssClient($accessKeyId, $accessKeySecret, $endpoint);
} catch (OssException $e) {
print $e->getMessage();
print $e->getMessage();
}
```

Expand All @@ -73,26 +77,26 @@ $bucket = "<您使用的Bucket名字,注意命名规范>";
$object = "<您使用的Object名字,注意命名规范>";
$content = "Hello, OSS!"; // 上传的文件内容
try {
$ossClient->putObject($bucket, $object, $content);
$ossClient->putObject($bucket, $object, $content);
} catch (OssException $e) {
print $e->getMessage();
}
print $e->getMessage();
}
```

### 存储空间操作

存储空间(又称Bucket)是一个用户用来管理所存储Object的存储空间,对于用户来说是一个管理Object的单元,所有的Object都必须隶属于某个Bucket。您可以按照下面的代码新建一个Bucket:

```php
<?php
$bucket = "<您使用的Bucket名字,注意命名规范>";
try {
$ossClient->createBucket($bucket);
$ossClient->createBucket($bucket);
} catch (OssException $e) {
print $e->getMessage();
print $e->getMessage();
}
```

### 返回结果处理

OssClient提供的接口返回返回数据分为两种:
Expand All @@ -105,22 +109,22 @@ OssClient提供的接口返回返回数据分为两种:
$bucketListInfo = $ossClient->listBuckets();
$bucketList = $bucketListInfo->getBucketList();
foreach($bucketList as $bucket) {
print($bucket->getLocation() . "\t" . $bucket->getName() . "\t" . $bucket->getCreatedate() . "\n");
print($bucket->getLocation() . "\t" . $bucket->getName() . "\t" . $bucket->getCreatedate() . "\n");
}
```
上面代码中的$bucketListInfo的数据类型是 `OSS\Model\BucketListInfo`


### 运行Sample程序

1. 修改 `samples/Config.php`, 补充配置信息
2. 执行 `cd samples/ && php RunAll.php`

### 运行单元测试

1. 修改 `tests/OSS/Tests/Config.php`, 补充配置信息
2. 执行 `./vendor/bin/phpunit tests/OSS/Tests/`

### 生成API文档

1. 到根目录下,执行 `composer install`, 下载依赖的库
Expand Down
7 changes: 3 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@
}
],
"require": {
"php":">=5.3"
"php":">=5.3"
},
"require-dev" : {
"phpunit/phpunit": "~4.0",
"squizlabs/php_codesniffer": "~2.3",
"phpdocumentor/phpdocumentor" : "2.*"
"phpunit/phpunit": "~4.0",
"satooshi/php-coveralls": "~1.0"
},
"minimum-stability": "stable",
"autoload": {
Expand Down
16 changes: 16 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<phpunit>
<filter>
<whitelist>
<directory suffix=".php">./src</directory>
</whitelist>
</filter>
<logging>
<log type="coverage-clover" target="coverage.xml" />
</logging>
<testsuites>
<testsuite name="FunctionTest">
<directory>./tests</directory>
<exclude>./tests/OSS/Tests/BucketCnameTest.php</exclude>
</testsuite>
</testsuites>
</phpunit>
2 changes: 1 addition & 1 deletion src/OSS/OssClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ public function deleteBucketCors($bucket, $options = NULL)
* 为指定Bucket增加CNAME绑定
*
* @param string $bucket bucket名称
* @param CnameConfig $cnameConfig
* @param string $cname
* @param array $options
* @throws OssException
* @return null
Expand Down
3 changes: 2 additions & 1 deletion tests/OSS/Tests/BucketCnameTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public function testDeleteCname()

$ret = $this->client->getBucketCname($this->bucketName);
$this->assertEquals(1, count($ret->getCnames()));
$this->assertEquals('www.qq.com', $ret->getCnames()[0]['Domain']);
$cnames = $ret->getCnames();
$this->assertEquals('www.qq.com', $cnames[0]['Domain']);
}
}
23 changes: 15 additions & 8 deletions tests/OSS/Tests/Common.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace OSS\Tests;

require_once __DIR__ . '/../../../autoload.php';
require_once __DIR__ . '/Config.php';

use OSS\OssClient;
use OSS\Core\OssException;
Expand All @@ -15,11 +14,6 @@
*/
class Common
{
const endpoint = Config::OSS_ENDPOINT;
const accessKeyId = Config::OSS_ACCESS_ID;
const accessKeySecret = Config::OSS_ACCESS_KEY;
const bucket = Config::OSS_TEST_BUCKET;

/**
* 根据Config配置,得到一个OssClient实例
*
Expand All @@ -28,7 +22,10 @@ class Common
public static function getOssClient()
{
try {
$ossClient = new OssClient(self::accessKeyId, self::accessKeySecret, self::endpoint, false);
$ossClient = new OssClient(
getenv('OSS_ACCESS_KEY_ID'),
getenv('OSS_ACCESS_KEY_SECRET'),
getenv('OSS_ENDPOINT'), false);
} catch (OssException $e) {
printf(__FUNCTION__ . "creating OssClient instance: FAILED\n");
printf($e->getMessage() . "\n");
Expand All @@ -39,7 +36,7 @@ public static function getOssClient()

public static function getBucketName()
{
return self::bucket;
return getenv('OSS_BUCKET');
}

/**
Expand All @@ -60,4 +57,14 @@ public static function createBucket()
}
print(__FUNCTION__ . ": OK" . "\n");
}

/**
* Wait for bucket meta sync
*/
public static function waitMetaSync()
{
if (getenv('TRAVIS')) {
sleep(30);
}
}
}
16 changes: 0 additions & 16 deletions tests/OSS/Tests/Config.php

This file was deleted.

27 changes: 17 additions & 10 deletions tests/OSS/Tests/ContentTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ private function runCmd($cmd)
$this->assertEquals(0, $status);
}

private function getContentType($bucket, $object)
{
$client = Common::getOssClient();
$headers = $client->getObjectMeta($bucket, $object);
return $headers['content-type'];
}

public function testByFileName()
{
$client = Common::getOssClient();
Expand All @@ -28,7 +35,7 @@ public function testByFileName()
$this->runCmd('touch ' . $file);

$client->uploadFile($bucket, $object, $file);
$type = $client->getObjectMeta($bucket, $object)['content-type'];
$type = $this->getContentType($bucket, $object);

$this->assertEquals('text/html', $type);

Expand All @@ -37,7 +44,7 @@ public function testByFileName()
$this->runCmd('dd if=/dev/random of=' . $file . ' bs=1024 count=100');

$client->multiuploadFile($bucket, $object, $file, array('partSize' => 100));
$type = $client->getObjectMeta($bucket, $object)['content-type'];
$type = $this->getContentType($bucket, $object);

$this->assertEquals('application/json', $type);
}
Expand All @@ -49,7 +56,7 @@ public function testByObjectKey()

$object = "test/x.txt";
$client->putObject($bucket, $object, "hello world");
$type = $client->getObjectMeta($bucket, $object)['content-type'];
$type = $this->getContentType($bucket, $object);

$this->assertEquals('text/plain', $type);

Expand All @@ -58,7 +65,7 @@ public function testByObjectKey()
$this->runCmd('touch ' . $file);

$client->uploadFile($bucket, $object, $file);
$type = $client->getObjectMeta($bucket, $object)['content-type'];
$type = $this->getContentType($bucket, $object);

$this->assertEquals('text/html', $type);

Expand All @@ -67,7 +74,7 @@ public function testByObjectKey()
$this->runCmd('touch ' . $file);

$client->uploadFile($bucket, $object, $file);
$type = $client->getObjectMeta($bucket, $object)['content-type'];
$type = $this->getContentType($bucket, $object);

$this->assertEquals('text/plain', $type);

Expand All @@ -76,7 +83,7 @@ public function testByObjectKey()
$this->runCmd('dd if=/dev/random of=' . $file . ' bs=1024 count=100');

$client->multiuploadFile($bucket, $object, $file, array('partSize' => 100));
$type = $client->getObjectMeta($bucket, $object)['content-type'];
$type = $this->getContentType($bucket, $object);

$this->assertEquals('audio/mpeg', $type);

Expand All @@ -85,7 +92,7 @@ public function testByObjectKey()
$this->runCmd('dd if=/dev/random of=' . $file . ' bs=1024 count=100');

$client->multiuploadFile($bucket, $object, $file, array('partSize' => 100));
$type = $client->getObjectMeta($bucket, $object)['content-type'];
$type = $this->getContentType($bucket, $object);

$this->assertEquals('application/json', $type);
}
Expand All @@ -99,7 +106,7 @@ public function testByUser()
$client->putObject($bucket, $object, "hello world", array(
'Content-Type' => 'text/html'
));
$type = $client->getObjectMeta($bucket, $object)['content-type'];
$type = $this->getContentType($bucket, $object);

$this->assertEquals('text/html', $type);

Expand All @@ -110,7 +117,7 @@ public function testByUser()
$client->uploadFile($bucket, $object, $file, array(
'Content-Type' => 'application/json'
));
$type = $client->getObjectMeta($bucket, $object)['content-type'];
$type = $this->getContentType($bucket, $object);

$this->assertEquals('application/json', $type);

Expand All @@ -122,7 +129,7 @@ public function testByUser()
'partSize' => 100,
'Content-Type' => 'audio/mpeg'
));
$type = $client->getObjectMeta($bucket, $object)['content-type'];
$type = $this->getContentType($bucket, $object);

$this->assertEquals('audio/mpeg', $type);
}
Expand Down
11 changes: 6 additions & 5 deletions tests/OSS/Tests/CorsConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,12 @@ public function testParseValidXml()
$corsConfig->parseFromXml($this->validXml);
$this->assertEquals($this->cleanXml($this->validXml), $this->cleanXml($corsConfig->serializeToXml()));
$this->assertNotNull($corsConfig->getRules());
$this->assertNotNull($corsConfig->getRules()[0]->getAllowedHeaders());
$this->assertNotNull($corsConfig->getRules()[0]->getAllowedMethods());
$this->assertNotNull($corsConfig->getRules()[0]->getAllowedOrigins());
$this->assertNotNull($corsConfig->getRules()[0]->getExposeHeaders());
$this->assertNotNull($corsConfig->getRules()[0]->getMaxAgeSeconds());
$rules = $corsConfig->getRules();
$this->assertNotNull($rules[0]->getAllowedHeaders());
$this->assertNotNull($rules[0]->getAllowedMethods());
$this->assertNotNull($rules[0]->getAllowedOrigins());
$this->assertNotNull($rules[0]->getExposeHeaders());
$this->assertNotNull($rules[0]->getMaxAgeSeconds());
}

public function testParseValidXml2()
Expand Down
3 changes: 2 additions & 1 deletion tests/OSS/Tests/HeaderResultTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public function testGetHeader()
$result = new HeaderResult($response);
$this->assertTrue($result->isOK());
$this->assertTrue(is_array($result->getData()));
$this->assertEquals($result->getData()['key'], 'value');
$data = $result->getData();
$this->assertEquals($data['key'], 'value');
}
}
14 changes: 8 additions & 6 deletions tests/OSS/Tests/ListMultipartUploadResultTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,10 @@ public function testParseValidXml()
$this->assertEquals("xx", $listMultipartUploadInfo->getPrefix());
$this->assertEquals(1000, $listMultipartUploadInfo->getMaxUploads());
$this->assertEquals("false", $listMultipartUploadInfo->getIsTruncated());
$this->assertEquals("multipart.data", $listMultipartUploadInfo->getUploads()[0]->getKey());
$this->assertEquals("0004B999EF518A1FE585B0C9360DC4C8", $listMultipartUploadInfo->getUploads()[0]->getUploadId());
$this->assertEquals("2012-02-23T04:18:23.000Z", $listMultipartUploadInfo->getUploads()[0]->getInitiated());
$uploads = $listMultipartUploadInfo->getUploads();
$this->assertEquals("multipart.data", $uploads[0]->getKey());
$this->assertEquals("0004B999EF518A1FE585B0C9360DC4C8", $uploads[0]->getUploadId());
$this->assertEquals("2012-02-23T04:18:23.000Z", $uploads[0]->getInitiated());
}

public function testParseValidXmlWithEncodedKey()
Expand All @@ -105,8 +106,9 @@ public function testParseValidXmlWithEncodedKey()
$this->assertEquals("php+prefix", $listMultipartUploadInfo->getPrefix());
$this->assertEquals(1000, $listMultipartUploadInfo->getMaxUploads());
$this->assertEquals("true", $listMultipartUploadInfo->getIsTruncated());
$this->assertEquals("php+key-1", $listMultipartUploadInfo->getUploads()[0]->getKey());
$this->assertEquals("0004B999EF518A1FE585B0C9360DC4C8", $listMultipartUploadInfo->getUploads()[0]->getUploadId());
$this->assertEquals("2012-02-23T04:18:23.000Z", $listMultipartUploadInfo->getUploads()[0]->getInitiated());
$uploads = $listMultipartUploadInfo->getUploads();
$this->assertEquals("php+key-1", $uploads[0]->getKey());
$this->assertEquals("0004B999EF518A1FE585B0C9360DC4C8", $uploads[0]->getUploadId());
$this->assertEquals("2012-02-23T04:18:23.000Z", $uploads[0]->getInitiated());
}
}
Loading

0 comments on commit 4f6839d

Please sign in to comment.