示例#1
0
 public function testIterateEmptyResult()
 {
     $this->transport->shouldReceive('performRequest')->once()->withArgs(['GET', 'categories/', ['limit' => 10, 'offset' => 100], \Mockery::any(), \Mockery::any()])->andReturn(['headers' => ['Hm-Collection-Range' => ['0-0/100']], 'json' => []]);
     $this->endpoint->setParams(['offset' => 100, 'limit' => 10]);
     $cursor = new Cursor($this->endpoint, '\\Hitmeister\\Component\\Api\\Transfers\\CategoryTransfer');
     // Iterate again (should not call performRequest)
     $count = 0;
     foreach ($cursor as $i => $item) {
         $count++;
     }
     $this->assertEquals(0, $count);
 }
示例#2
0
 /**
  *
  */
 private function fetchData()
 {
     if (!$this->apiHasNext) {
         return;
     }
     // Set limits defined by API
     $this->apiParams['limit'] = $this->apiLimit;
     $this->apiParams['offset'] = $this->apiOffset;
     // Adjust limits by user
     if (null !== $this->userLimit) {
         $expectedCount = $this->userOffset + $this->userLimit;
         $newCount = $this->apiLimit + $this->apiOffset;
         if ($newCount > $expectedCount) {
             $dx = $newCount - $expectedCount;
             $this->apiParams['limit'] -= $dx;
             if (!$this->apiParams['limit']) {
                 $this->apiHasNext = false;
                 return;
             }
         }
     }
     $this->endpoint->setParams($this->apiParams);
     $resultRequest = $this->endpoint->performRequest();
     Response::checkBody($resultRequest);
     $cursorData = Response::extractCursorPosition($resultRequest);
     $this->total = $cursorData['total'];
     // The end
     if ($cursorData['end'] == $cursorData['total'] || null !== $this->userOffset && null !== $this->userLimit && $cursorData['end'] >= $this->userOffset + $this->userLimit || 0 === count($resultRequest['json'])) {
         $this->apiHasNext = false;
     } else {
         $this->apiOffset += $this->apiLimit;
     }
     $this->rawData = array_merge($this->rawData, $resultRequest['json']);
 }
 public function testGetParamsWithOptions()
 {
     $params = ['status' => 'new', 'client' => ['test_me' => 'hard']];
     $this->endpoint->shouldReceive('getParamWhiteList')->andReturn(['status']);
     $this->endpoint->setParams($params);
     $this->assertEquals($params, $this->endpoint->getParams());
 }
示例#4
0
 /**
  * @return Cursor
  */
 public function find()
 {
     $this->endpoint->setParams($this->params);
     return new Cursor($this->endpoint, $this->transferClass);
 }