chobie\Jira\Api::getStatuses PHP Method

getStatuses() public method

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

Usage Example

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