From 30d71ab4c8b266b2d5f620c1cc49c069eaa97bca Mon Sep 17 00:00:00 2001 From: Mouddene Date: Sat, 23 Jan 2016 03:47:29 +0100 Subject: [PATCH] AWS service unit tests --- Tests/Services/SESMailingServiceTest.php | 64 ++++++++++++++++++++++++ Tests/Services/StorageServiceTest.php | 45 +++++++++++++++++ aws.config.yml | 23 +++------ 3 files changed, 116 insertions(+), 16 deletions(-) create mode 100644 Tests/Services/SESMailingServiceTest.php create mode 100644 Tests/Services/StorageServiceTest.php diff --git a/Tests/Services/SESMailingServiceTest.php b/Tests/Services/SESMailingServiceTest.php new file mode 100644 index 0000000..589f7be --- /dev/null +++ b/Tests/Services/SESMailingServiceTest.php @@ -0,0 +1,64 @@ +createClient(); + $ses = $client->getContainer()->get('amazon_SES'); + assert( $ses !== null, 'SES is not defined'); + } + + /** + * tests if verified email address exist in global config + */ + public function testMailingServiceInjection() + { + $client = $this->createClient(); + $mailer = $client->getContainer()->get('ws.service.mailing'); + assert( $mailer !== null, 'Mailing Service injection is not working'); + assert( $mailer instanceof MailingService, 'given Object is not an instance of MailingService'); + } + + public function testSendMail() + { + $client = $this->createClient(); + /**@var $mailer MailingService */ + $mailer = $client->getContainer()->get('ws.service.mailing'); + $mailer->setSubject('Drivy UNIT TEST') + ->addToAddress('mouddene@gmail.com') + ->setMessage('UNIT TEST is working'); + $result = $mailer->sendEmail(); + + var_dump($result); + assert(true === true, "todo"); + } + + public function testListVerifiedEmailsAddresses() + { + $client = $this->createClient(); + /**@var $ses SesClient */ + + $ses = $client->getContainer()->get('amazon_SES'); + + $list = $ses->listVerifiedEmailAddresses(array()); + + // TODO : + assert(true == true, 'source email is not verified'); + + + } diff --git a/Tests/Services/StorageServiceTest.php b/Tests/Services/StorageServiceTest.php new file mode 100644 index 0000000..f89ab47 --- /dev/null +++ b/Tests/Services/StorageServiceTest.php @@ -0,0 +1,45 @@ + + * + * Initial version created on: 23/01/16 23:59 + * + */ + +class StorageServiceTest extends WebTestCase +{ + + public function testServiceInjection(){ + $client = $this->createClient(); + $s3 = $client->getContainer()->get('amazon_S3'); + assert( $s3 !== null, 'Requested service unavailble'); + } + + public function testDoesContainerHasUploadBucketParameter(){ + $client = $this->createClient(); + assert($client->getContainer()->hasParameter('the_phalcons_amazon_web_services.services.S3.bucket') === true, "Container hasn't the_phalcons_amazon_web_services.services.S3.bucket parameter"); + } + + public function testCreateBucket(){ + /** @var S3Client $client */ + $client = $this->createClient(); + $client->createBucket(array( + 'Bucket' => 'mybucket', + 'LocationConstraint' => 'us-west-2', + )); + + assert($client->doesBucketExist("mybucket") === true, "bucket doesn't exist !!!") + $client->deleteBucket(array( + 'Bucket' => 'mybucket', + 'LocationConstraint' => 'us-west-2', + )); + + assert($client->doesBucketExist("mybucket") === false, "bucket hasn't been deleted !!!") + } + +} diff --git a/aws.config.yml b/aws.config.yml index f45a0c8..42577aa 100644 --- a/aws.config.yml +++ b/aws.config.yml @@ -1,11 +1,13 @@ thephalcons_amazon_web_services: - enable_extensions: false + # for stream wrapper use : [S3, SES ...] + enable_extensions: [] credentials: key: secret: shared_config: - region: 'eu_west_1' + region: %aws_region% + version: %aws_version% account_id: %aws_account_id% canonical_id: %aws_canonical_id% canonical_name: %aws_canonical_name% @@ -13,29 +15,18 @@ thephalcons_amazon_web_services: cloudfront_keypair: %aws_cloudfront_keypair% cloudfront_pem: %aws_cloudfront_pem% default_cache_config: null - enable_extensions: [] certificate_authority: false disable_auto_config: false services: - #For each service you want to inject: - #add service name exp : - #SQS: - #set to true if you'ill use it as service in your code - #false for global config - #injectable: true + S3: - #injectable set to true means that the wrapper service will be injected in runtime - injectable: true bucket: #... add all used bucket like assets bucket or upload bucket, can be accessed # using container in your code - # example $container->getParameter('services.S3.{key}') CloudFront: - injectable: false - #asset_distribution: http://d2aqddmeyyyfie.cloudfront.net + web_distribution: http://xxxxxxxxxxxxxx.cloudfront.net #upload_distribution: http://xxxxxxxxxxxxxx.cloudfront.net SES: - injectable: true + verified_addresse: #for more information how to use SES service #http://docs.aws.amazon.com/aws-sdk-php/v2/guide/service-ses.html - #verified_addresse: