public function testBitBucketAuthentication()
 {
     $remote = new BitBucketRemote();
     $this->assertEquals([], $remote->getToken());
     $remote->setOptions(['client_id' => 'clientid', 'client_secret' => 'clientsecret']);
     $body = $this->getMockBuilder('GuzzleHttp\\Psr7\\Stream')->disableOriginalConstructor()->getMock();
     $body->expects($this->once())->method('getContents')->willReturn(json_encode($token = ['access_token' => 'testaccesstoken', 'expires_in' => 3600]));
     $tokenResponse = $this->getMockBuilder('GuzzleHttp\\Psr7\\Response')->disableOriginalConstructor()->getMock();
     $tokenResponse->expects($this->once())->method('getStatusCode')->willReturn(200);
     $tokenResponse->expects($this->once())->method('getBody')->willReturn($body);
     $client = $this->getMockBuilder('GuzzleHttp\\Client')->getMock();
     $client->expects($this->once())->method('__call')->willReturn($tokenResponse);
     $remote->setClient($client);
     $this->assertArraySubset($token, $remote->getToken());
 }
 public function execute(InputInterface $input, OutputInterface $output)
 {
     if (!in_array($input->getOption('adapter'), ['BitBucket', 'GitHub'])) {
         throw new InvalidArgumentException(sprintf('The given adapter "%s" is not supported (yet)', $input->getOption('adapter')));
     }
     $guardian = new GitGuardian();
     $emitter = $guardian->getEmitter();
     if ('GitHub' === $input->getOption('adapter')) {
         $users = $input->getArgument('owner');
         if (count($users) && !strstr($users[0], '/')) {
             $username = array_shift($users);
             $gitHubCredentials = ['personal_token' => $input->getOption('personal-token'), 'username' => $username];
             $remote = new GitHubRemote();
             $remote->setEmitter($emitter);
             $remote->setOptions($gitHubCredentials);
             $guardian->addRemote($remote);
         }
         foreach ($users as $owner) {
             $remote = new GitHubRemote();
             $remote->setEmitter($emitter);
             $remote->setUser($owner);
             $guardian->addRemote($remote);
         }
     } else {
         $bitBucketCredentials = ['client_id' => $input->getOption('client-id'), 'client_secret' => $input->getOption('client-secret')];
         foreach ($input->getArgument('owner') as $owner) {
             $remote = new BitBucketRemote();
             $remote->setEmitter($emitter);
             $remote->setOptions($bitBucketCredentials);
             $remote->setUser($owner);
             $guardian->addRemote($remote);
         }
     }
     $this->setupListeners($emitter, $output);
     $guardian->cloneAll($input->getOption('destination'));
 }