chobie\Jira\Api::getPriorities PHP Method

getPriorities() public method

Get available priorities.
Since: 2.0.0
public getPriorities ( ) : array
return array
    public function getPriorities()
    {
        // Fetch priorities when the method is called for the first time.
        if ($this->priorities === null) {
            $priorities = array();
            $result = $this->api(self::REQUEST_GET, '/rest/api/2/priority', array(), true);
            /* set hash key as custom field id */
            foreach ($result as $priority) {
                $priorities[$priority['id']] = $priority;
            }
            $this->priorities = $priorities;
        }
        return $this->priorities;
    }

Usage Example

Example #1
0
 public function testGetPriorities()
 {
     $response = file_get_contents(__DIR__ . '/resources/api_priority.json');
     $this->expectClientCall(Api::REQUEST_GET, '/rest/api/2/priority', array(), $response);
     $actual = $this->api->getPriorities();
     $response_decoded = json_decode($response, true);
     $expected = array('1' => $response_decoded[0], '5' => $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/priority', array(), self::ENDPOINT, $this->credential)->shouldNotBeCalled();
     $this->assertEquals($expected, $this->api->getPriorities(), 'Calling twice did not yield the same results');
 }