/** * @test */ public function resultIsJsonSerializable() { $data = ['one', 2, '3']; $page = new Page(3, 4); $total = 322; $result = new Result($data, $page, $total); $stringified = (string) $result; $this->assertEquals(json_encode(['meta' => ['offset' => $page->getOffset(), 'limit' => $page->getLimit(), 'total' => $total], 'data' => $data]), $stringified); }
/** * @test */ public function setMaxLimitWithoutDefaultDoesNotChangeDefault() { $page = new Page(); $maxLimit = 14; $default = $page->getDefaultLimit(); $this->assertNotEquals($page->getMaxLimit(), $maxLimit); $page->setLimitBounds($maxLimit); $this->assertEquals($page->getMaxLimit(), $maxLimit); $this->assertEquals($page->getDefaultLimit(), $default); }
/** * Applies pagination offset/limit values to the QueryBuilder * @param QueryBuilder $qb * @param Page $page * @param Params $params */ protected function applyListPagination(QueryBuilder $qb, Page $page, Params $params) { $qb->setFirstResult($page->getOffset())->setMaxResults($page->getLimit()); }