/** * @test */ public function shouldReturnNullPaginationOnImproperResponse() { $mockResponse = array(); $listenerResponse = $this->getMock('Guzzle\\Http\\Message\\Response', array(), array(200)); $listenerResponse->expects($this->once())->method('getBody')->with(TRUE)->will($this->returnValue(json_encode($mockResponse))); $this->assertSame(NULL, ResponseMediator::getPagination($listenerResponse)); }
/** * @test */ public function shouldHandlePagination() { $url = 'http://example.com'; $path = '/some/path'; $body = 'a = b'; $headers = array('c' => 'd'); $response = new Response(200, NULL, json_encode(array('page' => 2, 'pageSize' => 10, 'total' => 30))); $response->setInfo(array('url' => $url)); $expected_pagination = array('first' => array($url => array('page' => 1, 'count' => 10)), 'last' => array($url => array('page' => 3, 'count' => 10)), 'next' => array($url => array('page' => 3, 'count' => 10)), 'prev' => array($url => array('page' => 1, 'count' => 10))); $client = $this->getBrowserMock(); $httpClient = new HttpClient(array(), $client); $httpClient->request($path, $body, 'HEAD', $headers); $this->assertEquals($expected_pagination, ResponseMediator::getPagination($response)); }
/** * {@inheritdoc} */ public function postFetch() { $this->pagination = ResponseMediator::getPagination($this->client->getHttpClient()->getLastResponse()); }