private function whenGitRepositoriesExist($user, array $repositories)
 {
     $this->mock_token_service->expects($this->any())->method('getToken')->with($user)->will($this->returnValue($this->token));
     $mock_response = $this->getMockBuilder('GuzzleHttp\\Psr7\\Response')->getMock();
     $mock_response->expects($this->any())->method('getBody')->will($this->returnValue(json_encode($repositories)));
     $this->mock_http_client->expects($this->any())->method('request')->with('GET', $this->git_api_host . '/user/repos', ['query' => ['access_token' => $this->token], 'headers' => ['Accept' => 'application/json']])->will($this->returnValue($mock_response));
 }
Exemple #2
0
 /**
  * Return array of \Ace\RepoManUi\Remote\Repository objects
  * @param string $user
  * @param string $timezone
  * @return array
  * @throws UnavailableException
  */
 public function getRepositories(string $user, string $timezone) : array
 {
     try {
         $token = $this->token_service->getToken($user);
         $response = $this->client->request('GET', $this->git_api_host . '/user/repos', ['query' => ['access_token' => $token], 'headers' => ['Accept' => 'application/json']]);
         $repositories = [];
         foreach (json_decode($response->getBody(), true) as $data) {
             $description = $data['description'] ?: '';
             $language = $data['language'] ?: '';
             $private = (bool) $data['private'];
             $repository = new Repository($data['html_url'], $description, $language, $private);
             $repository->setTimezone($timezone);
             $repositories[$repository->getFullName()] = $repository;
         }
         return $repositories;
     } catch (TransferException $ex) {
         throw new UnavailableException($ex->getMessage());
     }
 }
 /**
  * @expectedException \Ace\RepoManUi\Remote\UnavailableException
  */
 public function testGetRepositoriesThrowsExceptionOnError()
 {
     $user = '******';
     $this->mock_http_client->expects($this->any())->method('request')->will($this->throwException(new \GuzzleHttp\Exception\TransferException()));
     $this->token_service->getToken($user);
 }