Пример #1
0
 /**
  * @test
  *
  * description fetchNext
  */
 public function fetchNext()
 {
     $header = '<http://github.com/next>; rel="next"';
     $pagination = array('next' => 'http://github.com/next');
     $resultContent = 'fetch test';
     $responseMock = $this->getResponseMock($header);
     $responseMock->expects($this->once())->method('getBody')->will($this->returnValue($resultContent));
     // Expected 2 times, 1 for setup and 1 for the actual test
     $responseMock->expects($this->exactly(2))->method('getHeader')->with('Link');
     $httpClient = $this->getHttpClientMock($responseMock);
     $httpClient->expects($this->once())->method('get')->with($pagination['next'])->will($this->returnValue($responseMock));
     $client = $this->getClientMock($httpClient);
     $paginator = new Github\ResultPager($client);
     $paginator->postFetch();
     $this->assertEquals($paginator->fetchNext(), $resultContent);
 }
 /**
  * @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();
     }
 }