Skip to content

Commit

Permalink
Merge pull request #75 from omise/fix-search-with-perpage-attr
Browse files Browse the repository at this point in the history
Be able to limit items that will be shown at the Search Object
  • Loading branch information
guzzilar authored Mar 21, 2018
2 parents 3b49fe5 + e28db2f commit 21eb1b9
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/omise/OmiseSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -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": [

]
}
18 changes: 18 additions & 0 deletions tests/omise/SearchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
}
}

0 comments on commit 21eb1b9

Please sign in to comment.