diff --git a/lib/omise/OmiseSearch.php b/lib/omise/OmiseSearch.php index e669a73a..841bfa7d 100644 --- a/lib/omise/OmiseSearch.php +++ b/lib/omise/OmiseSearch.php @@ -98,6 +98,18 @@ public function page($page) return $this->mergeAttributes('page', $page); } + /** + * Update `per_page` parameter. + * + * @param int $limit Number of items that will be shown per page. + * + * @return OmiseSearch This instance. + */ + public function per_page($limit) + { + return $this->mergeAttributes('per_page', $limit); + } + /** * Update `order` parameter. * diff --git a/tests/fixtures/api.omise.co/search-c2NvcGU9Y2hhcmdlJnF1ZXJ5PWRlbW8mcGVyX3BhZ2U9MiZvcmRlcj1yZXZlcnNlX2Nocm9ub2xvZ2ljYWw-get.json b/tests/fixtures/api.omise.co/search-c2NvcGU9Y2hhcmdlJnF1ZXJ5PWRlbW8mcGVyX3BhZ2U9MiZvcmRlcj1yZXZlcnNlX2Nocm9ub2xvZ2ljYWw-get.json new file mode 100644 index 00000000..db429567 --- /dev/null +++ b/tests/fixtures/api.omise.co/search-c2NvcGU9Y2hhcmdlJnF1ZXJ5PWRlbW8mcGVyX3BhZ2U9MiZvcmRlcj1yZXZlcnNlX2Nocm9ub2xvZ2ljYWw-get.json @@ -0,0 +1,16 @@ +{ + "object": "search", + "order": "reverse_chronological", + "scope": "charge", + "query": "demo", + "filters": { + }, + "page": 1, + "per_page": 2, + "location": "/search", + "total_pages": 0, + "total": 0, + "data": [ + + ] +} diff --git a/tests/omise/SearchTest.php b/tests/omise/SearchTest.php index 05cd0084..0e1be1cb 100644 --- a/tests/omise/SearchTest.php +++ b/tests/omise/SearchTest.php @@ -111,4 +111,22 @@ public function testRetrieveSearchObjectBySpecificScopeAndQueryAndFilterAndPageA $this->assertEquals('demo', $search['query']); $this->assertEquals(array('captured' => 'true'), $search['filters']); } + + /** + * Assert that items of search object can be shown at a specific amount + * given by 'per_page' number. + */ + public function testSetLimit() + { + $search = OmiseSearch::scope('charge') + ->query('demo') + ->per_page(2) + ->order('reverse_chronological'); + + $this->assertArrayHasKey('object', $search); + $this->assertEquals('search', $search['object']); + $this->assertEquals('charge', $search['scope']); + $this->assertEquals('demo', $search['query']); + $this->assertEquals(2, $search['per_page']); + } }