Skip to content

Commit 5cdceba

Browse files
authored
Merge pull request #3 from sters/fix-issue-2
2 parents 9352e1f + 8a66016 commit 5cdceba

File tree

5 files changed

+50
-29
lines changed

5 files changed

+50
-29
lines changed

.circleci/config.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
version: 2
2+
jobs:
3+
build:
4+
docker:
5+
- image: circleci/php:5.6-apache-jessie-node-browsers
6+
working_directory: ~/repo
7+
steps:
8+
- run: sudo apt-get install libicu-dev libmcrypt-dev
9+
- run: sudo docker-php-ext-install intl && sudo docker-php-ext-install mcrypt
10+
- checkout
11+
- restore_cache:
12+
keys:
13+
- v1-dependencies-{{ checksum "composer.json" }}
14+
- run: composer install
15+
- save_cache:
16+
paths:
17+
- vendor
18+
key: v1-dependencies-{{ checksum "composer.json" }}
19+
- run: composer test

README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ one Datasrouce has one S3 Bucket connection.
3131
'key' => 'put your s3 access key',
3232
'secret' => 'put your s3 access secret',
3333
'bucketName' => 'put your bucket name',
34+
'region' => 'put your region',
3435
],
3536
],
3637
```
@@ -42,7 +43,7 @@ Setup new table using s3 connection.
4243

4344
```
4445
<?php
45-
namespace App\Model\Table\;
46+
namespace App\Model\Table;
4647
4748
use CakeS3\Datasource\AwsS3Table;
4849
@@ -52,7 +53,7 @@ class MyS3Table extends AwsS3Table
5253
}
5354
```
5455

55-
For example, declare action of get & show S3 Object.
56+
For example, declare action of get & show S3 Object.
5657

5758
```
5859
class TopController extends Controller
@@ -61,10 +62,10 @@ class TopController extends Controller
6162
{
6263
$MyS3Table = TableRegistry::get('MyS3');
6364
$content = $MyS3Table->getObjectBody('/path/to/object/file.jpg');
64-
65+
6566
$this->response->type('image/jpeg');
6667
$this->response->body($content);
67-
68+
6869
return $this->response;
6970
}
7071
}
@@ -77,7 +78,7 @@ class TopController extends Controller
7778

7879
The methods can call on your S3 Table.
7980

80-
If You want more detail, go to S3Client document.
81+
If You want more detail, go to S3Client document.
8182
[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)
8283

8384
#### ```copyObject(string $srcKey, string $destKey, array $options = []) : \Aws\Result```

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"aws/aws-sdk-php": "~3.18"
2121
},
2222
"require-dev": {
23-
"phpunit/phpunit": "*",
23+
"phpunit/phpunit": "~5.6",
2424
"cakephp/cakephp": "~3.2",
2525
"cakephp/cakephp-codesniffer": "dev-master",
2626
"mockery/mockery": "dev-master"

src/Datasource/Connection.php

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,8 @@ public function __construct(array $config = [])
4242
]);
4343
$this->_s3Client->registerStreamWrapper();
4444

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

5049
/**
@@ -107,6 +106,27 @@ public function logger($instance = null)
107106
{
108107
}
109108

109+
/**
110+
* This method is not supported.
111+
*
112+
* @return \Cake\Database\Log\QueryLogger logger instance
113+
*/
114+
public function getLogger()
115+
{
116+
return new \Cake\Database\Log\QueryLogger();
117+
}
118+
119+
/**
120+
* This method is not supported.
121+
*
122+
* @param \Cake\Database\Log\QueryLogger $logger Logger object
123+
* @return $this
124+
*/
125+
public function setLogger($logger)
126+
{
127+
return $this;
128+
}
129+
110130
/**
111131
* Pre processing to convert the key.
112132
* ex) '/key' => 'key'

tests/TestCase/Datasource/ConnectionTest.php

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ private function __getS3ClientMock()
2828
$mock = m::mock('overload:\Aws\S3\S3Client');
2929
$mock->shouldReceive('registerStreamWrapper')
3030
->once();
31-
$mock->shouldReceive('doesBucketExist')
31+
$mock->shouldReceive('getCommand')
3232
->once()
3333
->andReturn(true);
3434

@@ -78,25 +78,6 @@ public function testNewInstanceMissingArguments()
7878
new Connection($params);
7979
}
8080

81-
/**
82-
* Test new instance failed, missing bucket
83-
*
84-
* @return void
85-
*/
86-
public function testNewInstanceBucketIsNotExist()
87-
{
88-
$this->expectException(\InvalidArgumentException::class);
89-
90-
$mock = m::mock('overload:Aws\S3\S3Client');
91-
$mock->shouldReceive('registerStreamWrapper')
92-
->once();
93-
$mock->shouldReceive('doesBucketExist')
94-
->once()
95-
->andReturn(false);
96-
97-
$this->__getConnectionInstance();
98-
}
99-
10081
/**
10182
* Test copyObject method
10283
*/

0 commit comments

Comments
 (0)