@@ -19,7 +19,7 @@ final class FirebaseProjectManagerTest extends TestCase
19
19
{
20
20
protected function defineEnvironment ($ app ): void
21
21
{
22
- $ app ['config ' ]->set ('firebase.projects.app.credentials.file ' , __DIR__ . '/_fixtures/service_account.json ' );
22
+ $ app ['config ' ]->set ('firebase.projects.app.credentials ' , __DIR__ . '/_fixtures/service_account.json ' );
23
23
}
24
24
25
25
/**
@@ -66,7 +66,28 @@ public function calls_are_passed_to_default_project(): void
66
66
/**
67
67
* @test
68
68
*/
69
- public function credentials_can_be_configured (): void
69
+ public function credentials_can_be_configured_using_a_json_file (): void
70
+ {
71
+ // Reference credentials
72
+ $ credentialsPath = \realpath (__DIR__ . '/_fixtures/service_account.json ' );
73
+ $ credentials = \json_decode (\file_get_contents ($ credentialsPath ), true );
74
+
75
+ // Set configuration and retrieve project
76
+ $ projectName = 'app ' ;
77
+ $ this ->app ->config ->set ('firebase.projects. ' . $ projectName . '.credentials ' , \realpath (__DIR__ . '/_fixtures/service_account.json ' ));
78
+ $ factory = $ this ->factoryForProject ($ projectName );
79
+
80
+ // Retrieve service account
81
+ $ serviceAccount = $ this ->getAccessibleProperty ($ factory , 'serviceAccount ' )->getValue ($ factory );
82
+
83
+ // Validate value
84
+ $ this ->assertSame ($ credentials , $ serviceAccount );
85
+ }
86
+
87
+ /**
88
+ * @test
89
+ */
90
+ public function json_file_credentials_can_be_used_using_the_deprecated_configuration_entry (): void
70
91
{
71
92
// Reference credentials
72
93
$ credentialsPath = \realpath (__DIR__ . '/_fixtures/service_account.json ' );
@@ -84,6 +105,34 @@ public function credentials_can_be_configured(): void
84
105
$ this ->assertSame ($ credentials , $ serviceAccount );
85
106
}
86
107
108
+ /**
109
+ * @test
110
+ */
111
+ public function credentials_can_be_configured_using_an_array (): void
112
+ {
113
+ // Set configuration and retrieve project
114
+ $ projectName = 'app ' ;
115
+ $ this ->app ->config ->set ('firebase.projects. ' . $ projectName . '.credentials ' , $ credentials = [
116
+ 'type ' => 'service_account ' ,
117
+ 'project_id ' => 'project ' ,
118
+ 'private_key_id ' => 'private_key_id ' ,
119
+ 'private_key ' => '-----BEGIN PRIVATE KEY-----\nsome gibberish\n-----END PRIVATE KEY-----\n ' ,
120
+ 'client_email ' =>
'[email protected] ' ,
121
+ 'client_id ' => '1234567890 ' ,
122
+ 'auth_uri ' => 'https://some.google.tld/o/oauth2/auth ' ,
123
+ 'token_uri ' => 'https://some.google.tld/o/oauth2/token ' ,
124
+ 'auth_provider_x509_cert_url ' => 'https://some.google.tld/oauth2/v1/certs ' ,
125
+ 'client_x509_cert_url ' => 'https://some.google.tld/robot/v1/metadata/x509/user%40project.iam.gserviceaccount.com ' ,
126
+ ]);
127
+ $ factory = $ this ->factoryForProject ($ projectName );
128
+
129
+ // Retrieve service account
130
+ $ serviceAccount = $ this ->getAccessibleProperty ($ factory , 'serviceAccount ' )->getValue ($ factory );
131
+
132
+ // Validate value
133
+ $ this ->assertSame ($ credentials , $ serviceAccount );
134
+ }
135
+
87
136
/**
88
137
* @test
89
138
*/
@@ -101,8 +150,8 @@ public function projects_can_have_different_credentials(): void
101
150
$ secondProjectName = 'another-app ' ;
102
151
103
152
// Set service accounts explicitly
104
- $ this ->app ->config ->set ('firebase.projects. ' . $ projectName . '.credentials.file ' , \realpath (__DIR__ . '/_fixtures/service_account.json ' ));
105
- $ this ->app ->config ->set ('firebase.projects. ' . $ secondProjectName . '.credentials.file ' , \realpath (__DIR__ . '/_fixtures/another_service_account.json ' ));
153
+ $ this ->app ->config ->set ('firebase.projects. ' . $ projectName . '.credentials ' , \realpath (__DIR__ . '/_fixtures/service_account.json ' ));
154
+ $ this ->app ->config ->set ('firebase.projects. ' . $ secondProjectName . '.credentials ' , \realpath (__DIR__ . '/_fixtures/another_service_account.json ' ));
106
155
107
156
// Retrieve factories and service accounts
108
157
$ factory = $ this ->factoryForProject ($ projectName );
0 commit comments