public function testGetOAuthAuthorizationUrl()
 {
     $oAuth2Info = ['demo' => 'info'];
     $authorizationUrl = 'demourl';
     /** @var AdWordsUser $adWordsUser */
     $adWordsUser = $this->getMockBuilder(AdWordsUser::class)->disableOriginalConstructor()->getMock();
     /** @var OAuth2Handler $oAuth2Handler */
     $oAuth2Handler = $this->getMockBuilder(OAuth2Handler::class)->disableOriginalConstructor()->setMethods(['GetAuthorizationUrl', 'GetAccessToken', 'RefreshAccessToken'])->getMock();
     $adWordsUser->expects($this->at(0))->method('getOAuth2Handler')->willReturn($oAuth2Handler);
     $adWordsUser->expects($this->at(1))->method('GetOAuth2Info')->willReturn($oAuth2Info);
     $oAuth2Handler->expects($this->once())->method('GetAuthorizationUrl')->with($oAuth2Info, null, true)->willReturn($authorizationUrl);
     $result = $this->service->getOAuthAuthorizationUrl($adWordsUser);
     $this->assertSame($authorizationUrl, $result);
 }
 /**
  * Generate refresh token
  *
  * @param AdWordsService $adWordsService
  */
 public function fire(AdWordsService $adWordsService)
 {
     $user = new AdWordsUser();
     $authorizationUrl = $adWordsService->getOAuthAuthorizationUrl($user);
     // Post authorization URL
     $this->line(sprintf("Please sign in to your AdWords account, and open following url:\n%s", $authorizationUrl));
     // Retrieve token
     $accessToken = $this->ask('Insert your access token:');
     try {
         $oAuth2Info = $adWordsService->getOAuthCredentials($user, $accessToken);
     } catch (OAuth2Exception $e) {
         // OAuth2 error
         return $this->error('[OAUTH2]: ' . $e->getMessage());
     } catch (Exception $e) {
         return $this->error($e->getMessage());
     }
     if (!isset($oAuth2Info['refresh_token'])) {
         return $this->error('Error fetching the refresh token');
     }
     $this->comment('Insert the refresh token in your googleads configuration file (config/google-ads.php)');
     // Print refresh token
     $this->line(sprintf('Refresh token: "%s"', $oAuth2Info['refresh_token']));
 }