public function testSearch() { $response = file_get_contents(__DIR__ . '/resources/api_search.json'); $this->expectClientCall(Api::REQUEST_GET, '/rest/api/2/search', array('jql' => 'test', 'startAt' => 0, 'maxResults' => 2, 'fields' => 'description'), $response); $response_decoded = json_decode($response, true); $this->api->setOptions(0); // Don't auto-expand fields, because it makes another API call. $this->assertEquals(new Result($response_decoded), $this->api->search('test', 0, 2, 'description')); }
/** * Checks if current position is valid. * * @return boolean The return value will be casted to boolean and then evaluated. * Returns true on success or false on failure. * @throws \Exception When "Walker::push" method wasn't called. * @throws Api\UnauthorizedException When it happens. * @link http://php.net/manual/en/iterator.valid.php */ public function valid() { if (is_null($this->jql)) { throw new \Exception('you have to call Jira_Walker::push($jql, $fields) at first'); } if (!$this->executed) { try { $result = $this->api->search($this->getQuery(), $this->key(), $this->perPage, $this->fields); $this->setResult($result); $this->executed = true; if ($result->getTotal() == 0) { return false; } return true; } catch (Api\UnauthorizedException $e) { throw $e; } catch (\Exception $e) { error_log($e->getMessage()); return false; } } else { if ($this->offset >= $this->max && $this->key() < $this->total) { try { $result = $this->api->search($this->getQuery(), $this->key(), $this->perPage, $this->fields); $this->setResult($result); return true; } catch (Api\UnauthorizedException $e) { throw $e; } catch (\Exception $e) { error_log($e->getMessage()); return false; } } else { if (($this->startAt - 1) * $this->perPage + $this->offset < $this->total) { return true; } else { return false; } } } }
/** * query issues * * @param $jql * @param $startAt * @param $maxResult * @param string $fields * * @return \chobie\Jira\Api\Result */ public function search($jql, $startAt = 0, $maxResult = 20, $fields = '*navigable') { return parent::search($jql, $startAt, $maxResult, $fields); }