getFields() public method

Get fields definitions.
public getFields ( ) : array
return array
Example #1
0
 /**
  * Get fields definitions.
  *
  * @param integer $cache_duration Cache duration.
  *
  * @return array
  */
 public function getFields($cache_duration = 0)
 {
     $cache_key = __METHOD__ . '()';
     $cached_value = $this->cache->fetch($cache_key);
     if ($cached_value === false) {
         $cached_value = parent::getFields();
         $this->cache->save($cache_key, $cached_value, $cache_duration);
     }
     return $cached_value;
 }
Example #2
0
 public function testGetFields()
 {
     $response = file_get_contents(__DIR__ . '/resources/api_field.json');
     $this->expectClientCall(Api::REQUEST_GET, '/rest/api/2/field', array(), $response);
     $actual = $this->api->getFields();
     $response_decoded = json_decode($response, true);
     $expected = array('issuetype' => $response_decoded[0], 'timespent' => $response_decoded[1]);
     $this->assertEquals($expected, $actual);
     // Second time we call the method the results should be cached and not trigger an API Request.
     $this->client->sendRequest(Api::REQUEST_GET, '/rest/api/2/field', array(), self::ENDPOINT, $this->credential)->shouldNotBeCalled();
     $this->assertEquals($expected, $this->api->getFields(), 'Calling twice did not yield the same results');
 }