Skip to content

Commit

Permalink
Merge pull request #3 from sters/fix-issue-2
Browse files Browse the repository at this point in the history
  • Loading branch information
sters committed May 12, 2018
2 parents 9352e1f + 8a66016 commit 5cdceba
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 29 deletions.
19 changes: 19 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
version: 2
jobs:
build:
docker:
- image: circleci/php:5.6-apache-jessie-node-browsers
working_directory: ~/repo
steps:
- run: sudo apt-get install libicu-dev libmcrypt-dev
- run: sudo docker-php-ext-install intl && sudo docker-php-ext-install mcrypt
- checkout
- restore_cache:
keys:
- v1-dependencies-{{ checksum "composer.json" }}
- run: composer install
- save_cache:
paths:
- vendor
key: v1-dependencies-{{ checksum "composer.json" }}
- run: composer test
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ one Datasrouce has one S3 Bucket connection.
'key' => 'put your s3 access key',
'secret' => 'put your s3 access secret',
'bucketName' => 'put your bucket name',
'region' => 'put your region',
],
],
```
Expand All @@ -42,7 +43,7 @@ Setup new table using s3 connection.

```
<?php
namespace App\Model\Table\;
namespace App\Model\Table;
use CakeS3\Datasource\AwsS3Table;
Expand All @@ -52,7 +53,7 @@ class MyS3Table extends AwsS3Table
}
```

For example, declare action of get & show S3 Object.
For example, declare action of get & show S3 Object.

```
class TopController extends Controller
Expand All @@ -61,10 +62,10 @@ class TopController extends Controller
{
$MyS3Table = TableRegistry::get('MyS3');
$content = $MyS3Table->getObjectBody('/path/to/object/file.jpg');
$this->response->type('image/jpeg');
$this->response->body($content);
return $this->response;
}
}
Expand All @@ -77,7 +78,7 @@ class TopController extends Controller

The methods can call on your S3 Table.

If You want more detail, go to S3Client document.
If You want more detail, go to S3Client document.
[http://docs.aws.amazon.com/aws-sdk-php/v3/api/class-Aws.S3.S3Client.html](http://docs.aws.amazon.com/aws-sdk-php/v3/api/class-Aws.S3.S3Client.html)

#### ```copyObject(string $srcKey, string $destKey, array $options = []) : \Aws\Result```
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"aws/aws-sdk-php": "~3.18"
},
"require-dev": {
"phpunit/phpunit": "*",
"phpunit/phpunit": "~5.6",
"cakephp/cakephp": "~3.2",
"cakephp/cakephp-codesniffer": "dev-master",
"mockery/mockery": "dev-master"
Expand Down
26 changes: 23 additions & 3 deletions src/Datasource/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,8 @@ public function __construct(array $config = [])
]);
$this->_s3Client->registerStreamWrapper();

if ($this->_s3Client->doesBucketExist($this->_config['bucketName']) === false) {
throw new \InvalidArgumentException("Bucket '{$this->_config['bucketName']}' is not found.");
}
// check has bucket
$this->_s3Client->getCommand('HeadBucket', ['Bucket' => $this->_config['bucketName']]);
}

/**
Expand Down Expand Up @@ -107,6 +106,27 @@ public function logger($instance = null)
{
}

/**
* This method is not supported.
*
* @return \Cake\Database\Log\QueryLogger logger instance
*/
public function getLogger()
{
return new \Cake\Database\Log\QueryLogger();
}

/**
* This method is not supported.
*
* @param \Cake\Database\Log\QueryLogger $logger Logger object
* @return $this
*/
public function setLogger($logger)
{
return $this;
}

/**
* Pre processing to convert the key.
* ex) '/key' => 'key'
Expand Down
21 changes: 1 addition & 20 deletions tests/TestCase/Datasource/ConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ private function __getS3ClientMock()
$mock = m::mock('overload:\Aws\S3\S3Client');
$mock->shouldReceive('registerStreamWrapper')
->once();
$mock->shouldReceive('doesBucketExist')
$mock->shouldReceive('getCommand')
->once()
->andReturn(true);

Expand Down Expand Up @@ -78,25 +78,6 @@ public function testNewInstanceMissingArguments()
new Connection($params);
}

/**
* Test new instance failed, missing bucket
*
* @return void
*/
public function testNewInstanceBucketIsNotExist()
{
$this->expectException(\InvalidArgumentException::class);

$mock = m::mock('overload:Aws\S3\S3Client');
$mock->shouldReceive('registerStreamWrapper')
->once();
$mock->shouldReceive('doesBucketExist')
->once()
->andReturn(false);

$this->__getConnectionInstance();
}

/**
* Test copyObject method
*/
Expand Down

0 comments on commit 5cdceba

Please sign in to comment.