1- <?php
2- /**
3- * Copyright 2013 Amazon.com, Inc. or its affiliates. All Rights Reserved.
4- *
5- * Licensed under the Apache License, Version 2.0 (the "License").
6- * You may not use this file except in compliance with the License.
7- * A copy of the License is located at
8- *
9- * http://aws.amazon.com/apache2.0
10- *
11- * or in the "license" file accompanying this file. This file is distributed
12- * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
13- * express or implied. See the License for the specific language governing
14- * permissions and limitations under the License.
15- */
16-
17- namespace Aws \Laravel \Test ;
18-
19- /**
20- * AwsServiceProvider test cases
21- */
22- class AwsServiceProviderTest extends AwsServiceProviderTestCase
23- {
24- public function testRegisterAwsServiceProviderWithGlobalConfig ()
1+ <?php namespace Aws \Laravel \Test ;
2+
3+ use Aws \Laravel \AwsFacade as AWS ;
4+ use Aws \Laravel \AwsServiceProvider ;
5+ use Illuminate \Config \Repository ;
6+ use Illuminate \Foundation \Application ;
7+
8+ class AwsServiceProviderTest extends \PHPUnit_Framework_TestCase {
9+
10+ public function testFacadeCanBeResolvedToServiceInstance ()
11+ {
12+ $ app = $ this ->setupApplication ();
13+ $ this ->setupServiceProvider ($ app );
14+
15+ // Mount facades
16+ AWS ::setFacadeApplication ($ app );
17+
18+ // Get an instance of a client (S3) via its facade
19+ $ s3 = AWS ::get ('s3 ' );
20+ $ this ->assertInstanceOf ('Aws\S3\S3Client ' , $ s3 );
21+ }
22+
23+ public function testRegisterAwsServiceProviderWithConfigFile ()
2524 {
2625 $ app = $ this ->setupApplication ();
2726 $ this ->setupServiceProvider ($ app );
2827
2928 // Simulate global config; specify config file
30- $ app ['config ' ]->set ('aws ' , array (
29+ $ app ['config ' ]->set ('aws ' , [
3130 'config_file ' => __DIR__ . '/test_services.json '
32- ) );
31+ ] );
3332
3433 // Get an instance of a client (S3)
3534 /** @var $s3 \Aws\S3\S3Client */
@@ -39,15 +38,9 @@ public function testRegisterAwsServiceProviderWithGlobalConfig()
3938 // Verify that the client received the credentials from the global config
4039 $ this ->assertEquals ('change_me ' , $ s3 ->getCredentials ()->getAccessKeyId ());
4140 $ this ->assertEquals ('change_me ' , $ s3 ->getCredentials ()->getSecretKey ());
42-
43- // Make sure the user agent contains Laravel information
44- $ command = $ s3 ->getCommand ('ListBuckets ' );
45- $ request = $ command ->prepare ();
46- $ s3 ->dispatch ('command.before_send ' , array ('command ' => $ command ));
47- $ this ->assertRegExp ('/.+Laravel\/.+L4MOD\/.+/ ' , (string ) $ request ->getHeader ('User-Agent ' ));
4841 }
4942
50- public function testRegisterAwsServiceProviderWithPackageConfig ()
43+ public function testRegisterAwsServiceProviderWithPackageConfigAndEnv ()
5144 {
5245 $ app = $ this ->setupApplication ();
5346 $ this ->setupServiceProvider ($ app );
@@ -58,8 +51,9 @@ public function testRegisterAwsServiceProviderWithPackageConfig()
5851 $ this ->assertInstanceOf ('Aws\S3\S3Client ' , $ s3 );
5952
6053 // Verify that the client received the credentials from the package config
61- $ this ->assertEquals ('YOUR_AWS_ACCESS_KEY_ID ' , $ s3 ->getCredentials ()->getAccessKeyId ());
62- $ this ->assertEquals ('YOUR_AWS_SECRET_KEY ' , $ s3 ->getCredentials ()->getSecretKey ());
54+ $ this ->assertEquals ('foo ' , $ s3 ->getCredentials ()->getAccessKeyId ());
55+ $ this ->assertEquals ('bar ' , $ s3 ->getCredentials ()->getSecretKey ());
56+ $ this ->assertEquals ('baz ' , $ s3 ->getRegion ());
6357 }
6458
6559 public function testServiceNameIsProvided ()
@@ -68,4 +62,33 @@ public function testServiceNameIsProvided()
6862 $ provider = $ this ->setupServiceProvider ($ app );
6963 $ this ->assertContains ('aws ' , $ provider ->provides ());
7064 }
65+
66+ /**
67+ * @return Application
68+ */
69+ private function setupApplication ()
70+ {
71+ // Create the application such that the config is loaded
72+ $ app = new Application ();
73+ $ app ->setBasePath (sys_get_temp_dir ());
74+ $ app ->instance ('config ' , new Repository ());
75+
76+ return $ app ;
77+ }
78+
79+ /**
80+ * @param Application $app
81+ *
82+ * @return AwsServiceProvider
83+ */
84+ private function setupServiceProvider (Application $ app )
85+ {
86+ // Create and register the provider
87+ $ provider = new AwsServiceProvider ($ app );
88+ $ app ->register ($ provider );
89+ $ provider ->boot ();
90+
91+ return $ provider ;
92+ }
93+
7194}
0 commit comments