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();
     $adapter = 'GitHub' === $input->getOption('adapter') ? GitHubRemote::REMOTE_CANONICAL_NAME : BitBucketRemote::REMOTE_CANONICAL_NAME;
     $destination = $input->getOption('destination') . DIRECTORY_SEPARATOR . $adapter;
     $configLog = $guardian->getConfigLog($destination);
     switch ($input->getOption('format')) {
         case 'table':
             $this->dumpTableFormat($output, $configLog, $adapter);
             break;
         case 'table-compact':
             $this->dumpTableFormat($output, $configLog, $adapter, 'compact');
             break;
         case 'table-borderless':
             $this->dumpTableFormat($output, $configLog, $adapter, 'borderless');
             break;
         case 'csv':
             $this->dumpXsvFormat($configLog, $adapter);
             break;
         case 'tsv':
             $this->dumpXsvFormat($configLog, $adapter, "\t");
             break;
         case 'json':
             $this->dumpJsonFormat($configLog, $adapter);
             break;
         case 'json-pretty':
             $this->dumpJsonFormat($configLog, $adapter, JSON_PRETTY_PRINT);
             break;
         default:
             throw new InvalidArgumentException(sprintf('The format "%s" is not supported', $input->getOption('format')));
     }
 }
 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'));
 }
 /**
  * @dataProvider repositoryClassesProvider
  */
 public function testCloneRepository($class)
 {
     $guardian = new GitGuardian();
     $destination = sys_get_temp_dir() . DIRECTORY_SEPARATOR . uniqid('test-ggioffreda-git-guardian', true);
     mkdir($destination);
     $events = [];
     $guardian->getEmitter()->addListener('git_guardian.pre_clone_repository', function ($event) use(&$events) {
         $this->assertNotContains('git_guardian.pre_clone_repository', $events);
         $events[] = 'git_guardian.pre_clone_repository';
     });
     $guardian->getEmitter()->addListener('git_guardian.post_clone_repository', function ($event) use(&$events) {
         $this->assertNotContains('git_guardian.post_clone_repository', $events);
         $events[] = 'git_guardian.post_clone_repository';
     });
     $guardian->getEmitter()->addListener('git_guardian.pre_config_log_repository', function ($event) use(&$events, $destination) {
         /** @var GitRepositoryEvent $event */
         $this->assertNotContains('git_guardian.pre_config_log_repository', $events);
         $events[] = 'git_guardian.pre_config_log_repository';
         $this->assertStringStartsWith($destination, $event->getGit()->getPath());
     });
     $repository = $this->getMockBuilder($class)->disableOriginalConstructor()->getMock();
     $repository->expects($this->any())->method('getName')->willReturn('test/test');
     $repository->expects($this->any())->method('getUpdatedAt')->will($this->returnValue(new \DateTime('now')));
     $repository->expects($this->any())->method('getAnonymousUri')->willReturn('https://github.com/ggioffreda/git-guardian');
     $repository->expects($this->any())->method('getUri')->willReturn('https://github.com/ggioffreda/git-guardian');
     $repository->expects($this->any())->method('getDescription')->willReturn('Test description');
     $guardian->cloneRepository($repository, $destination);
     $this->assertContains('git_guardian.pre_clone_repository', $events);
     $this->assertContains('git_guardian.post_clone_repository', $events);
     $this->assertContains('git_guardian.pre_config_log_repository', $events);
 }