@@ -26,7 +26,6 @@ class BaseTest extends TestCase
2626{
2727 private $ key ;
2828 private $ client ;
29- protected $ testDir = __DIR__ ;
3029
3130 public function getClient ()
3231 {
@@ -140,21 +139,21 @@ public function tryToGetAnAccessToken(Google_Client $client)
140139
141140 private function getClientIdAndSecret ()
142141 {
143- $ clientId = getenv ('GCLOUD_CLIENT_ID ' ) ?: null ;
144- $ clientSecret = getenv ('GCLOUD_CLIENT_SECRET ' ) ?: null ;
142+ $ clientId = getenv ('GOOGLE_CLIENT_ID ' ) ?: null ;
143+ $ clientSecret = getenv ('GOOGLE_CLIENT_SECRET ' ) ?: null ;
145144
146145 return array ($ clientId , $ clientSecret );
147146 }
148147
149- public function checkClientCredentials ()
148+ protected function checkClientCredentials ()
150149 {
151150 list ($ clientId , $ clientSecret ) = $ this ->getClientIdAndSecret ();
152151 if (!($ clientId && $ clientSecret )) {
153- $ this ->markTestSkipped ("Test requires GCLOUD_CLIENT_ID and GCLOUD_CLIENT_SECRET to be set " );
152+ $ this ->markTestSkipped ("Test requires GOOGLE_CLIENT_ID and GOOGLE_CLIENT_SECRET to be set " );
154153 }
155154 }
156155
157- public function checkServiceAccountCredentials ()
156+ protected function checkServiceAccountCredentials ()
158157 {
159158 if (!$ f = getenv ('GOOGLE_APPLICATION_CREDENTIALS ' )) {
160159 $ skip = "This test requires the GOOGLE_APPLICATION_CREDENTIALS environment variable to be set \n"
@@ -171,21 +170,17 @@ public function checkServiceAccountCredentials()
171170 return true ;
172171 }
173172
174- public function checkKey ()
173+ protected function checkKey ()
175174 {
176- $ this ->key = $ this ->loadKey ();
177-
178- if (!strlen ($ this ->key )) {
179- $ this ->markTestSkipped ("Test requires api key \nYou can create one in your developer console " );
180- return false ;
181- }
182- }
183-
184- public function loadKey ()
185- {
186- if (file_exists ($ f = __DIR__ . DIRECTORY_SEPARATOR . '.apiKey ' )) {
187- return file_get_contents ($ f );
175+ if (file_exists ($ apiKeyFile = __DIR__ . DIRECTORY_SEPARATOR . '.apiKey ' )) {
176+ $ apiKey = file_get_contents ($ apiKeyFile );
177+ } elseif (!$ apiKey = getenv ('GOOGLE_API_KEY ' )) {
178+ $ this ->markTestSkipped (
179+ "Test requires api key \nYou can create one in your developer console "
180+ );
181+ file_put_contents ($ apiKeyFile , $ apiKey );
188182 }
183+ $ this ->key = $ apiKey ;
189184 }
190185
191186 protected function loadExample ($ example )
0 commit comments