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 ()
25
24
{
26
25
$ app = $ this ->setupApplication ();
27
26
$ this ->setupServiceProvider ($ app );
28
27
29
28
// Simulate global config; specify config file
30
- $ app ['config ' ]->set ('aws ' , array (
29
+ $ app ['config ' ]->set ('aws ' , [
31
30
'config_file ' => __DIR__ . '/test_services.json '
32
- ) );
31
+ ] );
33
32
34
33
// Get an instance of a client (S3)
35
34
/** @var $s3 \Aws\S3\S3Client */
@@ -39,15 +38,9 @@ public function testRegisterAwsServiceProviderWithGlobalConfig()
39
38
// Verify that the client received the credentials from the global config
40
39
$ this ->assertEquals ('change_me ' , $ s3 ->getCredentials ()->getAccessKeyId ());
41
40
$ 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 ' ));
48
41
}
49
42
50
- public function testRegisterAwsServiceProviderWithPackageConfig ()
43
+ public function testRegisterAwsServiceProviderWithPackageConfigAndEnv ()
51
44
{
52
45
$ app = $ this ->setupApplication ();
53
46
$ this ->setupServiceProvider ($ app );
@@ -58,8 +51,9 @@ public function testRegisterAwsServiceProviderWithPackageConfig()
58
51
$ this ->assertInstanceOf ('Aws\S3\S3Client ' , $ s3 );
59
52
60
53
// 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 ());
63
57
}
64
58
65
59
public function testServiceNameIsProvided ()
@@ -68,4 +62,33 @@ public function testServiceNameIsProvided()
68
62
$ provider = $ this ->setupServiceProvider ($ app );
69
63
$ this ->assertContains ('aws ' , $ provider ->provides ());
70
64
}
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
+
71
94
}
0 commit comments