/** * @test */ public function shouldPaginateGetRequests() { $repositoriesApi = $this->client->api('user'); $repositoriesApi->setPerPage(10); $pager = new ResultPager($this->client); $repositories = $pager->fetch($repositoriesApi, 'repositories', array('KnpLabs')); $this->assertCount(10, $repositories); $repositoriesApi->setPerPage(20); $repositories = $pager->fetch($repositoriesApi, 'repositories', array('KnpLabs')); $this->assertCount(20, $repositories); }
public function getContributors($link = null) { $api = $this->client->api('repo'); $paginator = new ResultPager($this->client); $parameters = [$this->config['contributors']['user'], $this->config['contributors']['repository']]; return ['contributors' => $paginator->fetch($api, 'contributors', $parameters), 'links' => $paginator->getPagination()]; }
/** * @test * * description fetch */ public function shouldGetSomeResults() { $pagination = array('next' => 'http://github.com/next'); $resultContent = 'organization test'; $responseMock = $this->getResponseMock('<http://github.com/next>; rel="next"'); $httpClient = $this->getHttpClientMock($responseMock); $client = $this->getClientMock($httpClient); $organizationApiMock = $this->getApiMock('Github\\Api\\Organization'); $organizationApiMock->expects($this->once())->method('show')->with('github')->will($this->returnValue($resultContent)); $paginator = new Github\ResultPager($client); $result = $paginator->fetch($organizationApiMock, 'show', array('github')); $this->assertEquals($resultContent, $result); $this->assertEquals($pagination, $paginator->getPagination()); }
/** * @param Client $client * @param string $method * @param array $params * @return \Generator */ protected function fetchUsersAsGenerator(Client $client, $method, $params) { $paginator = new ResultPager($client); $userApi = $client->api('user'); $results = $paginator->fetch($userApi, $method, $params); while (true) { foreach ($results as $result) { if (is_array($result) && isset($result[0]) && is_array($result[0])) { foreach ($result as $user) { (yield $user); } } else { (yield $result); } } if (!$paginator->hasNext()) { break; } $results = $paginator->fetchNext(); } }