Skip to content

Commit

Permalink
#20: Added store/remove/fetch aws s3 methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Inaki Anduaga committed Jan 26, 2015
1 parent c1722ef commit e3eb1cd
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 25 deletions.
37 changes: 19 additions & 18 deletions src/Drivers/AwsS3.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ public function store($content)
}
catch (S3Exception $e) {
echo "There was an error uploading the file: ". $e->getMessage().PHP_EOL;
$absolutePath = false;
}
// }

Expand All @@ -101,24 +102,24 @@ public function remove($path)
);
}

/**
* Checks whether an S3 object exists
*
* @param string $bucket
* @param string $key
*
* @return bool
* @throws S3Exception if there is a problem
*/
private function doesS3ObjectExist($bucket, $key)
{
try {
return $this->s3->doesObjectExist($bucket, $key);
}
catch (S3Exception $e) {
echo "There was a problem trying to locate S3 object: $key.\n";
}
}
// /**
// * Checks whether an S3 object exists
// *
// * @param string $bucket
// * @param string $key
// *
// * @return bool
// * @throws S3Exception if there is a problem
// */
// private function doesS3ObjectExist($bucket, $key)
// {
// try {
// return $this->s3->doesObjectExist($bucket, $key);
// }
// catch (S3Exception $e) {
// echo "There was a problem trying to locate S3 object: $key.\n";
// }
// }

/**
*
Expand Down
15 changes: 8 additions & 7 deletions tests/src/Drivers/AwsS3Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use InakiAnduaga\EloquentExternalStorage\Drivers\AwsS3 as StorageDriver;
use Aws\S3\S3Client;
use Illuminate\Support\Facades\Config;
use \Aws\S3\Exception\S3Exception;

class AwsS3Test extends BaseTestCase {

Expand Down Expand Up @@ -43,7 +44,6 @@ public function setUp()
public function testStoreAndFetch()
{
$storedPath = $this->storageDriver->store($this->content);
var_dump($storedPath);

$this->assertTrue(!empty($storedPath));

Expand All @@ -52,15 +52,16 @@ public function testStoreAndFetch()
$this->assertEquals($content, $this->content);
}

/**
* @expectedException \Aws\S3\Exception\AccessDeniedException
*/
public function testRemove()
{
$storedPath = $this->storageDriver->store($this->content);

$this->storageDriver->remove($storedPath);

$content = $this->storageDriver->fetch($storedPath);

//HERE THERE SHOULD BE SOME EXCEPTION OR ERROR SINCE THE FILE SHOULDN'T BE REACHABLE
}


Expand All @@ -73,17 +74,17 @@ public function testRemove()
*/
private function refreshDriver()
{
// Inject new file driver and mock config
$this->storageDriver = new StorageDriver();
$this->storageDriver->setConfigKey('mocked.config.key');

Config::set('mocked.config.key', array(
'key' => getenv('AWS_S3_KEY'), // Your AWS Access Key ID
'secret' => getenv('AWS_S3_SECRET'), // Your AWS Secret Access Key
'region' => getenv('AWS_S3_REGION'),
's3Bucket' => getenv('AWS_S3_BUCKET'),
's3BucketSubfolder' => getenv('AWS_S3_BUCKET_SUBFOLDER'),
));

// Inject new file driver and mock config
$this->storageDriver = new StorageDriver();
$this->storageDriver->setConfigKey('mocked.config.key');
}

private function generateRandomContent()
Expand Down

0 comments on commit e3eb1cd

Please sign in to comment.