From 3e1acd5f844df804b32f1305c6587c14706437e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Gallego?= Date: Thu, 28 May 2015 22:18:12 +0200 Subject: [PATCH 1/5] Initial commit --- CHANGELOG.md | 5 +++ composer.json | 15 ++++--- config/module.config.php | 45 ++++++++++--------- src/{Aws => }/Factory/AwsFactory.php | 0 .../CloudFrontLinkViewHelperFactory.php | 0 .../DynamoDbSessionSaveHandlerFactory.php | 0 .../Factory/S3LinkViewHelperFactory.php | 0 .../Factory/S3RenameUploadFactory.php | 0 .../Exception/MissingBucketException.php | 0 src/{Aws => }/Filter/File/S3RenameUpload.php | 0 .../Session/SaveHandler/DynamoDb.php | 0 .../Exception/InvalidDomainNameException.php | 0 .../View/Exception/InvalidSchemeException.php | 0 .../View/Helper/AbstractLinkHelper.php | 0 src/{Aws => }/View/Helper/CloudFrontLink.php | 0 src/{Aws => }/View/Helper/S3Link.php | 0 tests/{Aws => }/Tests/BaseModuleTest.php | 0 .../Tests/Factory/AwsFactoryTest.php | 0 .../DynamoDbSessionSaveHandlerFactoryTest.php | 0 .../Tests/Filter/File/S3RenameUploadTest.php | 0 tests/{Aws => }/Tests/ModuleTest.php | 0 .../Session/SaveHandler/DynamoDbTest.php | 0 .../Tests/View/Helper/CloudFrontLinkTest.php | 0 .../Tests/View/Helper/S3LinkTest.php | 0 24 files changed, 40 insertions(+), 25 deletions(-) rename src/{Aws => }/Factory/AwsFactory.php (100%) rename src/{Aws => }/Factory/CloudFrontLinkViewHelperFactory.php (100%) rename src/{Aws => }/Factory/DynamoDbSessionSaveHandlerFactory.php (100%) rename src/{Aws => }/Factory/S3LinkViewHelperFactory.php (100%) rename src/{Aws => }/Factory/S3RenameUploadFactory.php (100%) rename src/{Aws => }/Filter/Exception/MissingBucketException.php (100%) rename src/{Aws => }/Filter/File/S3RenameUpload.php (100%) rename src/{Aws => }/Session/SaveHandler/DynamoDb.php (100%) rename src/{Aws => }/View/Exception/InvalidDomainNameException.php (100%) rename src/{Aws => }/View/Exception/InvalidSchemeException.php (100%) rename src/{Aws => }/View/Helper/AbstractLinkHelper.php (100%) rename src/{Aws => }/View/Helper/CloudFrontLink.php (100%) rename src/{Aws => }/View/Helper/S3Link.php (100%) rename tests/{Aws => }/Tests/BaseModuleTest.php (100%) rename tests/{Aws => }/Tests/Factory/AwsFactoryTest.php (100%) rename tests/{Aws => }/Tests/Factory/DynamoDbSessionSaveHandlerFactoryTest.php (100%) rename tests/{Aws => }/Tests/Filter/File/S3RenameUploadTest.php (100%) rename tests/{Aws => }/Tests/ModuleTest.php (100%) rename tests/{Aws => }/Tests/Session/SaveHandler/DynamoDbTest.php (100%) rename tests/{Aws => }/Tests/View/Helper/CloudFrontLinkTest.php (100%) rename tests/{Aws => }/Tests/View/Helper/S3LinkTest.php (100%) diff --git a/CHANGELOG.md b/CHANGELOG.md index e0cae80..4c65cc9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,11 @@ CHANGELOG ========= +## 2.0.0 + +* [BC] PHP minimum version is now 5.5 +* [BC] Now require Aws SDK v3 + ## 1.2.0 * Added the ability to create protocol-relative URLs with the S3 and CloudFront link view helpers diff --git a/composer.json b/composer.json index eaea721..e68eca4 100644 --- a/composer.json +++ b/composer.json @@ -3,10 +3,10 @@ "description": "Zend Framework 2 Module that allows easy integration the AWS SDK for PHP", "type": "library", "license": "Apache", - "keywords": ["aws", "zf2", "amazon", "zend", "s3", "dynamodb", "ec2", "cloudfront"], + "keywords": ["aws", "zf2", "amazon", "zend", "s3", "dynamodb", "ec2", "cloudfront", "sqs"], "require": { - "php": ">=5.3.3", - "aws/aws-sdk-php": "2.*", + "php": ">=5.5", + "aws/aws-sdk-php": "3.*", "zendframework/zend-filter": "2.*", "zendframework/zend-servicemanager": "2.*", "zendframework/zend-session": "2.*", @@ -14,15 +14,20 @@ "zendframework/zend-view": "2.*" }, "require-dev": { - "phpunit/phpunit": "3.7.*", + "phpunit/phpunit": "4.*", "zendframework/zend-modulemanager": "2.*" }, "autoload": { - "psr-0": { + "psr-4": { "Aws\\": "src/" }, "classmap": [ "./Module.php" ] + }, + "autoload-dev": { + "psr-4": { + "AwsTest\\": "tests/" + } } } diff --git a/config/module.config.php b/config/module.config.php index b5a4845..85c0e32 100644 --- a/config/module.config.php +++ b/config/module.config.php @@ -1,31 +1,36 @@ array( - 'factories' => array( - 'Aws' => 'Aws\Factory\AwsFactory', - 'Aws\Session\SaveHandler\DynamoDb' => 'Aws\Factory\DynamoDbSessionSaveHandlerFactory' - ) - ), +use Aws\Factory\AwsFactory; +use Aws\Factory\DynamoDbSessionSaveHandlerFactory; +use Aws\Sdk as Aws; +use Aws\Session\SaveHandler\DynamoDb as DynamoDbSaveHandler; - 'filters' => array( - 'factories' => array( +return [ + 'service_manager' => [ + 'factories' => [ + Aws::class => AwsFactory::class, + DynamoDbSaveHandler::class => DynamoDbSessionSaveHandlerFactory::class + ] + ], + + 'filters' => [ + 'factories' => [ 'Aws\Filter\File\S3RenameUpload' => 'Aws\Factory\S3RenameUploadFactory' - ), - 'aliases' => array( + ], + 'aliases' => [ 's3renameupload' => 'Aws\Filter\File\S3RenameUpload' - ) - ), + ] + ], - 'view_helpers' => array( - 'factories' => array( + 'view_helpers' => [ + 'factories' => [ 'Aws\View\Helper\S3Link' => 'Aws\Factory\S3LinkViewHelperFactory', 'Aws\View\Helper\CloudFrontLink' => 'Aws\Factory\CloudFrontLinkViewHelperFactory' - ), + ], - 'aliases' => array( + 'aliases' => [ 'cloudfrontlink' => 'Aws\View\Helper\CloudFrontLink', 's3link' => 'Aws\View\Helper\S3Link' - ) - ), -); + ] + ], +]; diff --git a/src/Aws/Factory/AwsFactory.php b/src/Factory/AwsFactory.php similarity index 100% rename from src/Aws/Factory/AwsFactory.php rename to src/Factory/AwsFactory.php diff --git a/src/Aws/Factory/CloudFrontLinkViewHelperFactory.php b/src/Factory/CloudFrontLinkViewHelperFactory.php similarity index 100% rename from src/Aws/Factory/CloudFrontLinkViewHelperFactory.php rename to src/Factory/CloudFrontLinkViewHelperFactory.php diff --git a/src/Aws/Factory/DynamoDbSessionSaveHandlerFactory.php b/src/Factory/DynamoDbSessionSaveHandlerFactory.php similarity index 100% rename from src/Aws/Factory/DynamoDbSessionSaveHandlerFactory.php rename to src/Factory/DynamoDbSessionSaveHandlerFactory.php diff --git a/src/Aws/Factory/S3LinkViewHelperFactory.php b/src/Factory/S3LinkViewHelperFactory.php similarity index 100% rename from src/Aws/Factory/S3LinkViewHelperFactory.php rename to src/Factory/S3LinkViewHelperFactory.php diff --git a/src/Aws/Factory/S3RenameUploadFactory.php b/src/Factory/S3RenameUploadFactory.php similarity index 100% rename from src/Aws/Factory/S3RenameUploadFactory.php rename to src/Factory/S3RenameUploadFactory.php diff --git a/src/Aws/Filter/Exception/MissingBucketException.php b/src/Filter/Exception/MissingBucketException.php similarity index 100% rename from src/Aws/Filter/Exception/MissingBucketException.php rename to src/Filter/Exception/MissingBucketException.php diff --git a/src/Aws/Filter/File/S3RenameUpload.php b/src/Filter/File/S3RenameUpload.php similarity index 100% rename from src/Aws/Filter/File/S3RenameUpload.php rename to src/Filter/File/S3RenameUpload.php diff --git a/src/Aws/Session/SaveHandler/DynamoDb.php b/src/Session/SaveHandler/DynamoDb.php similarity index 100% rename from src/Aws/Session/SaveHandler/DynamoDb.php rename to src/Session/SaveHandler/DynamoDb.php diff --git a/src/Aws/View/Exception/InvalidDomainNameException.php b/src/View/Exception/InvalidDomainNameException.php similarity index 100% rename from src/Aws/View/Exception/InvalidDomainNameException.php rename to src/View/Exception/InvalidDomainNameException.php diff --git a/src/Aws/View/Exception/InvalidSchemeException.php b/src/View/Exception/InvalidSchemeException.php similarity index 100% rename from src/Aws/View/Exception/InvalidSchemeException.php rename to src/View/Exception/InvalidSchemeException.php diff --git a/src/Aws/View/Helper/AbstractLinkHelper.php b/src/View/Helper/AbstractLinkHelper.php similarity index 100% rename from src/Aws/View/Helper/AbstractLinkHelper.php rename to src/View/Helper/AbstractLinkHelper.php diff --git a/src/Aws/View/Helper/CloudFrontLink.php b/src/View/Helper/CloudFrontLink.php similarity index 100% rename from src/Aws/View/Helper/CloudFrontLink.php rename to src/View/Helper/CloudFrontLink.php diff --git a/src/Aws/View/Helper/S3Link.php b/src/View/Helper/S3Link.php similarity index 100% rename from src/Aws/View/Helper/S3Link.php rename to src/View/Helper/S3Link.php diff --git a/tests/Aws/Tests/BaseModuleTest.php b/tests/Tests/BaseModuleTest.php similarity index 100% rename from tests/Aws/Tests/BaseModuleTest.php rename to tests/Tests/BaseModuleTest.php diff --git a/tests/Aws/Tests/Factory/AwsFactoryTest.php b/tests/Tests/Factory/AwsFactoryTest.php similarity index 100% rename from tests/Aws/Tests/Factory/AwsFactoryTest.php rename to tests/Tests/Factory/AwsFactoryTest.php diff --git a/tests/Aws/Tests/Factory/DynamoDbSessionSaveHandlerFactoryTest.php b/tests/Tests/Factory/DynamoDbSessionSaveHandlerFactoryTest.php similarity index 100% rename from tests/Aws/Tests/Factory/DynamoDbSessionSaveHandlerFactoryTest.php rename to tests/Tests/Factory/DynamoDbSessionSaveHandlerFactoryTest.php diff --git a/tests/Aws/Tests/Filter/File/S3RenameUploadTest.php b/tests/Tests/Filter/File/S3RenameUploadTest.php similarity index 100% rename from tests/Aws/Tests/Filter/File/S3RenameUploadTest.php rename to tests/Tests/Filter/File/S3RenameUploadTest.php diff --git a/tests/Aws/Tests/ModuleTest.php b/tests/Tests/ModuleTest.php similarity index 100% rename from tests/Aws/Tests/ModuleTest.php rename to tests/Tests/ModuleTest.php diff --git a/tests/Aws/Tests/Session/SaveHandler/DynamoDbTest.php b/tests/Tests/Session/SaveHandler/DynamoDbTest.php similarity index 100% rename from tests/Aws/Tests/Session/SaveHandler/DynamoDbTest.php rename to tests/Tests/Session/SaveHandler/DynamoDbTest.php diff --git a/tests/Aws/Tests/View/Helper/CloudFrontLinkTest.php b/tests/Tests/View/Helper/CloudFrontLinkTest.php similarity index 100% rename from tests/Aws/Tests/View/Helper/CloudFrontLinkTest.php rename to tests/Tests/View/Helper/CloudFrontLinkTest.php diff --git a/tests/Aws/Tests/View/Helper/S3LinkTest.php b/tests/Tests/View/Helper/S3LinkTest.php similarity index 100% rename from tests/Aws/Tests/View/Helper/S3LinkTest.php rename to tests/Tests/View/Helper/S3LinkTest.php From c2b742e09ba3f9a286f6206aae67069b8eec7477 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Gallego?= Date: Fri, 29 May 2015 15:14:41 +0200 Subject: [PATCH 2/5] Update tests and code --- config/aws.local.php.dist | 31 +++--- config/aws_zf2.local.php.dist | 29 ++--- config/module.config.php | 18 ++- src/Factory/AwsFactory.php | 33 +----- .../CloudFrontLinkViewHelperFactory.php | 9 +- .../DynamoDbSessionSaveHandlerFactory.php | 15 +-- src/Factory/S3LinkViewHelperFactory.php | 7 +- src/Factory/S3RenameUploadFactory.php | 7 +- .../Exception/MissingBucketException.php | 2 +- src/Filter/File/S3RenameUpload.php | 6 +- src/Session/SaveHandler/DynamoDb.php | 2 +- .../Exception/InvalidDomainNameException.php | 3 +- src/View/Exception/InvalidSchemeException.php | 3 +- src/View/Helper/AbstractLinkHelper.php | 93 ---------------- src/View/Helper/CloudFrontLink.php | 29 ++--- src/View/Helper/S3Link.php | 35 ++---- tests/Tests/BaseModuleTest.php | 40 ------- tests/Tests/Factory/AwsFactoryTest.php | 37 ++----- .../DynamoDbSessionSaveHandlerFactoryTest.php | 61 +++++----- .../Tests/Filter/File/S3RenameUploadTest.php | 40 ++++--- tests/Tests/ModuleTest.php | 104 ------------------ .../Session/SaveHandler/DynamoDbTest.php | 13 +-- .../Tests/View/Helper/CloudFrontLinkTest.php | 62 ++--------- tests/Tests/View/Helper/S3LinkTest.php | 84 +++++--------- 24 files changed, 201 insertions(+), 562 deletions(-) delete mode 100644 src/View/Helper/AbstractLinkHelper.php delete mode 100644 tests/Tests/BaseModuleTest.php delete mode 100644 tests/Tests/ModuleTest.php diff --git a/config/aws.local.php.dist b/config/aws.local.php.dist index ef03efe..cfe857c 100644 --- a/config/aws.local.php.dist +++ b/config/aws.local.php.dist @@ -1,19 +1,24 @@ array( - // 'key' => 'change_me', - // 'secret' => 'change_me', - // 'region' => 'change_me' - // ) - - /** - * You can alternatively provide a path to an AWS SDK for PHP config file containing your configuration settings. - * Config files can allow you to have finer-grained control over the configuration settings for each service client. - */ - // 'aws' => 'path/to/your/aws-config.php' -); + // 'aws' => [ + // 'credentials' => [ + // 'key' => 'change_me', + // 'secret' => 'change_me' + // ] + // 'region' => 'change_me', + // 'version' => 'latest', + // 'DynamoDb' => [ + // 'region' => 'another_region', + // 'version' => 'latest' + // ] + // ] +]; diff --git a/config/aws_zf2.local.php.dist b/config/aws_zf2.local.php.dist index dd459d4..a8bdeff 100644 --- a/config/aws_zf2.local.php.dist +++ b/config/aws_zf2.local.php.dist @@ -6,23 +6,14 @@ * the .dist extension). Change it however you need for your project. */ -return array( - 'aws_zf2' => array( - 'session' => array( - 'save_handler' => array( - 'dynamodb' => array( +return [ + 'aws_zf2' => [ + 'session' => [ + 'save_handler' => [ + 'dynamodb' => [ // Locking strategy used for doing session locking. // 'locking_strategy' => null, - // DynamoDb client object used for performing DynamoDB - // operations. - // - // Note: you most likely want to leave this alone and allow - // the factory to fetch your configured instance of - // DynamoDB. However, if you override it with an object, we - // will respect that choice. - // 'dynamodb_client' => null, - // Name of the DynamoDB table in which to store the // sessions. // 'table_name' => 'sessions', @@ -63,8 +54,8 @@ return array( // Maximum time (in microseconds) to wait between attempts to acquire a lock // 'max_lock_retry_microtime' => 50000, - ) - ) - ) - ) -); + ] + ] + ] + ] +]; diff --git a/config/module.config.php b/config/module.config.php index 85c0e32..718a4ae 100644 --- a/config/module.config.php +++ b/config/module.config.php @@ -1,9 +1,15 @@ [ @@ -15,22 +21,22 @@ 'filters' => [ 'factories' => [ - 'Aws\Filter\File\S3RenameUpload' => 'Aws\Factory\S3RenameUploadFactory' + S3RenameUpload::class => S3RenameUploadFactory::class ], 'aliases' => [ - 's3renameupload' => 'Aws\Filter\File\S3RenameUpload' + 's3renameupload' => S3RenameUpload::class ] ], 'view_helpers' => [ 'factories' => [ - 'Aws\View\Helper\S3Link' => 'Aws\Factory\S3LinkViewHelperFactory', - 'Aws\View\Helper\CloudFrontLink' => 'Aws\Factory\CloudFrontLinkViewHelperFactory' + S3Link::class => S3LinkViewHelperFactory::class, + CloudFrontLink::class => CloudFrontLinkViewHelperFactory::class ], 'aliases' => [ - 'cloudfrontlink' => 'Aws\View\Helper\CloudFrontLink', - 's3link' => 'Aws\View\Helper\S3Link' + 'cloudfrontlink' => CloudFrontLink::class, + 's3link' => S3Link::class ] ], ]; diff --git a/src/Factory/AwsFactory.php b/src/Factory/AwsFactory.php index 2e9ed50..d999e6f 100644 --- a/src/Factory/AwsFactory.php +++ b/src/Factory/AwsFactory.php @@ -16,14 +16,9 @@ namespace Aws\Factory; -use Aws\Common\Aws; -use Aws\Common\Client\UserAgentListener; -use Aws\Module; -use Guzzle\Common\Event; -use Guzzle\Service\Client; +use Aws\Sdk as AwsSdk; use Zend\ServiceManager\FactoryInterface; use Zend\ServiceManager\ServiceLocatorInterface; -use Zend\Version\Version; /** * Factory used to instantiate an AWS client @@ -32,34 +27,14 @@ class AwsFactory implements FactoryInterface { /** * {@inheritDoc} - * @return Aws + * @return AwsSdk */ public function createService(ServiceLocatorInterface $serviceLocator) { // Instantiate the AWS SDK for PHP $config = $serviceLocator->get('Config'); - $config = isset($config['aws']) ? $config['aws'] : array(); - $aws = Aws::factory($config); + $config = isset($config['aws']) ? $config['aws'] : []; - // Attach an event listener that will append the ZF2 version number in the user agent string - $aws->getEventDispatcher()->addListener('service_builder.create_client', array($this, 'onCreateClient')); - - return $aws; - } - - /** - * Add ZF2 version in UserAgent (used for metrics) - * - * @param Event $event The event containing the instantiated client object - * - * @return void - */ - public function onCreateClient(Event $event) - { - $clientConfig = $event['client']->getConfig(); - $commandParams = $clientConfig->get(Client::COMMAND_PARAMS) ?: array(); - $clientConfig->set(Client::COMMAND_PARAMS, array_merge_recursive($commandParams, array( - UserAgentListener::OPTION => 'ZF2/' . Version::VERSION . ' ZFMOD/' . Module::VERSION, - ))); + return new AwsSdk($config); } } diff --git a/src/Factory/CloudFrontLinkViewHelperFactory.php b/src/Factory/CloudFrontLinkViewHelperFactory.php index 1312eae..845fc44 100644 --- a/src/Factory/CloudFrontLinkViewHelperFactory.php +++ b/src/Factory/CloudFrontLinkViewHelperFactory.php @@ -16,6 +16,7 @@ namespace Aws\Factory; +use Aws\Sdk as AwsSdk; use Aws\View\Helper\CloudFrontLink; use Zend\ServiceManager\FactoryInterface; use Zend\ServiceManager\ServiceLocatorInterface; @@ -31,9 +32,11 @@ class CloudFrontLinkViewHelperFactory implements FactoryInterface */ public function createService(ServiceLocatorInterface $serviceLocator) { - $parentLocator = $serviceLocator->getServiceLocator(); - $cloudFrontClient = $parentLocator->get('Aws')->get('CloudFront'); + $parentLocator = $serviceLocator->getServiceLocator(); - return new CloudFrontLink($cloudFrontClient); + /** @var AwsSdk $awsSdk */ + $awsSdk = $parentLocator->get(AwsSdk::class); + + return new CloudFrontLink($awsSdk->createCloudFront()); } } diff --git a/src/Factory/DynamoDbSessionSaveHandlerFactory.php b/src/Factory/DynamoDbSessionSaveHandlerFactory.php index 4c46b0e..b9e5bf4 100644 --- a/src/Factory/DynamoDbSessionSaveHandlerFactory.php +++ b/src/Factory/DynamoDbSessionSaveHandlerFactory.php @@ -16,7 +16,8 @@ namespace Aws\Factory; -use Aws\DynamoDb\Session\SessionHandler; +use Aws\Sdk as AwsSdk; +use Aws\DynamoDb\SessionHandler; use Aws\Session\SaveHandler\DynamoDb as DynamoDbSaveHandler; use Zend\ServiceManager\Exception\ServiceNotCreatedException; use Zend\ServiceManager\FactoryInterface; @@ -44,15 +45,11 @@ public function createService(ServiceLocatorInterface $serviceLocator) ); } - $saveHandlerConfig = $config['aws_zf2']['session']['save_handler']['dynamodb']; - - if (!isset($saveHandlerConfig['dynamodb_client'])) { - $dynamoDbClient = $serviceLocator->get('Aws')->get('DynamoDb'); + /** @var AwsSdk $awsSdk */ + $awsSdk = $serviceLocator->get(AwsSdk::class); - $saveHandlerConfig['dynamodb_client'] = $dynamoDbClient; - } - - $sessionHandler = SessionHandler::factory($saveHandlerConfig); + $saveHandlerConfig = $config['aws_zf2']['session']['save_handler']['dynamodb']; + $sessionHandler = SessionHandler::fromClient($awsSdk->createDynamoDb(), $saveHandlerConfig); return new DynamoDbSaveHandler($sessionHandler); } diff --git a/src/Factory/S3LinkViewHelperFactory.php b/src/Factory/S3LinkViewHelperFactory.php index e50dbff..30a233d 100644 --- a/src/Factory/S3LinkViewHelperFactory.php +++ b/src/Factory/S3LinkViewHelperFactory.php @@ -16,6 +16,7 @@ namespace Aws\Factory; +use Aws\Sdk as AwsSdk; use Aws\View\Helper\S3Link; use Zend\ServiceManager\FactoryInterface; use Zend\ServiceManager\ServiceLocatorInterface; @@ -32,8 +33,10 @@ class S3LinkViewHelperFactory implements FactoryInterface public function createService(ServiceLocatorInterface $serviceLocator) { $parentLocator = $serviceLocator->getServiceLocator(); - $s3Client = $parentLocator->get('Aws')->get('S3'); - return new S3Link($s3Client); + /** @var AwsSdk $awsSdk */ + $awsSdk = $parentLocator->get(AwsSdk::class); + + return new S3Link($awsSdk->createS3()); } } diff --git a/src/Factory/S3RenameUploadFactory.php b/src/Factory/S3RenameUploadFactory.php index def7db0..12c2745 100644 --- a/src/Factory/S3RenameUploadFactory.php +++ b/src/Factory/S3RenameUploadFactory.php @@ -16,6 +16,7 @@ namespace Aws\Factory; +use Aws\Sdk as AwsSdk; use Aws\Filter\File\S3RenameUpload; use Zend\ServiceManager\FactoryInterface; use Zend\ServiceManager\ServiceLocatorInterface; @@ -28,8 +29,10 @@ class S3RenameUploadFactory implements FactoryInterface public function createService(ServiceLocatorInterface $serviceLocator) { $parentLocator = $serviceLocator->getServiceLocator(); - $s3Client = $parentLocator->get('Aws')->get('S3'); - return new S3RenameUpload($s3Client); + /** @var AwsSdk $awsSdk */ + $awsSdk = $parentLocator->get(AwsSdk::class); + + return new S3RenameUpload($awsSdk->createS3()); } } diff --git a/src/Filter/Exception/MissingBucketException.php b/src/Filter/Exception/MissingBucketException.php index b0bc81a..ef22246 100644 --- a/src/Filter/Exception/MissingBucketException.php +++ b/src/Filter/Exception/MissingBucketException.php @@ -16,7 +16,7 @@ namespace Aws\Filter\Exception; -use Aws\Common\Exception\InvalidArgumentException; +use InvalidArgumentException; /** * Exception thrown when no bucket is passed diff --git a/src/Filter/File/S3RenameUpload.php b/src/Filter/File/S3RenameUpload.php index bfca318..5edd981 100644 --- a/src/Filter/File/S3RenameUpload.php +++ b/src/Filter/File/S3RenameUpload.php @@ -33,20 +33,20 @@ class S3RenameUpload extends RenameUpload /** * @var array */ - protected $options = array( + protected $options = [ 'bucket' => null, 'target' => null, 'use_upload_name' => false, 'use_upload_extension' => false, 'overwrite' => false, 'randomize' => false, - ); + ]; /** * @param S3Client $client * @param array $options */ - public function __construct(S3Client $client, $options = array()) + public function __construct(S3Client $client, $options = []) { parent::__construct($options); diff --git a/src/Session/SaveHandler/DynamoDb.php b/src/Session/SaveHandler/DynamoDb.php index b30d5c8..a3fae05 100644 --- a/src/Session/SaveHandler/DynamoDb.php +++ b/src/Session/SaveHandler/DynamoDb.php @@ -16,7 +16,7 @@ namespace Aws\Session\SaveHandler; -use Aws\Dynamodb\Session\SessionHandler; +use Aws\Dynamodb\SessionHandler; use Zend\Session\SaveHandler\SaveHandlerInterface; /** diff --git a/src/View/Exception/InvalidDomainNameException.php b/src/View/Exception/InvalidDomainNameException.php index 748e138..df36720 100644 --- a/src/View/Exception/InvalidDomainNameException.php +++ b/src/View/Exception/InvalidDomainNameException.php @@ -16,12 +16,11 @@ namespace Aws\View\Exception; -use Aws\Common\Exception\AwsExceptionInterface; use InvalidArgumentException; /** * Exception thrown when an invalid CloudFront domain is passed */ -class InvalidDomainNameException extends InvalidArgumentException implements AwsExceptionInterface +class InvalidDomainNameException extends InvalidArgumentException { } diff --git a/src/View/Exception/InvalidSchemeException.php b/src/View/Exception/InvalidSchemeException.php index 7dbe9f4..3cb63f5 100644 --- a/src/View/Exception/InvalidSchemeException.php +++ b/src/View/Exception/InvalidSchemeException.php @@ -16,13 +16,12 @@ namespace Aws\View\Exception; -use Aws\Common\Exception\AwsExceptionInterface; use InvalidArgumentException; /** * Exception thrown when an invalid scheme is passed for S3 or CloudFront * link generation. */ -class InvalidSchemeException extends InvalidArgumentException implements AwsExceptionInterface +class InvalidSchemeException extends InvalidArgumentException { } diff --git a/src/View/Helper/AbstractLinkHelper.php b/src/View/Helper/AbstractLinkHelper.php deleted file mode 100644 index d62b205..0000000 --- a/src/View/Helper/AbstractLinkHelper.php +++ /dev/null @@ -1,93 +0,0 @@ -setScheme($useSsl ? 'https' : 'http'); - - return $this; - } - - /** - * Get if HTTPS should be used for generating URLs - * - * @return bool - * @deprecated - */ - public function getUseSsl() - { - return $this->getScheme() === 'https'; - } - - /** - * Set the scheme to use for generating URLs. Supported schemes - * are http, https and null (see {@link $supportedSchemes}). - * - * @param string $scheme - * @throws InvalidSchemeException - * @return self - */ - public function setScheme($scheme) - { - if (!in_array($scheme, $this->supportedSchemes, true)) { - $schemes = implode(', ', $this->supportedSchemes); - - throw new InvalidSchemeException('Schemes must be one of ' . $schemes); - } - - $this->scheme = $scheme; - - return $this; - } - - /** - * Get the scheme to be used for generating URLs - * - * @return string - */ - public function getScheme() - { - return $this->scheme; - } -} diff --git a/src/View/Helper/CloudFrontLink.php b/src/View/Helper/CloudFrontLink.php index 9021e5a..2f5db35 100644 --- a/src/View/Helper/CloudFrontLink.php +++ b/src/View/Helper/CloudFrontLink.php @@ -25,7 +25,7 @@ * View helper that can render a link to a CloudFront object. It can also create signed URLs * using a canned policy */ -class CloudFrontLink extends AbstractLinkHelper +class CloudFrontLink extends AbstractHelper { /** * @var string The hostname for CloudFront domains @@ -37,11 +37,6 @@ class CloudFrontLink extends AbstractLinkHelper */ protected $client; - /** - * @var bool Whether or not to use SSl - */ - protected $useSsl = true; - /** * @var string The default CloudFront domain to use */ @@ -109,11 +104,13 @@ public function getDefaultDomain() * @param string $object * @param string $domain * @param string|int $expiration + * @param string $keyPairId + * @param string $privateKey * * @return string * @throws InvalidDomainNameException */ - public function __invoke($object, $domain = '', $expiration = '') + public function __invoke($object, $domain = '', $expiration = '', $keyPairId = '', $privateKey = '') { if (empty($domain)) { $domain = $this->getDefaultDomain(); @@ -125,9 +122,7 @@ public function __invoke($object, $domain = '', $expiration = '') } $url = sprintf( - '%s//%s%s/%s', - ($this->scheme === null) ? null : $this->scheme . ':', - // Remove hostname if provided as we include it already + 'https://%s%s/%s', str_replace($this->hostname, '', rtrim($domain, '/')), $this->hostname, ltrim($object, '/') @@ -137,13 +132,11 @@ public function __invoke($object, $domain = '', $expiration = '') return $url; } - if ($this->scheme === null) { - throw new InvalidSchemeException('Protocol relative URLs cannot be signed.'); - } - - return $this->client->getSignedUrl(array( - 'url' => $url, - 'expires' => $expiration - )); + return $this->client->getSignedUrl([ + 'url' => $url, + 'expires' => $expiration, + 'key_pair_id' => $keyPairId, + 'private_key' => $privateKey + ]); } } diff --git a/src/View/Helper/S3Link.php b/src/View/Helper/S3Link.php index 8f92fba..bc77afc 100644 --- a/src/View/Helper/S3Link.php +++ b/src/View/Helper/S3Link.php @@ -16,16 +16,14 @@ namespace Aws\View\Helper; -use Aws\Common\Aws; use Aws\S3\S3Client; -use Aws\S3\BucketStyleListener; use Aws\View\Exception\InvalidDomainNameException; -use Guzzle\Common\Event; +use Zend\View\Helper\AbstractHelper; /** * View helper that can render a link to a S3 object. It can also create signed URLs */ -class S3Link extends AbstractLinkHelper +class S3Link extends AbstractHelper { /** * @var S3Client @@ -82,33 +80,20 @@ public function getDefaultBucket() public function __invoke($object, $bucket = '', $expiration = '') { $bucket = trim($bucket ?: $this->getDefaultBucket(), '/'); + if (empty($bucket)) { throw new InvalidDomainNameException('An empty bucket name was given'); } - // Create a command representing the get request - // Using a command will make sure the configured regional endpoint is used - $command = $this->client->getCommand('GetObject', array( - 'Bucket' => $bucket, - 'Key' => $object, - )); - - // Instead of executing the command, retrieve the request and make sure the scheme is set to what was specified - $request = $command->prepare()->setScheme($this->getScheme())->setPort(null); - - // Ensure that the correct bucket URL style (virtual or path) is used based on the bucket name - // This addresses a bug in versions of the SDK less than or equal to 2.3.4 - // @codeCoverageIgnoreStart - if (version_compare(Aws::VERSION, '2.4.0', '<') && strpos($request->getHost(), $bucket) === false) { - $bucketStyleListener = new BucketStyleListener(); - $bucketStyleListener->onCommandBeforeSend(new Event(array('command' => $command))); - } - // @codeCoverageIgnoreEnd - if ($expiration) { - return $this->client->createPresignedUrl($request, $expiration); + $command = $this->client->getCommand('GetObject', [ + 'Bucket' => $bucket, + 'Key' => $object + ]); + + return $this->client->createPresignedRequest($command, $expiration)->getUri()->__toString(); } else { - return $request->getUrl(); + return $this->client->getObjectUrl($bucket, $object); } } } diff --git a/tests/Tests/BaseModuleTest.php b/tests/Tests/BaseModuleTest.php deleted file mode 100644 index be4b2f7..0000000 --- a/tests/Tests/BaseModuleTest.php +++ /dev/null @@ -1,40 +0,0 @@ -getConfig(); - - $serviceConfig = new ServiceConfig($config['service_manager']); - $serviceManager = new ServiceManager($serviceConfig); - - return $serviceManager; - } -} diff --git a/tests/Tests/Factory/AwsFactoryTest.php b/tests/Tests/Factory/AwsFactoryTest.php index d131c3f..06a49a6 100644 --- a/tests/Tests/Factory/AwsFactoryTest.php +++ b/tests/Tests/Factory/AwsFactoryTest.php @@ -14,44 +14,27 @@ * permissions and limitations under the License. */ -namespace AwsTests; +namespace AwsTests\Factory; -use Aws\Common\Client\UserAgentListener; use Aws\Factory\AwsFactory; -use Aws\S3\S3Client; -use Aws\Tests\BaseModuleTest; -use Guzzle\Common\Event; -use Guzzle\Service\Client; +use Aws\Sdk as AwsSdk; +use Zend\ServiceManager\ServiceLocatorInterface; /** * AWS Module test cases */ -class ModuleTest extends BaseModuleTest +class AwsFactoryTest extends \PHPUnit_Framework_TestCase { public function testCanFetchAwsFromServiceManager() { - $awsFactory = new AwsFactory(); - $serviceManager = $this->createServiceManagerForTest(); + $serviceLocator = $this->getMock(ServiceLocatorInterface::class); + $serviceLocator->expects($this->once())->method('get')->with('Config')->willReturn([]); - $serviceManager->setService('config', array()); + $awsFactory = new AwsFactory(); - /** @var $aws \Guzzle\Service\Builder\ServiceBuilder */ - $aws = $awsFactory->createService($serviceManager); + /** @var $aws AwsSdk */ + $aws = $awsFactory->createService($serviceLocator); - $this->assertInstanceOf('Guzzle\Service\Builder\ServiceBuilderInterface', $aws); - $this->assertTrue($aws->getEventDispatcher()->hasListeners('service_builder.create_client')); - } - - public function testCanAddZf2ToUserAgent() - { - $factory = new AwsFactory(); - $client = S3Client::factory(); - $event = new Event(array('client' => $client)); - - $factory->onCreateClient($event); - $clientParams = $client->getConfig()->get(Client::COMMAND_PARAMS); - - $this->assertArrayHasKey(UserAgentListener::OPTION, $clientParams); - $this->assertRegExp('/ZF2\/.+ZFMOD\/.+/', $clientParams[UserAgentListener::OPTION]); + $this->assertInstanceOf(AwsSdk::class, $aws); } } diff --git a/tests/Tests/Factory/DynamoDbSessionSaveHandlerFactoryTest.php b/tests/Tests/Factory/DynamoDbSessionSaveHandlerFactoryTest.php index 23e41fb..103b1b4 100644 --- a/tests/Tests/Factory/DynamoDbSessionSaveHandlerFactoryTest.php +++ b/tests/Tests/Factory/DynamoDbSessionSaveHandlerFactoryTest.php @@ -14,56 +14,59 @@ * permissions and limitations under the License. */ -namespace Aws\Tests; +namespace Aws\Tests\Factory; use Aws\Factory\DynamoDbSessionSaveHandlerFactory; -use Aws\Tests\BaseModuleTest; +use Aws\Sdk as AwsSdk; +use Aws\Session\SaveHandler\DynamoDb as DynamoDbSaveHandler; +use Zend\ServiceManager\ServiceLocatorInterface; /** * DynamoDB-backed session save handler tests */ -class DynamoDbSessionSaveHandlerFactoryTest extends BaseModuleTest +class DynamoDbSessionSaveHandlerFactoryTest extends \PHPUnit_Framework_TestCase { public function testCanFetchSaveHandlerFromServiceManager() { - $saveHandlerFactory = new DynamoDbSessionSaveHandlerFactory(); - $serviceManager = $this->createServiceManagerForTest(); + $config = [ + 'aws' => [ + 'region' => 'us-east-1', + 'version' => 'latest' + ], + 'aws_zf2' => [ + 'session' => [ + 'save_handler' => [ + 'dynamodb' => [] + ] + ] + ] + ]; + + $awsSdk = new AwsSdk($config['aws']); - $config = array( - 'aws' => array( - 'region' => 'us-east-1' - ), - 'aws_zf2' => array( - 'session' => array( - 'save_handler' => array( - 'dynamodb' => array() - ) - ) - ) - ); + $serviceLocator = $this->getMock(ServiceLocatorInterface::class); + $serviceLocator->expects($this->at(0))->method('get')->with('Config')->willReturn($config); + $serviceLocator->expects($this->at(1))->method('get')->with(AwsSdk::class)->willReturn($awsSdk); - $serviceManager->setService( - 'Config', - $config - ); + + $saveHandlerFactory = new DynamoDbSessionSaveHandlerFactory(); /** @var $saveHandler \Aws\Session\SaveHandler\DynamoDb */ - $saveHandler = $serviceManager->get('Aws\Session\SaveHandler\DynamoDb'); + $saveHandler = $saveHandlerFactory->createService($serviceLocator); - $this->assertInstanceOf('Aws\Session\SaveHandler\DynamoDb', $saveHandler); + $this->assertInstanceOf(DynamoDbSaveHandler::class, $saveHandler); } /** - * @expectedException Zend\ServiceManager\Exception\ServiceNotCreatedException + * @expectedException \Zend\ServiceManager\Exception\ServiceNotCreatedException */ public function testExceptionThrownWhenSaveHandlerConfigurationDoesNotExist() { - $saveHandlerFactory = new DynamoDbSessionSaveHandlerFactory(); - $serviceManager = $this->createServiceManagerForTest(); + $serviceLocator = $this->getMock(ServiceLocatorInterface::class); + $serviceLocator->expects($this->once())->method('get')->with('Config')->willReturn([]); - $serviceManager->setService('Config', array()); + $saveHandlerFactory = new DynamoDbSessionSaveHandlerFactory(); - /** @var $saveHandler \Aws\Session\SaveHandler\DynamoDb */ - $saveHandler = $serviceManager->get('Aws\Session\SaveHandler\DynamoDb'); + $saveHandlerFactory->createService($serviceLocator); } } diff --git a/tests/Tests/Filter/File/S3RenameUploadTest.php b/tests/Tests/Filter/File/S3RenameUploadTest.php index f05dbfc..bf1825a 100644 --- a/tests/Tests/Filter/File/S3RenameUploadTest.php +++ b/tests/Tests/Filter/File/S3RenameUploadTest.php @@ -16,12 +16,12 @@ namespace AwsTests\Filter\File; +use Aws\Filter\Exception\MissingBucketException; use Aws\Filter\File\S3RenameUpload; use Aws\S3\S3Client; -use Aws\Tests\BaseModuleTest; use ReflectionMethod; -class S3RenameUploadTest extends BaseModuleTest +class S3RenameUploadTest extends \PHPUnit_Framework_TestCase { /** * @var S3RenameUpload @@ -30,10 +30,14 @@ class S3RenameUploadTest extends BaseModuleTest public function setUp() { - $s3Client = S3Client::factory(array( - 'key' => '1234', - 'secret' => '5678' - )); + $s3Client = new S3Client([ + 'credentials' => [ + 'key' => '1234', + 'secret' => '5678' + ], + 'region' => 'us-east-1', + 'version' => 'latest' + ]); $this->filter = new S3RenameUpload($s3Client); } @@ -48,16 +52,16 @@ public function testBucketNameIsTrimmedWhenSet() $this->filter->setBucket('/my-bucket/'); $this->assertEquals('my-bucket', $this->filter->getBucket()); - $this->filter->setOptions(array( + $this->filter->setOptions([ 'bucket' => '/my-bucket/' - )); + ]); $this->assertEquals('my-bucket', $this->filter->getBucket()); } public function testThrowExceptionIfNoBucketIsSet() { - $this->setExpectedException('Aws\Filter\Exception\MissingBucketException'); - $this->filter->filter(array('tmp_name' => 'foo')); + $this->setExpectedException(MissingBucketException::class); + $this->filter->filter(['tmp_name' => 'foo']); } /** @@ -70,20 +74,20 @@ public function testAssertS3UriIsGenerated($tmpName, $expectedKey) $this->filter->setBucket('my-bucket'); - $result = $reflMethod->invoke($this->filter, array( + $result = $reflMethod->invoke($this->filter, [ 'tmp_name' => $tmpName - )); + ]); $this->assertEquals("s3://my-bucket/{$expectedKey}", $result); } public function tmpNameProvider() { - return array( - array('temp/phptmpname', 'temp/phptmpname'), - array('temp/phptmpname/', 'temp/phptmpname'), - array('temp\\phptmpname', 'temp/phptmpname'), - array('temp\\phptmpname\\', 'temp/phptmpname'), - ); + return [ + ['temp/phptmpname', 'temp/phptmpname'], + ['temp/phptmpname/', 'temp/phptmpname'], + ['temp\\phptmpname', 'temp/phptmpname'], + ['temp\\phptmpname\\', 'temp/phptmpname'], + ]; } } diff --git a/tests/Tests/ModuleTest.php b/tests/Tests/ModuleTest.php deleted file mode 100644 index f4bb831..0000000 --- a/tests/Tests/ModuleTest.php +++ /dev/null @@ -1,104 +0,0 @@ -getConfig(); - - $this->assertInternalType('array', $config); - - $classExists = isset($config['service_manager']['factories']['Aws']) - && class_exists($config['service_manager']['factories']['Aws']); - - $this->assertTrue($classExists); - } - - /** - * Tests a normal module registration - */ - public function testRegisterAwsModule() - { - // Create the module and service manager, and register the module - $serviceManager = $this->createServiceManagerForTest(); - $serviceManager->setService('config', array('aws' => array( - 'key' => 'your-aws-access-key-id', - 'secret' => 'your-aws-secret-access-key', - ))); - - // Make sure the service manager received the service configuration from the module - $services = $serviceManager->getRegisteredServices(); - $this->assertContains('aws', $services['factories']); - - // Get the SDK's service builder from the ZF2's service manager - $aws = $serviceManager->get('aws'); - $this->assertInstanceOf('Guzzle\Service\Builder\ServiceBuilderInterface', $aws); - - // Get an instance of a client (S3) to use for testing - $s3 = $aws->get('s3'); - $this->assertInstanceOf('Aws\S3\S3Client', $s3); - - // Verify that the S3 client created by the SDK received the provided credentials - $this->assertEquals('your-aws-access-key-id', $s3->getCredentials()->getAccessKeyId()); - $this->assertEquals('your-aws-secret-access-key', $s3->getCredentials()->getSecretKey()); - - // Make sure the user agent contains "ZF2" - $command = $s3->getCommand('ListBuckets'); - $request = $command->prepare(); - $s3->dispatch('command.before_send', array('command' => $command)); - $this->assertRegExp('/.+ZF2\/.+/', (string) $request->getHeader('User-Agent')); - } - - /** - * Tests modules registration with no config provided - * - * @dataProvider dataForNoConfigTest - * @expectedException \Aws\Common\Exception\InstanceProfileCredentialsException - */ - public function testNoConfigProvided(array $providedConfig) - { - // Create the module and service manager, and register the module without any configuration - $serviceManager = $this->createServiceManagerForTest(); - $serviceManager->setService('config', $providedConfig); - - // Instantiate a client and get the access key, which should trigger an exception trying to use IAM credentials - $s3 = $serviceManager->get('aws')->get('s3'); - $s3->getCredentials()->getAccessKeyId(); - } - - /** - * @return array - */ - public function dataForNoConfigTest() - { - return array( - array(array()), - array(array('aws' => array())), - ); - } -} diff --git a/tests/Tests/Session/SaveHandler/DynamoDbTest.php b/tests/Tests/Session/SaveHandler/DynamoDbTest.php index f98af3e..c9670ce 100644 --- a/tests/Tests/Session/SaveHandler/DynamoDbTest.php +++ b/tests/Tests/Session/SaveHandler/DynamoDbTest.php @@ -16,11 +16,10 @@ namespace AwsTests\Session\SaveHandler; -use Aws\DynamoDb\Session\SessionHandler; +use Aws\DynamoDb\SessionHandler; use Aws\Session\SaveHandler\DynamoDb as DynamoDbSaveHandler; -use Aws\Tests\BaseModuleTest; -class DynamoDbTest extends BaseModuleTest +class DynamoDbTest extends \PHPUnit_Framework_TestCase { /** * @var SessionHandler @@ -37,16 +36,16 @@ public function setUp() parent::setUp(); $this->sessionHandler = $this->getMock( - 'Aws\DynamoDb\Session\SessionHandler', - array( + SessionHandler::class, + [ 'open', 'close', 'read', 'write', 'destroy', 'gc', - ), - array(), + ], + [], '', false ); diff --git a/tests/Tests/View/Helper/CloudFrontLinkTest.php b/tests/Tests/View/Helper/CloudFrontLinkTest.php index 9ef147a..8629e3a 100644 --- a/tests/Tests/View/Helper/CloudFrontLinkTest.php +++ b/tests/Tests/View/Helper/CloudFrontLinkTest.php @@ -16,11 +16,10 @@ namespace AwsTests\View\Helper; -use Aws\Tests\BaseModuleTest; use Aws\CloudFront\CloudFrontClient; use Aws\View\Helper\CloudFrontLink; -class CloudFrontLinkTest extends BaseModuleTest +class CloudFrontLinkTest extends \PHPUnit_Framework_TestCase { /** * @var CloudFrontClient @@ -34,49 +33,24 @@ class CloudFrontLinkTest extends BaseModuleTest public function setUp() { - $this->cloudFrontClient = CloudFrontClient::factory(array( - 'key' => '1234', - 'secret' => '5678', - )); + $this->cloudFrontClient = new CloudFrontClient([ + 'credentials' => [ + 'key' => '1234', + 'secret' => '5678', + ], + 'region' => 'us-east-1', + 'version' => 'latest' + ]); $this->viewHelper = new CloudFrontLink($this->cloudFrontClient); } - public function testAssertDoesUseSslByDefault() - { - $this->assertTrue($this->viewHelper->getUseSsl()); - } - - /** - * @expectedException \Aws\View\Exception\InvalidSchemeException - */ - public function testAssertInvalidSchemesThrowExceptions() - { - $this->viewHelper->setScheme('nosuchscheme'); - } - public function testGenerateSimpleLink() { $link = $this->viewHelper->__invoke('my-object', 'my-domain'); $this->assertEquals('https://my-domain.cloudfront.net/my-object', $link); } - public function testGenerateSimpleNonSslLink() - { - $this->viewHelper->setScheme('http'); - - $link = $this->viewHelper->__invoke('my-object', 'my-domain'); - $this->assertEquals('http://my-domain.cloudfront.net/my-object', $link); - } - - public function testGenerateSimpleProtocolRelativeLink() - { - $this->viewHelper->setScheme(null); - - $link = $this->viewHelper->__invoke('my-object', 'my-domain'); - $this->assertEquals('//my-domain.cloudfront.net/my-object', $link); - } - public function testCanUseDefaultDomain() { $this->viewHelper->setDefaultDomain('my-default-domain'); @@ -140,27 +114,11 @@ public function testGenerateSignedLink() openssl_pkey_export_to_file($privateKey, $pemFile); } - $clientConfig = $this->cloudFrontClient->getConfig(); - $clientConfig->set('key_pair_id', 'kpid'); - $clientConfig->set('private_key', $pemFile); - $this->viewHelper->setHostname('example.com'); - $link = $this->viewHelper->__invoke('my-object', '123abc', time() + 600); + $link = $this->viewHelper->__invoke('my-object', '123abc', time() + 600, 'kpid', $pemFile); $this->assertRegExp( '#^https\:\/\/123abc\.example\.com\/my-object\?Expires\=(.*)\&Signature\=(.*)\&Key-Pair-Id\=kpid$#', $link ); } - - /** - * @expectedException \Aws\View\Exception\InvalidSchemeException - */ - public function testGenerateSignedProtocolRelativeLink() - { - $this->viewHelper - ->setHostname('example.com') - ->setScheme(null); - - $link = $this->viewHelper->__invoke('my-object', '123abc', time() + 600); - } } diff --git a/tests/Tests/View/Helper/S3LinkTest.php b/tests/Tests/View/Helper/S3LinkTest.php index 235577b..fb95b30 100644 --- a/tests/Tests/View/Helper/S3LinkTest.php +++ b/tests/Tests/View/Helper/S3LinkTest.php @@ -16,11 +16,10 @@ namespace AwsTests\View\Helper; -use Aws\Tests\BaseModuleTest; use Aws\S3\S3Client; use Aws\View\Helper\S3Link; -class S3LinkTest extends BaseModuleTest +class S3LinkTest extends \PHPUnit_Framework_TestCase { /** * @var S3Client @@ -34,47 +33,22 @@ class S3LinkTest extends BaseModuleTest public function setUp() { - $this->s3Client = S3Client::factory(array( - 'key' => '1234', - 'secret' => '5678' - )); + $this->s3Client = new S3Client([ + 'credentials' => [ + 'key' => '1234', + 'secret' => '5678' + ], + 'region' => 'us-east-1', + 'version' => 'latest' + ]); $this->viewHelper = new S3Link($this->s3Client); } - public function testAssertUseSslByDefault() - { - $this->assertEquals('https', $this->viewHelper->getScheme()); - } - - /** - * @expectedException \Aws\View\Exception\InvalidSchemeException - */ - public function testAssertInvalidSchemesThrowExceptions() - { - $this->viewHelper->setScheme('nosuchscheme'); - } - public function testGenerateSimpleLink() { $link = $this->viewHelper->__invoke('my-object', 'my-bucket'); - $this->assertEquals('https://my-bucket.s3.amazonaws.com/my-object', $link); - } - - public function testGenerateSimpleNonSslLink() - { - $this->viewHelper->setUseSsl(false); - - $link = $this->viewHelper->__invoke('my-object', 'my-bucket'); - $this->assertEquals('http://my-bucket.s3.amazonaws.com/my-object', $link); - } - - public function testGenerateSimpleProtocolRelativeLink() - { - $this->viewHelper->setScheme(null); - - $link = $this->viewHelper->__invoke('my-object', 'my-bucket'); - $this->assertEquals('//my-bucket.s3.amazonaws.com/my-object', $link); + $this->assertEquals('https://s3.amazonaws.com/my-bucket/my-object', $link); } public function testCanUseDefaultBucket() @@ -82,7 +56,7 @@ public function testCanUseDefaultBucket() $this->viewHelper->setDefaultBucket('my-default-bucket'); $link = $this->viewHelper->__invoke('my-object'); - $this->assertEquals('https://my-default-bucket.s3.amazonaws.com/my-object', $link); + $this->assertEquals('https://s3.amazonaws.com/my-default-bucket/my-object', $link); } public function testAssertGivenBucketOverrideDefaultBucket() @@ -90,15 +64,24 @@ public function testAssertGivenBucketOverrideDefaultBucket() $this->viewHelper->setDefaultBucket('my-default-bucket'); $link = $this->viewHelper->__invoke('my-object', 'my-overriden-bucket'); - $this->assertEquals('https://my-overriden-bucket.s3.amazonaws.com/my-object', $link); + $this->assertEquals('https://s3.amazonaws.com/my-overriden-bucket/my-object', $link); } public function testCreatesUrlsForRegionalBuckets() { - $this->s3Client->setRegion('sa-east-1'); - - $link = $this->viewHelper->__invoke('my-object', 'my-bucket'); - $this->assertEquals('https://my-bucket.s3-sa-east-1.amazonaws.com/my-object', $link); + $s3Client = new S3Client([ + 'credentials' => [ + 'key' => '1234', + 'secret' => '5678' + ], + 'region' => 'sa-east-1', + 'version' => 'latest' + ]); + + $viewHelper = new S3Link($s3Client); + + $link = $viewHelper->__invoke('my-object', 'my-bucket'); + $this->assertEquals('https://s3-sa-east-1.amazonaws.com/my-bucket/my-object', $link); } public function testCreatesUrlsForNonUrlCompatibleBucketNames() @@ -115,12 +98,8 @@ public function testFailsWhenNoBucketSpecified() $link = $this->viewHelper->__invoke('my-object'); } - /** - * @dataProvider dataForLinkSigningTest - */ - public function testGenerateSignedLink($scheme) + public function testGenerateSignedLink() { - $this->viewHelper->setScheme($scheme); $expires = time() + 10; $actualResult = $this->viewHelper->__invoke('my-object', 'my-bucket', $expires); @@ -134,7 +113,7 @@ public function testGenerateSignedLink($scheme) $this->s3Client->getCredentials() ); $expectedResult = sprintf( - ltrim("{$scheme}://my-bucket.s3.amazonaws.com/my-object?AWSAccessKeyId=%s&Expires=%s&Signature=%s", ':'), + ltrim("https://my-bucket.s3.amazonaws.com/my-object?AWSAccessKeyId=%s&Expires=%s&Signature=%s", ':'), $this->s3Client->getCredentials()->getAccessKeyId(), $expires, urlencode($signature) @@ -142,13 +121,4 @@ public function testGenerateSignedLink($scheme) $this->assertEquals($expectedResult, $actualResult); } - - public function dataForLinkSigningTest() - { - return array( - array('https'), - array('http'), - array(NULL), - ); - } } From 0176ba6925ec2e8f968104ee4c4908a0493a28b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Gallego?= Date: Sat, 30 May 2015 18:07:49 +0200 Subject: [PATCH 3/5] Feedback --- CHANGELOG.md | 1 + README.md | 43 +++++++++++-------- composer.json | 4 +- config/aws_zf2.local.php.dist | 2 +- config/module.config.php | 18 ++++---- src/Factory/AwsFactory.php | 2 +- .../CloudFrontLinkViewHelperFactory.php | 4 +- .../DynamoDbSessionSaveHandlerFactory.php | 4 +- src/Factory/S3LinkViewHelperFactory.php | 4 +- src/Factory/S3RenameUploadFactory.php | 4 +- .../Exception/MissingBucketException.php | 2 +- src/Filter/File/S3RenameUpload.php | 4 +- src/Session/SaveHandler/DynamoDb.php | 2 +- .../Exception/InvalidDomainNameException.php | 2 +- src/View/Exception/InvalidSchemeException.php | 27 ------------ src/View/Helper/CloudFrontLink.php | 5 +-- src/View/Helper/S3Link.php | 4 +- tests/Tests/Factory/AwsFactoryTest.php | 4 +- .../DynamoDbSessionSaveHandlerFactoryTest.php | 8 ++-- .../Tests/Filter/File/S3RenameUploadTest.php | 6 +-- .../Session/SaveHandler/DynamoDbTest.php | 4 +- .../Tests/View/Helper/CloudFrontLinkTest.php | 6 +-- tests/Tests/View/Helper/S3LinkTest.php | 6 +-- tests/bootstrap.php | 2 +- 24 files changed, 73 insertions(+), 95 deletions(-) delete mode 100644 src/View/Exception/InvalidSchemeException.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 4c65cc9..f7a566e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ CHANGELOG * [BC] PHP minimum version is now 5.5 * [BC] Now require Aws SDK v3 +* [BC] To avoid name clashes, module name has been renamed from `Aws` to `AwsModule`. ## 1.2.0 diff --git a/README.md b/README.md index 2b6e2fe..2bbe93d 100644 --- a/README.md +++ b/README.md @@ -17,11 +17,13 @@ Install the module using Composer into your application's vendor directory. Add ```json { "require": { - "aws/aws-sdk-php-zf2": "1.2.*" + "aws/aws-sdk-php-zf2": "2.*" } } ``` +> If you are using AWS SDK v2, please use the 1.2.* version of the ZF2 module. + ## Configuration Enable the module in your `application.config.php` file. @@ -29,7 +31,7 @@ Enable the module in your `application.config.php` file. ```php return array( 'modules' => array( - 'Aws' + 'AwsModule' ) ); ``` @@ -41,13 +43,15 @@ the following: ```php array( - 'key' => '', - 'secret' => '', +return [ + 'aws' => [ + 'credentials' => [ + 'key' => '', + 'secret' => '', + ] 'region' => 'us-west-2' - ) -); + ] +]; ``` > NOTE: If you are using [IAM Instance Profile @@ -61,10 +65,12 @@ You can get the AWS service builder object from anywhere that the ZF2 service lo classes). The following example instantiates an Amazon DynamoDB client and creates a table in DynamoDB. ```php +use Aws\Sdk as Aws; + public function indexAction() { - $aws = $this->getServiceLocator()->get('aws'); - $client = $aws->get('dynamodb'); + $aws = $this->getServiceLocator()->get(Aws::class); + $client = $aws->create('DynamoDb'); $table = 'posts'; @@ -92,12 +98,10 @@ public function indexAction() ### View Helpers -Starting from version 1.0.2, the AWS SDK ZF2 Module now provides two view helpers to generate links for Amazon S3 and -Amazon CloudFront resources. +The AWS SDK ZF2 Module now provides two view helpers to generate links for Amazon S3 and Amazon CloudFront resources. -> **Note:** Both of the view helpers generate URLs with an HTTPS scheme by default. This is ideal for security, but -please keep in mind that Amazon CloudFront charges more for HTTPS requests. You can use a different scheme (e.g., HTTP) -by calling the `setScheme` method on either helper. +> **Note:** Starting from v2 of the AWS module, all URLs for both S3 and CloudFront are using HTTPS and this cannot +be modified. #### S3Link View Helper @@ -145,7 +149,7 @@ You can also create signed URLs for private content by passing a third argument ### Filters -Starting from version 1.0.3, the AWS SDK ZF2 module provides a simple file filter that allow to directly upload to S3. +The AWS SDK ZF2 module provides a simple file filter that allow to directly upload to S3. The `S3RenameUpload` extends `RenameUpload` class, so please refer to [its documentation](http://framework.zend.com/manual/2.2/en/modules/zend.filter.file.rename-upload.html#zend-filter-file-rename-upload) for available options. @@ -162,11 +166,11 @@ $files = $request->getFiles(); // Fetch the filter from the Filter Plugin Manager to automatically handle dependencies $filter = $serviceLocator->get('FilterManager')->get('S3RenameUpload'); -$filter->setOptions(array( +$filter->setOptions(’[ 'bucket' => 'my-bucket', 'target' => 'users/5/profile-picture.jpg', 'overwrite' => true -)); +]); $filter->filter($files['my-upload']); @@ -186,11 +190,12 @@ To follow the [ZF2 examples] the DynamoDB session save handler might be used like this: ```php +use AwsModule\Session\SaveHandler\DynamoDb as DynamoDbSaveHandler; use Zend\Session\SessionManager; // Assume we are in a context where $serviceLocator is a ZF2 service locator. -$saveHandler = $serviceLocator->get('Aws\Session\SaveHandler\DynamoDb'); +$saveHandler = $serviceLocator->get(DynamoDbSaveHandler::class); $manager = new SessionManager(); $manager->setSaveHandler($saveHandler); diff --git a/composer.json b/composer.json index e68eca4..8b4399c 100644 --- a/composer.json +++ b/composer.json @@ -19,7 +19,7 @@ }, "autoload": { "psr-4": { - "Aws\\": "src/" + "AwsModule\\": "src/" }, "classmap": [ "./Module.php" @@ -27,7 +27,7 @@ }, "autoload-dev": { "psr-4": { - "AwsTest\\": "tests/" + "AwsModuleTests\\": "tests/" } } } diff --git a/config/aws_zf2.local.php.dist b/config/aws_zf2.local.php.dist index a8bdeff..e008e2d 100644 --- a/config/aws_zf2.local.php.dist +++ b/config/aws_zf2.local.php.dist @@ -12,7 +12,7 @@ return [ 'save_handler' => [ 'dynamodb' => [ // Locking strategy used for doing session locking. - // 'locking_strategy' => null, + // 'locking' => null, // Name of the DynamoDB table in which to store the // sessions. diff --git a/config/module.config.php b/config/module.config.php index 718a4ae..71084a3 100644 --- a/config/module.config.php +++ b/config/module.config.php @@ -1,15 +1,15 @@ [ diff --git a/src/Factory/AwsFactory.php b/src/Factory/AwsFactory.php index d999e6f..d4a92a6 100644 --- a/src/Factory/AwsFactory.php +++ b/src/Factory/AwsFactory.php @@ -14,7 +14,7 @@ * permissions and limitations under the License. */ -namespace Aws\Factory; +namespace AwsModule\Factory; use Aws\Sdk as AwsSdk; use Zend\ServiceManager\FactoryInterface; diff --git a/src/Factory/CloudFrontLinkViewHelperFactory.php b/src/Factory/CloudFrontLinkViewHelperFactory.php index 845fc44..6e4a39b 100644 --- a/src/Factory/CloudFrontLinkViewHelperFactory.php +++ b/src/Factory/CloudFrontLinkViewHelperFactory.php @@ -14,10 +14,10 @@ * permissions and limitations under the License. */ -namespace Aws\Factory; +namespace AwsModule\Factory; use Aws\Sdk as AwsSdk; -use Aws\View\Helper\CloudFrontLink; +use AwsModule\View\Helper\CloudFrontLink; use Zend\ServiceManager\FactoryInterface; use Zend\ServiceManager\ServiceLocatorInterface; diff --git a/src/Factory/DynamoDbSessionSaveHandlerFactory.php b/src/Factory/DynamoDbSessionSaveHandlerFactory.php index b9e5bf4..152a93a 100644 --- a/src/Factory/DynamoDbSessionSaveHandlerFactory.php +++ b/src/Factory/DynamoDbSessionSaveHandlerFactory.php @@ -14,11 +14,11 @@ * permissions and limitations under the License. */ -namespace Aws\Factory; +namespace AwsModule\Factory; use Aws\Sdk as AwsSdk; use Aws\DynamoDb\SessionHandler; -use Aws\Session\SaveHandler\DynamoDb as DynamoDbSaveHandler; +use AwsModule\Session\SaveHandler\DynamoDb as DynamoDbSaveHandler; use Zend\ServiceManager\Exception\ServiceNotCreatedException; use Zend\ServiceManager\FactoryInterface; use Zend\ServiceManager\ServiceLocatorInterface; diff --git a/src/Factory/S3LinkViewHelperFactory.php b/src/Factory/S3LinkViewHelperFactory.php index 30a233d..6cc492b 100644 --- a/src/Factory/S3LinkViewHelperFactory.php +++ b/src/Factory/S3LinkViewHelperFactory.php @@ -14,10 +14,10 @@ * permissions and limitations under the License. */ -namespace Aws\Factory; +namespace AwsModule\Factory; use Aws\Sdk as AwsSdk; -use Aws\View\Helper\S3Link; +use AwsModule\View\Helper\S3Link; use Zend\ServiceManager\FactoryInterface; use Zend\ServiceManager\ServiceLocatorInterface; diff --git a/src/Factory/S3RenameUploadFactory.php b/src/Factory/S3RenameUploadFactory.php index 12c2745..b2887c5 100644 --- a/src/Factory/S3RenameUploadFactory.php +++ b/src/Factory/S3RenameUploadFactory.php @@ -14,10 +14,10 @@ * permissions and limitations under the License. */ -namespace Aws\Factory; +namespace AwsModule\Factory; use Aws\Sdk as AwsSdk; -use Aws\Filter\File\S3RenameUpload; +use AwsModule\Filter\File\S3RenameUpload; use Zend\ServiceManager\FactoryInterface; use Zend\ServiceManager\ServiceLocatorInterface; diff --git a/src/Filter/Exception/MissingBucketException.php b/src/Filter/Exception/MissingBucketException.php index ef22246..a653a35 100644 --- a/src/Filter/Exception/MissingBucketException.php +++ b/src/Filter/Exception/MissingBucketException.php @@ -14,7 +14,7 @@ * permissions and limitations under the License. */ -namespace Aws\Filter\Exception; +namespace AwsModule\Filter\Exception; use InvalidArgumentException; diff --git a/src/Filter/File/S3RenameUpload.php b/src/Filter/File/S3RenameUpload.php index 5edd981..eb7787f 100644 --- a/src/Filter/File/S3RenameUpload.php +++ b/src/Filter/File/S3RenameUpload.php @@ -14,10 +14,10 @@ * permissions and limitations under the License. */ -namespace Aws\Filter\File; +namespace AwsModule\Filter\File; use Aws\S3\S3Client; -use Aws\Filter\Exception\MissingBucketException; +use AwsModule\Filter\Exception\MissingBucketException; use Zend\Filter\File\RenameUpload; /** diff --git a/src/Session/SaveHandler/DynamoDb.php b/src/Session/SaveHandler/DynamoDb.php index a3fae05..258123a 100644 --- a/src/Session/SaveHandler/DynamoDb.php +++ b/src/Session/SaveHandler/DynamoDb.php @@ -14,7 +14,7 @@ * permissions and limitations under the License. */ -namespace Aws\Session\SaveHandler; +namespace AwsModule\Session\SaveHandler; use Aws\Dynamodb\SessionHandler; use Zend\Session\SaveHandler\SaveHandlerInterface; diff --git a/src/View/Exception/InvalidDomainNameException.php b/src/View/Exception/InvalidDomainNameException.php index df36720..3902641 100644 --- a/src/View/Exception/InvalidDomainNameException.php +++ b/src/View/Exception/InvalidDomainNameException.php @@ -14,7 +14,7 @@ * permissions and limitations under the License. */ -namespace Aws\View\Exception; +namespace AwsModule\View\Exception; use InvalidArgumentException; diff --git a/src/View/Exception/InvalidSchemeException.php b/src/View/Exception/InvalidSchemeException.php deleted file mode 100644 index 3cb63f5..0000000 --- a/src/View/Exception/InvalidSchemeException.php +++ /dev/null @@ -1,27 +0,0 @@ -createService($serviceLocator); $this->assertInstanceOf(DynamoDbSaveHandler::class, $saveHandler); diff --git a/tests/Tests/Filter/File/S3RenameUploadTest.php b/tests/Tests/Filter/File/S3RenameUploadTest.php index bf1825a..91cce63 100644 --- a/tests/Tests/Filter/File/S3RenameUploadTest.php +++ b/tests/Tests/Filter/File/S3RenameUploadTest.php @@ -14,10 +14,10 @@ * permissions and limitations under the License. */ -namespace AwsTests\Filter\File; +namespace AwsModuleTests\Filter\File; -use Aws\Filter\Exception\MissingBucketException; -use Aws\Filter\File\S3RenameUpload; +use AwsModule\Filter\Exception\MissingBucketException; +use AwsModule\Filter\File\S3RenameUpload; use Aws\S3\S3Client; use ReflectionMethod; diff --git a/tests/Tests/Session/SaveHandler/DynamoDbTest.php b/tests/Tests/Session/SaveHandler/DynamoDbTest.php index c9670ce..30d44ab 100644 --- a/tests/Tests/Session/SaveHandler/DynamoDbTest.php +++ b/tests/Tests/Session/SaveHandler/DynamoDbTest.php @@ -14,10 +14,10 @@ * permissions and limitations under the License. */ -namespace AwsTests\Session\SaveHandler; +namespace AwsModuleTests\Session\SaveHandler; use Aws\DynamoDb\SessionHandler; -use Aws\Session\SaveHandler\DynamoDb as DynamoDbSaveHandler; +use AwsModule\Session\SaveHandler\DynamoDb as DynamoDbSaveHandler; class DynamoDbTest extends \PHPUnit_Framework_TestCase { diff --git a/tests/Tests/View/Helper/CloudFrontLinkTest.php b/tests/Tests/View/Helper/CloudFrontLinkTest.php index 8629e3a..1e1e1d9 100644 --- a/tests/Tests/View/Helper/CloudFrontLinkTest.php +++ b/tests/Tests/View/Helper/CloudFrontLinkTest.php @@ -14,10 +14,10 @@ * permissions and limitations under the License. */ -namespace AwsTests\View\Helper; +namespace AwsModuleTests\View\Helper; use Aws\CloudFront\CloudFrontClient; -use Aws\View\Helper\CloudFrontLink; +use AwsModule\View\Helper\CloudFrontLink; class CloudFrontLinkTest extends \PHPUnit_Framework_TestCase { @@ -86,7 +86,7 @@ public function testCanUseCustomHostname() } /** - * @expectedException \Aws\View\Exception\InvalidDomainNameException + * @expectedException \AwsModule\View\Exception\InvalidDomainNameException */ public function testFailsWhenDomainIsInvalid() { diff --git a/tests/Tests/View/Helper/S3LinkTest.php b/tests/Tests/View/Helper/S3LinkTest.php index fb95b30..df893c8 100644 --- a/tests/Tests/View/Helper/S3LinkTest.php +++ b/tests/Tests/View/Helper/S3LinkTest.php @@ -14,10 +14,10 @@ * permissions and limitations under the License. */ -namespace AwsTests\View\Helper; +namespace AwsModuleTests\View\Helper; use Aws\S3\S3Client; -use Aws\View\Helper\S3Link; +use AwsModule\View\Helper\S3Link; class S3LinkTest extends \PHPUnit_Framework_TestCase { @@ -91,7 +91,7 @@ public function testCreatesUrlsForNonUrlCompatibleBucketNames() } /** - * @expectedException \Aws\View\Exception\InvalidDomainNameException + * @expectedException \AwsModule\View\Exception\InvalidDomainNameException */ public function testFailsWhenNoBucketSpecified() { diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 96008e3..945a116 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -15,6 +15,6 @@ } /* @var $loader \Composer\Autoload\ClassLoader */ -$loader->add('Aws\\Tests\\', __DIR__); +$loader->add('AwsModule\\Tests\\', __DIR__); unset($files, $file, $loader); From ff711f9e3479e3bedf05ea456f802ce1ac328b0b Mon Sep 17 00:00:00 2001 From: Jeremy Lindblom Date: Tue, 16 Jun 2015 14:25:19 -0700 Subject: [PATCH 4/5] Cleaned up and reviewed changes from @bakura10 --- Module.php | 14 ----- composer.json | 2 +- src/Factory/AwsFactory.php | 14 ----- .../CloudFrontLinkViewHelperFactory.php | 14 ----- .../DynamoDbSessionSaveHandlerFactory.php | 14 ----- src/Factory/S3LinkViewHelperFactory.php | 14 ----- src/Factory/S3RenameUploadFactory.php | 14 ----- .../Exception/MissingBucketException.php | 14 ----- src/Filter/File/S3RenameUpload.php | 14 ----- src/Session/SaveHandler/DynamoDb.php | 14 ----- .../Exception/InvalidDomainNameException.php | 14 ----- src/View/Helper/CloudFrontLink.php | 14 ----- src/View/Helper/S3Link.php | 14 ----- tests/{Tests => }/Factory/AwsFactoryTest.php | 16 +---- .../DynamoDbSessionSaveHandlerFactoryTest.php | 16 +---- .../Filter/File/S3RenameUploadTest.php | 16 +---- .../Session/SaveHandler/DynamoDbTest.php | 18 +----- .../View/Helper/CloudFrontLinkTest.php | 18 +----- tests/{Tests => }/View/Helper/S3LinkTest.php | 59 ++++++------------- tests/bootstrap.php | 3 - 20 files changed, 27 insertions(+), 289 deletions(-) rename tests/{Tests => }/Factory/AwsFactoryTest.php (50%) rename tests/{Tests => }/Factory/DynamoDbSessionSaveHandlerFactoryTest.php (75%) rename tests/{Tests => }/Filter/File/S3RenameUploadTest.php (76%) rename tests/{Tests => }/Session/SaveHandler/DynamoDbTest.php (81%) rename tests/{Tests => }/View/Helper/CloudFrontLinkTest.php (85%) rename tests/{Tests => }/View/Helper/S3LinkTest.php (56%) diff --git a/Module.php b/Module.php index 333b845..2317e59 100644 --- a/Module.php +++ b/Module.php @@ -1,18 +1,4 @@ assertEquals('https://s3-sa-east-1.amazonaws.com/my-bucket/my-object', $link); } - public function testCreatesUrlsForNonUrlCompatibleBucketNames() - { - $link = $this->viewHelper->__invoke('my-object', 'my.bucket'); - $this->assertEquals('https://s3.amazonaws.com/my.bucket/my-object', $link); - } - /** * @expectedException \AwsModule\View\Exception\InvalidDomainNameException */ @@ -101,24 +81,23 @@ public function testFailsWhenNoBucketSpecified() public function testGenerateSignedLink() { $expires = time() + 10; + $s3Client = new S3Client([ + 'credentials' => [ + 'key' => '1234', + 'secret' => '5678', + 'token' => '999' + ], + 'region' => 'sa-east-1', + 'version' => 'latest' + ]); + + $viewHelper = new S3Link($s3Client); + + $url = $viewHelper->__invoke('my-object', 'my-bucket', $expires); - $actualResult = $this->viewHelper->__invoke('my-object', 'my-bucket', $expires); - - // Build expected signature - $request = $this->s3Client->get($this->viewHelper->__invoke('my-object', 'my-bucket')); - $request->getParams()->set('s3.resource', '/my-bucket/my-object'); - $signature = $this->s3Client->getSignature(); - $signature = $signature->signString( - $signature->createCanonicalizedString($request, $expires), - $this->s3Client->getCredentials() - ); - $expectedResult = sprintf( - ltrim("https://my-bucket.s3.amazonaws.com/my-object?AWSAccessKeyId=%s&Expires=%s&Signature=%s", ':'), - $this->s3Client->getCredentials()->getAccessKeyId(), - $expires, - urlencode($signature) - ); - - $this->assertEquals($expectedResult, $actualResult); + $this->assertStringStartsWith('https://s3-sa-east-1.amazonaws.com/my-bucket/my-object?', $url); + $this->assertContains('X-Amz-Security-Token=999', $url); + $this->assertContains('X-Amz-Content-Sha256=', $url); + $this->assertContains('X-Amz-Expires=', $url); } } diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 945a116..187cf38 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -14,7 +14,4 @@ throw new RuntimeException('The vendor/autoload.php could not be found. Did you run `php composer.phar install`?'); } -/* @var $loader \Composer\Autoload\ClassLoader */ -$loader->add('AwsModule\\Tests\\', __DIR__); - unset($files, $file, $loader); From 70d174f5b7df1d40dac2a269bca6c5aac62d37e7 Mon Sep 17 00:00:00 2001 From: Jeremy Lindblom Date: Tue, 16 Jun 2015 14:44:30 -0700 Subject: [PATCH 5/5] Updated TravisCI config. --- .travis.yml | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/.travis.yml b/.travis.yml index afa9172..f8cb938 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,10 +1,11 @@ language: php + php: - - 5.3 - - 5.4 - 5.5 -before_script: -- sh -c 'if [ $(php -r "echo PHP_MINOR_VERSION;") -le 4 ]; then echo "extension = apc.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini; fi;' -- cp phpunit.xml.dist phpunit.xml -- composer install --dev -script: vendor/bin/phpunit --coverage-text + - 5.6 + +sudo: false + +install: travis_retry composer install --no-interaction --prefer-source + +script: vendor/bin/phpunit