public function getRepositories()
 {
     $repositories = [];
     $endpoint = $this->getUser() ? sprintf($this->endpoints['public_repositories'], $this->getUser()) : sprintf($this->endpoints['repositories']);
     $authenticationPart = $this->getAuthenticationPart();
     do {
         /** @var Response $response */
         $response = $this->client->get($endpoint, $authenticationPart);
         if (200 !== $response->getStatusCode()) {
             throw new AdapterException(sprintf('Response is not OK for "%s"', $endpoint));
         }
         $chunk = json_decode($response->getBody()->getContents(), true);
         foreach ($chunk as $definition) {
             $repository = new GitHubRepository($definition['full_name'], $definition['description'], $definition['clone_url']);
             $repository->setSize($definition['size']);
             $repository->setPrivate($definition['private']);
             $repository->setUpdatedAt(new \DateTime($definition['updated_at']));
             $repository->setRemote($this);
             $this->getEmitter()->emit(GitRepositoryEvent::prepare('git_remote.repository_discovery', $repository, 'discovery', null, ['definition' => $definition]));
             $repositories[] = $repository;
         }
         $endpoint = null;
         $headerLinks = $response->getHeader('link');
         if (count($headerLinks)) {
             $links = explode(',', $headerLinks[0]);
             foreach ($links as $link) {
                 $matches = [];
                 if (preg_match('/^<([^>]+)>; rel="next"$/', trim($link), $matches)) {
                     $endpoint = $matches[1];
                 }
             }
         }
     } while (isset($chunk) && is_array($chunk) && count($chunk) > 0 && $endpoint);
     return $repositories;
 }
 public function testGitHubAuthentication()
 {
     $remote = new GitHubRemote();
     $this->assertEquals([], $remote->getAuthenticationPart());
     $remote->setOptions(['personal_token' => 'testpersonaltoken', 'username' => 'testusername']);
     $this->assertEquals(['auth' => ['testusername', 'testpersonaltoken']], $remote->getAuthenticationPart());
     $repository = new GitHubRepository('text/test', 'just a test', $anon = 'https://github.com/test/test.git');
     $repository->setRemote($remote);
     $this->assertEquals($anon, $repository->getAnonymousUri());
     $this->assertEquals('https://*****:*****@github.com/test/test.git', $repository->getUri());
 }