@@ -19,7 +19,7 @@ final class FirebaseProjectManagerTest extends TestCase
1919{
2020 protected function defineEnvironment ($ app ): void
2121 {
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 ' );
2323 }
2424
2525 /**
@@ -66,7 +66,28 @@ public function calls_are_passed_to_default_project(): void
6666 /**
6767 * @test
6868 */
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
7091 {
7192 // Reference credentials
7293 $ credentialsPath = \realpath (__DIR__ . '/_fixtures/service_account.json ' );
@@ -84,6 +105,34 @@ public function credentials_can_be_configured(): void
84105 $ this ->assertSame ($ credentials , $ serviceAccount );
85106 }
86107
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+
87136 /**
88137 * @test
89138 */
@@ -101,8 +150,8 @@ public function projects_can_have_different_credentials(): void
101150 $ secondProjectName = 'another-app ' ;
102151
103152 // 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 ' ));
106155
107156 // Retrieve factories and service accounts
108157 $ factory = $ this ->factoryForProject ($ projectName );
0 commit comments