public function test() { $results = array('Adrien', 'William'); $pagerProphecy = $this->prophesize('Pagerfanta\\Pagerfanta'); $pagerProphecy->getCurrentPageResults()->willReturn($results); $pagerProphecy->getCurrentPage()->willReturn(2); $pagerProphecy->getMaxPerPage()->willReturn(20); $pagerProphecy->getNbPages()->willReturn(4); $factory = new PagerfantaFactory('p', 'l'); $representation = $factory->create($pagerProphecy->reveal(), 'users', array('query' => 'hateoas')); $this->object($representation)->isInstanceOf('Hateoas\\Representation\\PaginatedCollection')->variable($representation->getPage())->isEqualTo(2)->variable($representation->getLimit())->isEqualTo(20)->variable($representation->getPages())->isEqualTo(4)->array($representation->getParameters())->isEqualTo(array('query' => 'hateoas', 'p' => 2, 'l' => 20))->string($representation->getPageParameterName())->isEqualTo('p')->string($representation->getLimitParameterName())->isEqualTo('l'); }
public function testWithPagerfanta() { $hateoas = HateoasBuilder::create()->setUrlGenerator(null, new CallableUrlGenerator(function ($route, array $parameters) { return $route . '?' . http_build_query($parameters); }))->build(); $factory = new PagerfantaFactory(); $pagerfanta = new Pagerfanta(new ArrayAdapter(array('bim', 'bam', 'boom'))); $collection = $factory->create($pagerfanta, 'my_route'); $this->string($hateoas->serialize($collection, 'xml'))->isEqualTo(<<<XML <?xml version="1.0" encoding="UTF-8"?> <collection page="1" limit="10" pages="1"> <entry><![CDATA[bim]]></entry> <entry><![CDATA[bam]]></entry> <entry><![CDATA[boom]]></entry> <link rel="self" href="my_route?page=1&limit=10"/> <link rel="first" href="my_route?page=1&limit=10"/> <link rel="last" href="my_route?page=1&limit=10"/> </collection> XML ); }