public function testShouldReturnTokenInfo()
 {
     $wantedTokens = ['access_token' => '1/abdef1234567890', 'expires_in' => '57', 'token_type' => 'Bearer'];
     $jsonTokens = json_encode($wantedTokens);
     $client = new Client();
     $plugin = new Mock([new Response(200, [GCECredentials::FLAVOR_HEADER => 'Google']), new Response(200, [], Stream::factory($jsonTokens))]);
     $client->getEmitter()->attach($plugin);
     $g = new GCECredentials();
     $this->assertEquals($wantedTokens, $g->fetchAuthToken($client));
 }
 /**
  * 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 $client GuzzleHttp\ClientInterface optional client.
  * @throws DomainException if no implementation can be obtained.
  */
 public static function getCredentials($scope = null, $client = 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($client)) {
         return new GCECredentials();
     }
     throw new \DomainException(self::notFound());
 }
 /**
  * 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 $client GuzzleHttp\ClientInterface optional client.
  * @throws DomainException if no implementation can be obtained.
  */
 public static function getCredentials($scope = null, $client = null)
 {
     $creds = DefaultCredentials::fromEnv($scope);
     if (!is_null($creds)) {
         return $creds;
     }
     $creds = DefaultCredentials::fromWellKnownFile($scope);
     if (!is_null($creds)) {
         return $creds;
     }
     if (!GCECredentials::onGce($client)) {
         throw new \DomainException(self::notFound());
     }
     return new GCECredentials();
 }