protected function getMockBadReleaseslApi($method = 'post') { $httpClientMock = $this->getMock('Guzzle\\Http\\Client', array('send')); $httpClientMock->expects($this->any())->method('send'); $mock = $this->getMock('Github\\HttpClient\\HttpClient', array(), array(array(), $httpClientMock)); $client = new Github\Client($mock); $client->setHttpClient($mock); // Mock the Issue API. $repoMock = $this->getMockBuilder('Github\\Api\\Repo')->setMethods(array('releases'))->setConstructorArgs(array($client))->getMock(); // Mock the label API. $releasesMock = $this->getMockBuilder('Github\\Api\\Repository\\Releases')->setMethods(array('all', 'show', 'showTag', 'create', 'edit', 'remove', 'assets'))->setConstructorArgs(array($client))->getMock(); $releasesMock->method('showTag')->will($this->throwException(new \Exception())); // This actually runs an assert and makes sure our API call actually returns that :-O. $repoMock->method($method)->will($this->returnValue('Success')); // Set up the Issue API to return the Label api. $repoMock->expects($this->exactly(1))->method('releases')->willReturn($releasesMock); return $repoMock; }
/** * Return or generate github client on-demand * * @param OutputInterface $output * @return GithubClient */ protected function getGithubClient(OutputInterface $output) { if ($this->githubClient) { return $this->githubClient; } // Create authenticated github client $token = $this->getOAUTHToken($output); $client = new GithubClient(); $httpClient = GuzzleClient::createWithConfig(['http_errors' => false]); $client->setHttpClient($httpClient); $client->authenticate($token, null, GithubClient::AUTH_HTTP_TOKEN); // Cache $this->githubClient = $client; return $client; }
protected function getClientMock(HttpClientInterface $httpClient = null) { // if no httpClient isset use the default HttpClient mock if (!$httpClient) { $httpClient = $this->getHttpClientMock(); } $client = new \Github\Client($httpClient); $client->setHttpClient($httpClient); return $client; }