Skip to content

Commit

Permalink
Added document about how to use
Browse files Browse the repository at this point in the history
  • Loading branch information
limingxinleo committed Jul 6, 2021
1 parent fc54542 commit ebf396f
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,20 @@ composer require hyperf/flysystem-oss

## 使用

```php
<?php

$adapter = new Adapter([
'accessId' => env('OSS_ACCESS_ID'),
'accessSecret' => env('OSS_ACCESS_SECRET'),
'bucket' => env('OSS_BUCKET'),
'endpoint' => env('OSS_ENDPOINT'),
'timeout' => 3600,
'connectTimeout' => 10,
'isCName' => false,
'token' => null,
'proxy' => null,
]);
$flysystem = new Filesystem($adapter);
$flysystem->write('test.json', Json::encode(['id' => uniqid()]));
```
31 changes: 31 additions & 0 deletions tests/Cases/OssAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,37 @@ public function testDelete()
$this->assertNull($flysystem->delete('test.json'));
}

public function testSetTimeout()
{
$container = $this->getContainer();
$container->shouldReceive('make')->with(OssClient::class, Mockery::any())->andReturnUsing(function ($_, $args) {
$client = Mockery::mock(OssClient::class);
$client->shouldReceive('setTimeout')->with(3600)->once()->andReturnNull();
$client->shouldReceive('setConnectTimeout')->with(10)->once()->andReturnNull();
return $client;
});
$adapter = new Adapter($this->getDefaultOptions());
new Filesystem($adapter);

$container = $this->getContainer();
$container->shouldReceive('make')->with(OssClient::class, Mockery::any())->andReturnUsing(function ($_, $args) {
$client = Mockery::mock(OssClient::class);
$client->shouldReceive('setTimeout')->with(1000)->once()->andReturnNull();
$client->shouldReceive('setConnectTimeout')->with(20)->once()->andReturnNull();
return $client;
});
$adapter = new Adapter([
'accessId' => 'xxx',
'accessSecret' => 'xxx',
'bucket' => $this->bucket,
'endpoint' => 'oss-cn-qingdao.aliyuncs.com',
'timeout' => 1000,
'connectTimeout' => 20,
]);
new Filesystem($adapter);
$this->assertTrue(true);
}

protected function getDefaultOssClient()
{
$client = Mockery::mock(OssClient::class);
Expand Down

0 comments on commit ebf396f

Please sign in to comment.