public function testScopeIsAlwaysArray()
 {
     // include the mock AppIdentityService class
     require_once __DIR__ . '/../mocks/AppIdentityService.php';
     $scope1 = ['scopeA', 'scopeB'];
     $scope2 = 'scopeA scopeB';
     $scope3 = 'scopeA';
     $_SERVER['SERVER_SOFTWARE'] = 'Google App Engine';
     $g = new AppIdentityCredentials($scope1);
     $g->fetchAuthToken();
     $this->assertEquals($scope1, AppIdentityService::$scope);
     $g = new AppIdentityCredentials($scope2);
     $g->fetchAuthToken();
     $this->assertEquals(explode(' ', $scope2), AppIdentityService::$scope);
     $g = new AppIdentityCredentials($scope3);
     $g->fetchAuthToken();
     $this->assertEquals([$scope3], AppIdentityService::$scope);
 }
 /**
  * Obtains the default FetchAuthTokenInterface implementation to use
  * in this environment.
  *
  * If supplied, $scope is used to in creating the credentials instance if
  * this does not fallback to the Compute Engine defaults.
  *
  * @param string|array scope the scope of the access request, expressed
  *   either as an Array or as a space-delimited String.
  * @param callable $httpHandler callback which delivers psr7 request
  * @param array $cacheConfig configuration for the cache when it's present
  * @param CacheItemPoolInterface $cache
  *
  * @return CredentialsLoader
  *
  * @throws DomainException if no implementation can be obtained.
  */
 public static function getCredentials($scope = null, callable $httpHandler = null, array $cacheConfig = null, CacheItemPoolInterface $cache = null)
 {
     $creds = null;
     $jsonKey = CredentialsLoader::fromEnv() ?: CredentialsLoader::fromWellKnownFile();
     if (!is_null($jsonKey)) {
         $creds = CredentialsLoader::makeCredentials($scope, $jsonKey);
     }
     if (AppIdentityCredentials::onAppEngine() && !GCECredentials::onAppEngineFlexible()) {
         $creds = new AppIdentityCredentials($scope);
     }
     if (GCECredentials::onGce($httpHandler)) {
         $creds = new GCECredentials();
     }
     if (is_null($creds)) {
         throw new \DomainException(self::notFound());
     }
     if (!is_null($cache)) {
         $creds = new FetchAuthTokenCache($creds, $cacheConfig, $cache);
     }
     return $creds;
 }
 /**
  * Obtains the default FetchAuthTokenInterface implementation to use
  * in this environment.
  *
  * If supplied, $scope is used to in creating the credentials instance if
  * this does not fallback to the Compute Engine defaults.
  *
  * @param string|array scope the scope of the access request, expressed
  *   either as an Array or as a space-delimited String.
  *
  * @param callable $httpHandler callback which delivers psr7 request
  * @throws DomainException if no implementation can be obtained.
  */
 public static function getCredentials($scope = null, callable $httpHandler = null)
 {
     $creds = CredentialsLoader::fromEnv($scope);
     if (!is_null($creds)) {
         return $creds;
     }
     $creds = CredentialsLoader::fromWellKnownFile($scope);
     if (!is_null($creds)) {
         return $creds;
     }
     if (AppIdentityCredentials::onAppEngine()) {
         return new AppIdentityCredentials($scope);
     }
     if (GCECredentials::onGce($httpHandler)) {
         return new GCECredentials();
     }
     throw new \DomainException(self::notFound());
 }