public function testResponseChangeHeaders() { $response = new Response('Body', 404); $this->assertEquals($response->getStatus()->getCode(), 404); $this->assertEquals($response->getBody(), 'Body'); $response->addHeader('Auth', 'author'); $this->assertEquals($response->getStatus()->getCode(), 404); $this->assertEquals($response->getHeaders(), array('Auth' => 'author')); $response->addHeader('Auth', 'author_change'); $this->assertEquals($response->getHeaders(), array('Auth' => 'author_change')); }
/** * Response constructor. * @param $client * @param \Http\Response $response */ public function __construct(Client $client, \Http\Response $response) { $this->client = $client; $this->body = $body = json_decode($response->getBody(), TRUE); if (isset($body['items'])) { $this->items = $body['items']; } if (isset($body['_meta'])) { $this->total_count = $body['_meta']['totalCount']; $this->page_count = $body['_meta']['pageCount']; $this->current_page = $body['_meta']['currentPage']; $this->per_page = $body['_meta']['perPage']; } if (isset($body['_links'])) { $this->pages = array_map('current', $body['_links']); } foreach ($body as $key => $value) { if ($key !== 'items' and $key[0] !== '_') { $this->additional[$key] = $value; } } }