diff --git a/.gitignore b/.gitignore index e019709..8d4386c 100644 --- a/.gitignore +++ b/.gitignore @@ -10,9 +10,11 @@ coverage #build related gulp node_modules - tests/storage/files/* tests/storage/meta/* +# Test AWS credentials +tests/src/.env + #Keep special .gitkeep file, useful for keeping empty directory structure !.gitkeep \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index 002f7f6..3408bed 100644 --- a/.travis.yml +++ b/.travis.yml @@ -22,3 +22,13 @@ script: after_script: - php vendor/bin/coveralls + +# Setup environment to pass AWS S3 credentials +env: + global: + - AWS_S3_REGION="eu-west-1" + - AWS_S3_BUCKET="github-ci-test" + - AWS_S3_BUCKET_SUBFOLDER="files" + # Encrypted AWS_S3_KEY, AWS_S3_SECRET + - secure: fyTrGJ0tuP9i+WxWSz6M7VjpzKot5Lvp1t/KDoCtjE1h5U5FBaQ/W7mITj3lja79ZLOeL6rgCNdPR+5aUPjcVGvGWTs4VsbL6AUMql5XmK3hHb25/S0LgItnsFoPpp2XuptPyjo2k1RXGJfU8ImZCCY80WscKimuIMqMukcmQWE= + - secure: GUza74BlQMzxu5UKtSXx7J0t2HOMHYVh61PC5PqPZF6IzUuI5sfEkt5WhYM3vyAZ/wMzzO0sIGZKUhWIZVG9QxTMgwdGtUGJyoz66f96ebQcRtGdPHfBGwWfUzsYtPiXBgao2KTLm0iKEGw9gST67zXBg17z11wadyiVv6NoKwc= \ No newline at end of file diff --git a/README.md b/README.md index 64bee3d..0e06223 100644 --- a/README.md +++ b/README.md @@ -111,7 +111,11 @@ There are several commands related to testing Both options have the ability to generate a code coverage report in different formats. When this is selected, a local server will be launched to visualize the coverage report +### Testing AWS S3 Driver +- Valid AWS S3 credentials need to be provided via `tests/.env` file, see `tests/.env.example` as an example. +- Travis CI integration is performed by passing encrypted credentials in travis.yml (valid only for inakianduaga/eloquent-external-storage repo). +- [Amazon S3 testing in Travis CI](http://milesj.me/blog/read/amazon-s3-testing-travis-ci) [travis-url]: https://travis-ci.org/inakianduaga/eloquent-external-storage [travis-image]: https://travis-ci.org/inakianduaga/eloquent-external-storage.svg?branch=master diff --git a/composer.json b/composer.json index 3c139ee..6de32d7 100644 --- a/composer.json +++ b/composer.json @@ -24,7 +24,8 @@ "phpunit/phpunit": "4.3.*@dev", "mockery/mockery": "dev-master", "orchestra/testbench" : "2.2.x", - "satooshi/php-coveralls": "dev-master" + "satooshi/php-coveralls": "dev-master", + "vlucas/phpdotenv" : "dev-master" }, "autoload": { "psr-4": { diff --git a/composer.lock b/composer.lock index 852c9f9..c994f40 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "2b46bb93ed61e8cc30033d7a7e0b0e29", + "hash": "c879cddf849cde295212059cbc03b358", "packages": [ { "name": "aws/aws-sdk-php", @@ -12,12 +12,12 @@ "source": { "type": "git", "url": "https://github.com/aws/aws-sdk-php.git", - "reference": "7dd429f8916eb384fcaf43c6510c519eaf3b900e" + "reference": "2d120e45f1ae4cbebd49abbc780c7d69431ee8ae" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/aws/aws-sdk-php/zipball/7dd429f8916eb384fcaf43c6510c519eaf3b900e", - "reference": "7dd429f8916eb384fcaf43c6510c519eaf3b900e", + "url": "https://api.github.com/repos/aws/aws-sdk-php/zipball/2d120e45f1ae4cbebd49abbc780c7d69431ee8ae", + "reference": "2d120e45f1ae4cbebd49abbc780c7d69431ee8ae", "shasum": "" }, "require": { @@ -71,7 +71,7 @@ "s3", "sdk" ], - "time": "2015-01-16 01:44:42" + "time": "2015-01-22 16:26:52" }, { "name": "classpreloader/classpreloader", @@ -400,12 +400,12 @@ "source": { "type": "git", "url": "https://github.com/laravel/framework.git", - "reference": "c17ed8875f37995491955c58bd0a019f12472599" + "reference": "a3579e92df4ac38f340b82ae37e2101759460c90" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laravel/framework/zipball/c17ed8875f37995491955c58bd0a019f12472599", - "reference": "c17ed8875f37995491955c58bd0a019f12472599", + "url": "https://api.github.com/repos/laravel/framework/zipball/a3579e92df4ac38f340b82ae37e2101759460c90", + "reference": "a3579e92df4ac38f340b82ae37e2101759460c90", "shasum": "" }, "require": { @@ -416,7 +416,7 @@ "jeremeamia/superclosure": "~1.0.1", "monolog/monolog": "~1.6", "nesbot/carbon": "~1.0", - "patchwork/utf8": "1.1.*", + "patchwork/utf8": "~1.1", "php": ">=5.4.0", "phpseclib/phpseclib": "0.3.*", "predis/predis": "0.8.*", @@ -507,7 +507,7 @@ "framework", "laravel" ], - "time": "2015-01-19 01:27:09" + "time": "2015-01-23 20:12:49" }, { "name": "monolog/monolog", @@ -515,12 +515,12 @@ "source": { "type": "git", "url": "https://github.com/Seldaek/monolog.git", - "reference": "b18a6eff04b15184375a6875ef2aa54bc5a7c9f2" + "reference": "ba31b79fa540d68da0e9e3269c0f85c1756ff10a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Seldaek/monolog/zipball/b18a6eff04b15184375a6875ef2aa54bc5a7c9f2", - "reference": "b18a6eff04b15184375a6875ef2aa54bc5a7c9f2", + "url": "https://api.github.com/repos/Seldaek/monolog/zipball/ba31b79fa540d68da0e9e3269c0f85c1756ff10a", + "reference": "ba31b79fa540d68da0e9e3269c0f85c1756ff10a", "shasum": "" }, "require": { @@ -579,7 +579,7 @@ "logging", "psr-3" ], - "time": "2015-01-07 15:29:03" + "time": "2015-01-20 10:31:44" }, { "name": "nesbot/carbon", @@ -674,16 +674,16 @@ }, { "name": "patchwork/utf8", - "version": "1.1.x-dev", + "version": "dev-master", "source": { "type": "git", "url": "https://github.com/tchwork/utf8.git", - "reference": "ffa082111aa3cb23cf2479a17e6785ace91da982" + "reference": "9639d28f1aa24add93ca7a0cf2a5cc3169ddb7d5" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/tchwork/utf8/zipball/ffa082111aa3cb23cf2479a17e6785ace91da982", - "reference": "ffa082111aa3cb23cf2479a17e6785ace91da982", + "url": "https://api.github.com/repos/tchwork/utf8/zipball/9639d28f1aa24add93ca7a0cf2a5cc3169ddb7d5", + "reference": "9639d28f1aa24add93ca7a0cf2a5cc3169ddb7d5", "shasum": "" }, "require": { @@ -693,9 +693,15 @@ "suggest": { "ext-iconv": "Use iconv for best performance", "ext-intl": "Use Intl for best performance", - "ext-mbstring": "Use Mbstring for best performance" + "ext-mbstring": "Use Mbstring for best performance", + "ext-wfio": "Use WFIO for UTF-8 filesystem access on Windows" }, "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.2-dev" + } + }, "autoload": { "psr-0": { "Patchwork": "class/", @@ -721,7 +727,7 @@ "utf-8", "utf8" ], - "time": "2015-01-12 08:05:15" + "time": "2015-01-12 20:01:53" }, { "name": "phpseclib/phpseclib", @@ -1072,12 +1078,12 @@ "source": { "type": "git", "url": "https://github.com/symfony/Console.git", - "reference": "b830805b02c860935f44774afbd737d9bf52bd11" + "reference": "f41807e67f00244f013bb96a66ac02f778a31209" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/Console/zipball/b830805b02c860935f44774afbd737d9bf52bd11", - "reference": "b830805b02c860935f44774afbd737d9bf52bd11", + "url": "https://api.github.com/repos/symfony/Console/zipball/f41807e67f00244f013bb96a66ac02f778a31209", + "reference": "f41807e67f00244f013bb96a66ac02f778a31209", "shasum": "" }, "require": { @@ -1118,7 +1124,7 @@ ], "description": "Symfony Console Component", "homepage": "http://symfony.com", - "time": "2015-01-10 12:50:07" + "time": "2015-01-25 04:37:39" }, { "name": "symfony/css-selector", @@ -1442,12 +1448,12 @@ "source": { "type": "git", "url": "https://github.com/symfony/HttpFoundation.git", - "reference": "cba266f6023ce3bcc2998707ddbabbd449ca703c" + "reference": "0481c0a69c23d51eee6ba329a677a1d1af425b26" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/HttpFoundation/zipball/cba266f6023ce3bcc2998707ddbabbd449ca703c", - "reference": "cba266f6023ce3bcc2998707ddbabbd449ca703c", + "url": "https://api.github.com/repos/symfony/HttpFoundation/zipball/0481c0a69c23d51eee6ba329a677a1d1af425b26", + "reference": "0481c0a69c23d51eee6ba329a677a1d1af425b26", "shasum": "" }, "require": { @@ -1486,7 +1492,7 @@ ], "description": "Symfony HttpFoundation Component", "homepage": "http://symfony.com", - "time": "2015-01-13 07:22:00" + "time": "2015-01-25 04:37:39" }, { "name": "symfony/http-kernel", @@ -1495,12 +1501,12 @@ "source": { "type": "git", "url": "https://github.com/symfony/HttpKernel.git", - "reference": "10e8ad33bc6c59b538678dae3059ed48a416d605" + "reference": "e52e53bab767c254e72bed8156b95884c6200b11" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/HttpKernel/zipball/10e8ad33bc6c59b538678dae3059ed48a416d605", - "reference": "10e8ad33bc6c59b538678dae3059ed48a416d605", + "url": "https://api.github.com/repos/symfony/HttpKernel/zipball/e52e53bab767c254e72bed8156b95884c6200b11", + "reference": "e52e53bab767c254e72bed8156b95884c6200b11", "shasum": "" }, "require": { @@ -1560,7 +1566,7 @@ ], "description": "Symfony HttpKernel Component", "homepage": "http://symfony.com", - "time": "2015-01-07 13:02:53" + "time": "2015-01-25 08:45:13" }, { "name": "symfony/process", @@ -1569,12 +1575,12 @@ "source": { "type": "git", "url": "https://github.com/symfony/Process.git", - "reference": "3309098ce4d9b5e44c04e51bf4541ea466fbe343" + "reference": "7b6632c849f87a062301e853f03f71d726520b58" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/Process/zipball/3309098ce4d9b5e44c04e51bf4541ea466fbe343", - "reference": "3309098ce4d9b5e44c04e51bf4541ea466fbe343", + "url": "https://api.github.com/repos/symfony/Process/zipball/7b6632c849f87a062301e853f03f71d726520b58", + "reference": "7b6632c849f87a062301e853f03f71d726520b58", "shasum": "" }, "require": { @@ -1607,7 +1613,7 @@ ], "description": "Symfony Process Component", "homepage": "http://symfony.com", - "time": "2015-01-05 20:58:03" + "time": "2015-01-25 04:37:39" }, { "name": "symfony/routing", @@ -1684,12 +1690,12 @@ "source": { "type": "git", "url": "https://github.com/symfony/security-core.git", - "reference": "25c64fcfcacdf90b1503073e1452999670c2cdd8" + "reference": "3a27d7b34ee62cb0fdf5ad970e7777912ef4722f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/security-core/zipball/25c64fcfcacdf90b1503073e1452999670c2cdd8", - "reference": "25c64fcfcacdf90b1503073e1452999670c2cdd8", + "url": "https://api.github.com/repos/symfony/security-core/zipball/3a27d7b34ee62cb0fdf5ad970e7777912ef4722f", + "reference": "3a27d7b34ee62cb0fdf5ad970e7777912ef4722f", "shasum": "" }, "require": { @@ -1738,7 +1744,7 @@ ], "description": "Symfony Security Component - Core Library", "homepage": "http://symfony.com", - "time": "2015-01-08 10:25:36" + "time": "2015-01-25 04:37:39" }, { "name": "symfony/translation", @@ -1985,12 +1991,12 @@ "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "5aaadd58aab6fd96200596820994641cb685f4aa" + "reference": "34cc484af1ca149188d0d9e91412191e398e0b67" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/5aaadd58aab6fd96200596820994641cb685f4aa", - "reference": "5aaadd58aab6fd96200596820994641cb685f4aa", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/34cc484af1ca149188d0d9e91412191e398e0b67", + "reference": "34cc484af1ca149188d0d9e91412191e398e0b67", "shasum": "" }, "require": { @@ -2039,7 +2045,7 @@ "testing", "xunit" ], - "time": "2015-01-15 05:45:24" + "time": "2015-01-24 10:06:35" }, { "name": "phpunit/php-file-iterator", @@ -2599,24 +2605,25 @@ "source": { "type": "git", "url": "https://github.com/sebastianbergmann/exporter.git", - "reference": "e0a5fdd64463a0d524305c733e3e4391c76cf739" + "reference": "35ab8d385eef068186c83e23ae83c96b0288b3ee" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/e0a5fdd64463a0d524305c733e3e4391c76cf739", - "reference": "e0a5fdd64463a0d524305c733e3e4391c76cf739", + "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/35ab8d385eef068186c83e23ae83c96b0288b3ee", + "reference": "35ab8d385eef068186c83e23ae83c96b0288b3ee", "shasum": "" }, "require": { - "php": ">=5.3.3" + "php": ">=5.3.3", + "sebastian/recursion-context": "~1.0" }, "require-dev": { - "phpunit/phpunit": "~4.0" + "phpunit/phpunit": "~4.4" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.0.x-dev" + "dev-master": "1.1.x-dev" } }, "autoload": { @@ -2656,7 +2663,60 @@ "export", "exporter" ], - "time": "2015-01-01 09:36:15" + "time": "2015-01-24 09:57:24" + }, + { + "name": "sebastian/recursion-context", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/recursion-context.git", + "reference": "3989662bbb30a29d20d9faa04a846af79b276252" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/3989662bbb30a29d20d9faa04a846af79b276252", + "reference": "3989662bbb30a29d20d9faa04a846af79b276252", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "require-dev": { + "phpunit/phpunit": "~4.4" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Jeff Welch", + "email": "whatthejeff@gmail.com" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + }, + { + "name": "Adam Harvey", + "email": "aharvey@php.net" + } + ], + "description": "Provides functionality to recursively process PHP variables", + "homepage": "http://www.github.com/sebastianbergmann/recursion-context", + "time": "2015-01-24 09:48:32" }, { "name": "sebastian/version", @@ -2700,12 +2760,12 @@ "source": { "type": "git", "url": "https://github.com/symfony/Config.git", - "reference": "2233b460470266caa95857d0a7401b300400b933" + "reference": "9d7f59f3d674dcf4f6d8e444e7a44b121d2959fe" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/Config/zipball/2233b460470266caa95857d0a7401b300400b933", - "reference": "2233b460470266caa95857d0a7401b300400b933", + "url": "https://api.github.com/repos/symfony/Config/zipball/9d7f59f3d674dcf4f6d8e444e7a44b121d2959fe", + "reference": "9d7f59f3d674dcf4f6d8e444e7a44b121d2959fe", "shasum": "" }, "require": { @@ -2739,7 +2799,7 @@ ], "description": "Symfony Config Component", "homepage": "http://symfony.com", - "time": "2015-01-03 16:09:48" + "time": "2015-01-25 04:42:01" }, { "name": "symfony/stopwatch", @@ -2795,12 +2855,12 @@ "source": { "type": "git", "url": "https://github.com/symfony/Yaml.git", - "reference": "f562c11a31743e3ed8d972fcadd1a90022c5c7e4" + "reference": "02ba3dc638c5d3f0ab3b47ddb74f98c11dcc0c60" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/Yaml/zipball/f562c11a31743e3ed8d972fcadd1a90022c5c7e4", - "reference": "f562c11a31743e3ed8d972fcadd1a90022c5c7e4", + "url": "https://api.github.com/repos/symfony/Yaml/zipball/02ba3dc638c5d3f0ab3b47ddb74f98c11dcc0c60", + "reference": "02ba3dc638c5d3f0ab3b47ddb74f98c11dcc0c60", "shasum": "" }, "require": { @@ -2833,7 +2893,58 @@ ], "description": "Symfony Yaml Component", "homepage": "http://symfony.com", - "time": "2015-01-16 14:55:54" + "time": "2015-01-25 04:39:35" + }, + { + "name": "vlucas/phpdotenv", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/vlucas/phpdotenv.git", + "reference": "732d2adb7d916c9593b9d58c3b0d9ebefead07aa" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/vlucas/phpdotenv/zipball/732d2adb7d916c9593b9d58c3b0d9ebefead07aa", + "reference": "732d2adb7d916c9593b9d58c3b0d9ebefead07aa", + "shasum": "" + }, + "require": { + "php": ">=5.3.2" + }, + "require-dev": { + "phpunit/phpunit": "~4.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" + } + }, + "autoload": { + "psr-0": { + "Dotenv": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD" + ], + "authors": [ + { + "name": "Vance Lucas", + "email": "vance@vancelucas.com", + "homepage": "http://www.vancelucas.com" + } + ], + "description": "Loads environment variables from `.env` to `getenv()`, `$_ENV` and `$_SERVER` automagically.", + "homepage": "http://github.com/vlucas/phpdotenv", + "keywords": [ + "dotenv", + "env", + "environment" + ], + "time": "2014-12-05 15:19:21" } ], "aliases": [], @@ -2842,7 +2953,8 @@ "aws/aws-sdk-php": 20, "phpunit/phpunit": 20, "mockery/mockery": 20, - "satooshi/php-coveralls": 20 + "satooshi/php-coveralls": 20, + "vlucas/phpdotenv": 20 }, "prefer-stable": false, "prefer-lowest": false, diff --git a/src/Drivers/AwsS3.php b/src/Drivers/AwsS3.php index f08dde6..39bc3b8 100644 --- a/src/Drivers/AwsS3.php +++ b/src/Drivers/AwsS3.php @@ -14,12 +14,6 @@ class AwsS3 extends AbstractDriver { protected $configKey = 'inakianduaga/eloquent-external-storage::awsS3'; -// /** @var string */ -// private $s3Bucket; - - /** var S3Client */ - private $s3Client; - /** * An s3 client configured instance * @var S3Client @@ -27,14 +21,12 @@ class AwsS3 extends AbstractDriver { private $s3; /** - * @param S3Client $s3Client + * Initialize the S3 Client */ - function __construct(S3Client $s3Client) { + function __construct() { parent::__construct(); - $this->s3Client = $s3Client; - $this->initializeConfiguredS3Client(); } @@ -81,7 +73,7 @@ public function fetch($path) { public function store($content) { $relativePath = $this->generateStoragePath($content); - $absolutePath = $this->getConfigRelativeKey('s3BucketSubfolder').$relativePath; + $absolutePath = $this->getConfigRelativeKey('s3BucketSubfolder').'/'.$relativePath; // Note: The S3 doesS3ObjectExist method has a problem when the object doesn't exist within the sdk, so we skip this check for now // if(! $this->doesS3ObjectExist($this->getConfigRelativeKey('s3Bucket'),, $absolutePath)) { @@ -93,7 +85,8 @@ public function store($content) )); } catch (S3Exception $e) { - echo "There was an error uploading the file.\n"; + echo "There was an error uploading the file: ". $e->getMessage().PHP_EOL; + $absolutePath = false; } // } @@ -109,28 +102,31 @@ 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"; - } - } - private function initializeConfiguredS3Client() { - $this->s3 = $this->s3Client->factory(array( + $this->s3 = S3Client::factory(array( 'key' => $this->getConfigRelativeKey('key'), 'secret' => $this->getConfigRelativeKey('secret'), 'region' => $this->getConfigRelativeKey('region'), diff --git a/src/Drivers/DriverInterface.php b/src/Drivers/DriverInterface.php index f76019e..dffcb79 100644 --- a/src/Drivers/DriverInterface.php +++ b/src/Drivers/DriverInterface.php @@ -26,7 +26,7 @@ public function fetch($path); * Stores external content for the given model * * @param string $content content to store - * @return array with the stored path, binary md5 + * @return string with the stored path */ public function store($content); diff --git a/tests/src/.env.example b/tests/src/.env.example new file mode 100644 index 0000000..473c7dd --- /dev/null +++ b/tests/src/.env.example @@ -0,0 +1,9 @@ +# ----------------------------------------------------------- +# Test AWS Driver credentials +# ----------------------------------------------------------- + +AWS_S3_REGION=eu-west-1 +AWS_S3_BUCKET=github-ci-test +AWS_S3_BUCKET_SUBFOLDER=files +AWS_S3_KEY=S3_KEY_HERE +AWS_S3_SECRET=S3_SECRET_HERE \ No newline at end of file diff --git a/tests/src/Drivers/AwsS3Test.php b/tests/src/Drivers/AwsS3Test.php new file mode 100644 index 0000000..ddf32d7 --- /dev/null +++ b/tests/src/Drivers/AwsS3Test.php @@ -0,0 +1,97 @@ +refreshDriver(); + + $this->content = $this->generateRandomContent(); + } + + //-----------// + //-- Tests --// + //-----------// + + public function testStoreAndFetch() + { + $storedPath = $this->storageDriver->store($this->content); + + $this->assertTrue(!empty($storedPath)); + + $content = $this->storageDriver->fetch($storedPath); + + $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); + } + + + //---------------------// + //-- Private Methods --// + //---------------------// + + /** + * Sets a clean storage driver with configuration & credentials read from environment + */ + private function refreshDriver() + { + 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() + { + return substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, 20); + } + + +} + diff --git a/tests/src/bootstrap.php b/tests/src/bootstrap.php index f9e66dc..fd48d0d 100644 --- a/tests/src/bootstrap.php +++ b/tests/src/bootstrap.php @@ -19,3 +19,16 @@ //For some reasons the drivers folder is not added by composer automatically, so we require the files here manually require_once("src/Drivers/DriverInterface.php"); require_once("src/Drivers/File.php"); + + +/* +|-------------------------------------------------------------------------- +| Loads test env variables +|-------------------------------------------------------------------------- +| +| Except when the environment is flagged as CI, such as when building in Travis +*/ + +if(!getenv('CI')) { + Dotenv::load(__DIR__); +}