/** * @test */ public function testPopulatePagingHeaders() { $pathToLinkMapping = [[$this->createPageLink(1), self::DUMMY_SERVER . $this->createPageLink(1)], [$this->createPageLink(6), self::DUMMY_SERVER . $this->createPageLink(6)], [$this->createPageLink(4), self::DUMMY_SERVER . $this->createPageLink(4)], [$this->createPageLink(2), self::DUMMY_SERVER . $this->createPageLink(2)]]; $linksString = $this->getLinksString($pathToLinkMapping); $expectedHeaders = array('link' => array($linksString), 'x-total' => array(150)); $headers = new HeaderBag(); $this->pagingProvider->expects($this->exactly(2))->method('getContext')->will($this->returnValue($this->pagingContext)); $this->pagingContext->expects($this->exactly(2))->method('getHeaderContainer')->will($this->returnValue($headers)); $this->pagingInfo->expects($this->once())->method('getTotalRecords')->will($this->returnValue(150)); $this->apiPagingServiceImpl->populatePagingHeaders($this->pagingInfo, $linksString); $this->assertEquals($expectedHeaders, $headers->all()); }
/** * @param PagingInfo $info * @param string $links */ public function populatePagingHeaders(PagingInfo $info, $links) { $this->provider->getContext()->getHeaderContainer()->add(array('Link' => $links)); $this->provider->getContext()->getHeaderContainer()->add(array('X-Total' => $info->getTotalRecords())); }