From 62e667bfbed2370b59274c892748b6cd7d33610e Mon Sep 17 00:00:00 2001 From: namfal <10213761+namfal@users.noreply.github.com> Date: Fri, 14 Dec 2018 11:12:29 +0100 Subject: [PATCH 01/11] Subaccounts are now filterable --- .../FilterableSubaccountLister.php | 55 +++++++++++++ src/Subaccounts/SubaccountListParams.php | 80 +++++++++++++++++++ src/Subaccounts/Subaccounts.php | 38 ++++++--- 3 files changed, 160 insertions(+), 13 deletions(-) create mode 100644 src/Subaccounts/FilterableSubaccountLister.php create mode 100644 src/Subaccounts/SubaccountListParams.php diff --git a/src/Subaccounts/FilterableSubaccountLister.php b/src/Subaccounts/FilterableSubaccountLister.php new file mode 100644 index 0000000..6a978a3 --- /dev/null +++ b/src/Subaccounts/FilterableSubaccountLister.php @@ -0,0 +1,55 @@ +pageFetcher = $pageFetcher; + } + + /** + * @param $queryParams SubaccountListParams[] + * @return SubaccountPagedIterator + */ + public function all($queryParams) + { + return new SubaccountPagedIterator($this->pageFetcher, $queryParams); + } + + /** + * @param $queryParams SubaccountListParams[] + * @param $pageSize int + * @return SubaccountPage + */ + public function firstPage($queryParams, $pageSize = null) + { + return $this->pageFetcher->fetchAfter(null, $queryParams, $pageSize); + } + + /** + * @param $afterId int + * @param $queryParams SubaccountListParams[] + * @param $pageSize int + * @return SubaccountPage + */ + public function pageAfter($afterId, $queryParams, $pageSize = null) + { + return $this->pageFetcher->fetchAfter($afterId, $queryParams, $pageSize); + } + + /** + * @param $beforeId int + * @param $queryParams SubaccountListParams[] + * @param $pageSize int + * @return SubaccountPage + */ + public function pageBefore($beforeId, $queryParams, $pageSize = null) + { + return $this->pageFetcher->fetchBefore($beforeId, $queryParams, $pageSize); + } +} \ No newline at end of file diff --git a/src/Subaccounts/SubaccountListParams.php b/src/Subaccounts/SubaccountListParams.php new file mode 100644 index 0000000..c5b6f03 --- /dev/null +++ b/src/Subaccounts/SubaccountListParams.php @@ -0,0 +1,80 @@ +filter = $filter; + $this->tag = $tag; + $this->expandEvents = $expandEvents; + } + + /** + * @param $filter string + * @return $this + */ + public function withFilter($filter) + { + $this->filter = $filter; + return $this; + } + + /** + * @param $tag string + * @return $this + */ + public function withTag($tag) + { + $this->tag = $tag; + return $this; + } + + /** + * @param $expandEvents boolean + * @return $this + */ + public function withExpandEvents($expandEvents) + { + $this->expandEvents = $expandEvents; + return $this; + } + + public function toArray() + { + $result = []; + + if ($this->filter !== null) { + $result['filter'] = $this->filter; + } + if ($this->tag !== null) { + $result['tag'] = $this->tag; + } + if ($this->expandEvents) { + $result['expand'] = 'events'; + } + + return $result; + } + +} + diff --git a/src/Subaccounts/Subaccounts.php b/src/Subaccounts/Subaccounts.php index 85593ee..2f2a6ea 100644 --- a/src/Subaccounts/Subaccounts.php +++ b/src/Subaccounts/Subaccounts.php @@ -167,50 +167,62 @@ public function copyChartToSubaccount($fromId, $toId, $chartKey) } /** + * @param $subaccountListParams SubaccountListParams * @return SubaccountPagedIterator */ - public function listAll() + public function listAll($subaccountListParams = null) { - return $this->iterator()->all(); + return $this->iterator()->all($this->listParamsToArray($subaccountListParams)); } /** * @param $pageSize int - * @return SubaccountsPage + * @param $subaccountListParams SubaccountListParams + * @return SubaccountPage */ - public function listFirstPage($pageSize = null) + public function listFirstPage($subaccountListParams = null, $pageSize = null) { - return $this->iterator()->firstPage($pageSize); + return $this->iterator()->firstPage($this->listParamsToArray($subaccountListParams), $pageSize); } /** * @param $afterId int + * @param $subaccountListParams SubaccountListParams * @param $pageSize int - * @return SubaccountsPage + * @return SubaccountPage */ - public function listPageAfter($afterId, $pageSize = null) + public function listPageAfter($afterId, $subaccountListParams = null, $pageSize = null) { - return $this->iterator()->pageAfter($afterId, $pageSize); + return $this->iterator()->pageAfter($afterId, $this->listParamsToArray($subaccountListParams), $pageSize); } /** * @param $beforeId int + * @param $subaccountListParams SubaccountListParams * @param $pageSize int - * @return SubaccountsPage + * @return SubaccountPage */ - public function listPageBefore($beforeId, $pageSize = null) + public function listPageBefore($beforeId, $subaccountListParams = null, $pageSize = null) { - return $this->iterator()->pageBefore($beforeId, $pageSize); + return $this->iterator()->pageBefore($beforeId, $this->listParamsToArray($subaccountListParams), $pageSize); } /** - * @return SubaccountLister + * @return FilterableSubaccountLister */ private function iterator() { - return new SubaccountLister(new PageFetcher('/subaccounts', $this->client, function () { + return new FilterableSubaccountLister(new PageFetcher('/subaccounts', $this->client, function () { return new SubaccountPage(); })); } + private function listParamsToArray($subaccountListParams) + { + if ($subaccountListParams == null) { + return []; + } + return $subaccountListParams->toArray(); + } + } \ No newline at end of file From 2fee92c1479ba7ba9aece2507315ef215c70bbe3 Mon Sep 17 00:00:00 2001 From: namfal <10213761+namfal@users.noreply.github.com> Date: Fri, 14 Dec 2018 20:42:02 +0100 Subject: [PATCH 02/11] Added a test, removed tag and withExpandEvents params --- src/Subaccounts/SubaccountListParams.php | 40 +-------------------- tests/Subacounts/ListAllSubaccountsTest.php | 12 +++++++ 2 files changed, 13 insertions(+), 39 deletions(-) diff --git a/src/Subaccounts/SubaccountListParams.php b/src/Subaccounts/SubaccountListParams.php index c5b6f03..42c78da 100644 --- a/src/Subaccounts/SubaccountListParams.php +++ b/src/Subaccounts/SubaccountListParams.php @@ -8,25 +8,13 @@ class SubaccountListParams * @var string */ public $filter; - /** - * @var string - */ - public $tag; - /** - * @var boolean - */ - public $expandEvents; /** * @param $filter string - * @param $tag string - * @param $expandEvents boolean */ - public function __construct($filter = null, $tag = null, $expandEvents = null) + public function __construct($filter = null) { $this->filter = $filter; - $this->tag = $tag; - $this->expandEvents = $expandEvents; } /** @@ -39,26 +27,6 @@ public function withFilter($filter) return $this; } - /** - * @param $tag string - * @return $this - */ - public function withTag($tag) - { - $this->tag = $tag; - return $this; - } - - /** - * @param $expandEvents boolean - * @return $this - */ - public function withExpandEvents($expandEvents) - { - $this->expandEvents = $expandEvents; - return $this; - } - public function toArray() { $result = []; @@ -66,12 +34,6 @@ public function toArray() if ($this->filter !== null) { $result['filter'] = $this->filter; } - if ($this->tag !== null) { - $result['tag'] = $this->tag; - } - if ($this->expandEvents) { - $result['expand'] = 'events'; - } return $result; } diff --git a/tests/Subacounts/ListAllSubaccountsTest.php b/tests/Subacounts/ListAllSubaccountsTest.php index 8f4a8ee..7a311a7 100644 --- a/tests/Subacounts/ListAllSubaccountsTest.php +++ b/tests/Subacounts/ListAllSubaccountsTest.php @@ -19,4 +19,16 @@ public function test() self::assertEquals([$subaccount3->id, $subaccount2->id, $subaccount1->id], array_values($subaccountIds)); } + public function testWithFilter() + { + $this->seatsioClient->subaccounts->create(); + $subaccount2 = $this->seatsioClient->subaccounts->create("test-/@/"); + $this->seatsioClient->subaccounts->create(); + + $subaccounts = $this->seatsioClient->subaccounts->listAll((new SubaccountListParams())->withFilter('test')); + $subaccountIds = \Functional\map($subaccounts, function($subaccount) { return $subaccount->id; }); + + self::assertEquals([$subaccount2->id], array_values($subaccountIds)); + } + } \ No newline at end of file From 2fd360067b0ad1038b3234ec36b1915a740350d2 Mon Sep 17 00:00:00 2001 From: namfal <10213761+namfal@users.noreply.github.com> Date: Fri, 14 Dec 2018 21:35:16 +0100 Subject: [PATCH 03/11] Added an additional test with special characters --- tests/Subacounts/ListAllSubaccountsTest.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/Subacounts/ListAllSubaccountsTest.php b/tests/Subacounts/ListAllSubaccountsTest.php index 7a311a7..df83226 100644 --- a/tests/Subacounts/ListAllSubaccountsTest.php +++ b/tests/Subacounts/ListAllSubaccountsTest.php @@ -31,4 +31,21 @@ public function testWithFilter() self::assertEquals([$subaccount2->id], array_values($subaccountIds)); } + public function testWithFilterContainingSpecialCharacter() + { + $createdSubaccountKeys = array(); + + for ($i = 0; $i < 55; $i++) { + $subaccount = $this->seatsioClient->subaccounts->create("test-/@/" . $i); + if($i >= 40 && $i <=49) { + $createdSubaccountKeys[] = $subaccount->id; + } + } + + $subaccounts = $this->seatsioClient->subaccounts->listAll((new SubaccountListParams())->withFilter('test-/@/4')); + $retrievedSubaccountKeys = \Functional\map($subaccounts, function($subaccount) { return $subaccount->id; }); + + self::assertEquals(sort(array_values($createdSubaccountKeys)), sort(array_values($retrievedSubaccountKeys))); + } + } \ No newline at end of file From f0f7d01fcd1a60bfd6c24ccc22401f296a35b0cd Mon Sep 17 00:00:00 2001 From: namfal <10213761+namfal@users.noreply.github.com> Date: Fri, 14 Dec 2018 21:37:46 +0100 Subject: [PATCH 04/11] Fixed variable name in the test --- tests/Subacounts/ListAllSubaccountsTest.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/Subacounts/ListAllSubaccountsTest.php b/tests/Subacounts/ListAllSubaccountsTest.php index df83226..ba4fe42 100644 --- a/tests/Subacounts/ListAllSubaccountsTest.php +++ b/tests/Subacounts/ListAllSubaccountsTest.php @@ -30,22 +30,22 @@ public function testWithFilter() self::assertEquals([$subaccount2->id], array_values($subaccountIds)); } - + public function testWithFilterContainingSpecialCharacter() { - $createdSubaccountKeys = array(); + $createdSubaccountIds = array(); for ($i = 0; $i < 55; $i++) { $subaccount = $this->seatsioClient->subaccounts->create("test-/@/" . $i); if($i >= 40 && $i <=49) { - $createdSubaccountKeys[] = $subaccount->id; + $createdSubaccountIds[] = $subaccount->id; } } $subaccounts = $this->seatsioClient->subaccounts->listAll((new SubaccountListParams())->withFilter('test-/@/4')); - $retrievedSubaccountKeys = \Functional\map($subaccounts, function($subaccount) { return $subaccount->id; }); + $retrievedSubaccountIds = \Functional\map($subaccounts, function($subaccount) { return $subaccount->id; }); - self::assertEquals(sort(array_values($createdSubaccountKeys)), sort(array_values($retrievedSubaccountKeys))); + self::assertEquals(sort(array_values($createdSubaccountIds)), sort(array_values($retrievedSubaccountIds))); } } \ No newline at end of file From 5147d164d87176b490b99030fb0d5bacbe2e5f17 Mon Sep 17 00:00:00 2001 From: namfal <10213761+namfal@users.noreply.github.com> Date: Fri, 14 Dec 2018 21:57:39 +0100 Subject: [PATCH 05/11] Fixed test --- tests/Subacounts/ListAllSubaccountsTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Subacounts/ListAllSubaccountsTest.php b/tests/Subacounts/ListAllSubaccountsTest.php index ba4fe42..a11ff8a 100644 --- a/tests/Subacounts/ListAllSubaccountsTest.php +++ b/tests/Subacounts/ListAllSubaccountsTest.php @@ -37,7 +37,7 @@ public function testWithFilterContainingSpecialCharacter() for ($i = 0; $i < 55; $i++) { $subaccount = $this->seatsioClient->subaccounts->create("test-/@/" . $i); - if($i >= 40 && $i <=49) { + if($i == 4 || ($i >= 40 && $i <=49)) { $createdSubaccountIds[] = $subaccount->id; } } @@ -45,7 +45,7 @@ public function testWithFilterContainingSpecialCharacter() $subaccounts = $this->seatsioClient->subaccounts->listAll((new SubaccountListParams())->withFilter('test-/@/4')); $retrievedSubaccountIds = \Functional\map($subaccounts, function($subaccount) { return $subaccount->id; }); - self::assertEquals(sort(array_values($createdSubaccountIds)), sort(array_values($retrievedSubaccountIds))); + self::assertEquals($createdSubaccountIds, $retrievedSubaccountIds, "\$canonicalize = true", 0.0, 10, true); } } \ No newline at end of file From 202809eefd349eac0881e51c9c2b43d5cdacac37 Mon Sep 17 00:00:00 2001 From: namfal <10213761+namfal@users.noreply.github.com> Date: Fri, 14 Dec 2018 21:58:38 +0100 Subject: [PATCH 06/11] Fixed test --- tests/Subacounts/ListAllSubaccountsTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Subacounts/ListAllSubaccountsTest.php b/tests/Subacounts/ListAllSubaccountsTest.php index a11ff8a..0a4ef00 100644 --- a/tests/Subacounts/ListAllSubaccountsTest.php +++ b/tests/Subacounts/ListAllSubaccountsTest.php @@ -30,7 +30,7 @@ public function testWithFilter() self::assertEquals([$subaccount2->id], array_values($subaccountIds)); } - + public function testWithFilterContainingSpecialCharacter() { $createdSubaccountIds = array(); @@ -45,7 +45,7 @@ public function testWithFilterContainingSpecialCharacter() $subaccounts = $this->seatsioClient->subaccounts->listAll((new SubaccountListParams())->withFilter('test-/@/4')); $retrievedSubaccountIds = \Functional\map($subaccounts, function($subaccount) { return $subaccount->id; }); - self::assertEquals($createdSubaccountIds, $retrievedSubaccountIds, "\$canonicalize = true", 0.0, 10, true); + self::assertEquals($createdSubaccountIds, $retrievedSubaccountIds, "", 0.0, 10, true); } } \ No newline at end of file From c9ec03be04ccb410103959cf84753ede6bd879b6 Mon Sep 17 00:00:00 2001 From: namfal <10213761+namfal@users.noreply.github.com> Date: Sat, 15 Dec 2018 13:45:22 +0100 Subject: [PATCH 07/11] Fixed backward compability --- src/Subaccounts/Subaccounts.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Subaccounts/Subaccounts.php b/src/Subaccounts/Subaccounts.php index 2f2a6ea..e305abf 100644 --- a/src/Subaccounts/Subaccounts.php +++ b/src/Subaccounts/Subaccounts.php @@ -180,7 +180,7 @@ public function listAll($subaccountListParams = null) * @param $subaccountListParams SubaccountListParams * @return SubaccountPage */ - public function listFirstPage($subaccountListParams = null, $pageSize = null) + public function listFirstPage($pageSize = null, $subaccountListParams = null) { return $this->iterator()->firstPage($this->listParamsToArray($subaccountListParams), $pageSize); } @@ -191,7 +191,7 @@ public function listFirstPage($subaccountListParams = null, $pageSize = null) * @param $pageSize int * @return SubaccountPage */ - public function listPageAfter($afterId, $subaccountListParams = null, $pageSize = null) + public function listPageAfter($afterId, $pageSize = null, $subaccountListParams = null) { return $this->iterator()->pageAfter($afterId, $this->listParamsToArray($subaccountListParams), $pageSize); } @@ -202,7 +202,7 @@ public function listPageAfter($afterId, $subaccountListParams = null, $pageSize * @param $pageSize int * @return SubaccountPage */ - public function listPageBefore($beforeId, $subaccountListParams = null, $pageSize = null) + public function listPageBefore($beforeId, $pageSize = null, $subaccountListParams = null) { return $this->iterator()->pageBefore($beforeId, $this->listParamsToArray($subaccountListParams), $pageSize); } From 8d1801ffbf20eaa6be0a9d7b7a0209b9a312bba3 Mon Sep 17 00:00:00 2001 From: namfal <10213761+namfal@users.noreply.github.com> Date: Sat, 15 Dec 2018 13:53:09 +0100 Subject: [PATCH 08/11] Fixed param order --- src/Subaccounts/FilterableSubaccountLister.php | 14 +++++++------- src/Subaccounts/Subaccounts.php | 10 +++++----- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/Subaccounts/FilterableSubaccountLister.php b/src/Subaccounts/FilterableSubaccountLister.php index 6a978a3..1f33095 100644 --- a/src/Subaccounts/FilterableSubaccountLister.php +++ b/src/Subaccounts/FilterableSubaccountLister.php @@ -16,39 +16,39 @@ public function __construct($pageFetcher) * @param $queryParams SubaccountListParams[] * @return SubaccountPagedIterator */ - public function all($queryParams) + public function all($queryParams = null) { return new SubaccountPagedIterator($this->pageFetcher, $queryParams); } /** - * @param $queryParams SubaccountListParams[] * @param $pageSize int + * @param $queryParams SubaccountListParams[] * @return SubaccountPage */ - public function firstPage($queryParams, $pageSize = null) + public function firstPage($pageSize = null, $queryParams = null) { return $this->pageFetcher->fetchAfter(null, $queryParams, $pageSize); } /** * @param $afterId int - * @param $queryParams SubaccountListParams[] * @param $pageSize int + * @param $queryParams SubaccountListParams[] * @return SubaccountPage */ - public function pageAfter($afterId, $queryParams, $pageSize = null) + public function pageAfter($afterId, $pageSize = null, $queryParams = null) { return $this->pageFetcher->fetchAfter($afterId, $queryParams, $pageSize); } /** * @param $beforeId int - * @param $queryParams SubaccountListParams[] * @param $pageSize int + * @param $queryParams SubaccountListParams[] * @return SubaccountPage */ - public function pageBefore($beforeId, $queryParams, $pageSize = null) + public function pageBefore($beforeId, $pageSize = null, $queryParams = null) { return $this->pageFetcher->fetchBefore($beforeId, $queryParams, $pageSize); } diff --git a/src/Subaccounts/Subaccounts.php b/src/Subaccounts/Subaccounts.php index e305abf..6311a90 100644 --- a/src/Subaccounts/Subaccounts.php +++ b/src/Subaccounts/Subaccounts.php @@ -182,29 +182,29 @@ public function listAll($subaccountListParams = null) */ public function listFirstPage($pageSize = null, $subaccountListParams = null) { - return $this->iterator()->firstPage($this->listParamsToArray($subaccountListParams), $pageSize); + return $this->iterator()->firstPage($pageSize, $this->listParamsToArray($subaccountListParams)); } /** * @param $afterId int - * @param $subaccountListParams SubaccountListParams * @param $pageSize int + * @param $subaccountListParams SubaccountListParams * @return SubaccountPage */ public function listPageAfter($afterId, $pageSize = null, $subaccountListParams = null) { - return $this->iterator()->pageAfter($afterId, $this->listParamsToArray($subaccountListParams), $pageSize); + return $this->iterator()->pageAfter($afterId, $pageSize, $this->listParamsToArray($subaccountListParams)); } /** * @param $beforeId int - * @param $subaccountListParams SubaccountListParams * @param $pageSize int + * @param $subaccountListParams SubaccountListParams * @return SubaccountPage */ public function listPageBefore($beforeId, $pageSize = null, $subaccountListParams = null) { - return $this->iterator()->pageBefore($beforeId, $this->listParamsToArray($subaccountListParams), $pageSize); + return $this->iterator()->pageBefore($beforeId, $pageSize, $this->listParamsToArray($subaccountListParams)); } /** From fd2ad0139d622e99792a290331cfece591c11444 Mon Sep 17 00:00:00 2001 From: namfal <10213761+namfal@users.noreply.github.com> Date: Sat, 15 Dec 2018 13:58:56 +0100 Subject: [PATCH 09/11] Changed deafult value for in FilterableSubaccountLister to empty array --- src/Subaccounts/FilterableSubaccountLister.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Subaccounts/FilterableSubaccountLister.php b/src/Subaccounts/FilterableSubaccountLister.php index 1f33095..af6b895 100644 --- a/src/Subaccounts/FilterableSubaccountLister.php +++ b/src/Subaccounts/FilterableSubaccountLister.php @@ -26,7 +26,7 @@ public function all($queryParams = null) * @param $queryParams SubaccountListParams[] * @return SubaccountPage */ - public function firstPage($pageSize = null, $queryParams = null) + public function firstPage($pageSize = null, $queryParams = []) { return $this->pageFetcher->fetchAfter(null, $queryParams, $pageSize); } @@ -37,7 +37,7 @@ public function firstPage($pageSize = null, $queryParams = null) * @param $queryParams SubaccountListParams[] * @return SubaccountPage */ - public function pageAfter($afterId, $pageSize = null, $queryParams = null) + public function pageAfter($afterId, $pageSize = null, $queryParams = []) { return $this->pageFetcher->fetchAfter($afterId, $queryParams, $pageSize); } @@ -48,7 +48,7 @@ public function pageAfter($afterId, $pageSize = null, $queryParams = null) * @param $queryParams SubaccountListParams[] * @return SubaccountPage */ - public function pageBefore($beforeId, $pageSize = null, $queryParams = null) + public function pageBefore($beforeId, $pageSize = null, $queryParams = []) { return $this->pageFetcher->fetchBefore($beforeId, $queryParams, $pageSize); } From 289773bc0a39109288d1b367f4db7736ec4862fa Mon Sep 17 00:00:00 2001 From: namfal <10213761+namfal@users.noreply.github.com> Date: Sat, 15 Dec 2018 14:00:50 +0100 Subject: [PATCH 10/11] realized in FilterableSubaccountLister doesn't need default param value --- src/Subaccounts/FilterableSubaccountLister.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Subaccounts/FilterableSubaccountLister.php b/src/Subaccounts/FilterableSubaccountLister.php index af6b895..435be5e 100644 --- a/src/Subaccounts/FilterableSubaccountLister.php +++ b/src/Subaccounts/FilterableSubaccountLister.php @@ -16,7 +16,7 @@ public function __construct($pageFetcher) * @param $queryParams SubaccountListParams[] * @return SubaccountPagedIterator */ - public function all($queryParams = null) + public function all($queryParams) { return new SubaccountPagedIterator($this->pageFetcher, $queryParams); } @@ -26,7 +26,7 @@ public function all($queryParams = null) * @param $queryParams SubaccountListParams[] * @return SubaccountPage */ - public function firstPage($pageSize = null, $queryParams = []) + public function firstPage($pageSize = null, $queryParams) { return $this->pageFetcher->fetchAfter(null, $queryParams, $pageSize); } @@ -37,7 +37,7 @@ public function firstPage($pageSize = null, $queryParams = []) * @param $queryParams SubaccountListParams[] * @return SubaccountPage */ - public function pageAfter($afterId, $pageSize = null, $queryParams = []) + public function pageAfter($afterId, $pageSize = null, $queryParams) { return $this->pageFetcher->fetchAfter($afterId, $queryParams, $pageSize); } @@ -48,7 +48,7 @@ public function pageAfter($afterId, $pageSize = null, $queryParams = []) * @param $queryParams SubaccountListParams[] * @return SubaccountPage */ - public function pageBefore($beforeId, $pageSize = null, $queryParams = []) + public function pageBefore($beforeId, $pageSize = null, $queryParams) { return $this->pageFetcher->fetchBefore($beforeId, $queryParams, $pageSize); } From 844165f02244dbcc4d4091a84d25ee9219a151e5 Mon Sep 17 00:00:00 2001 From: namfal <10213761+namfal@users.noreply.github.com> Date: Wed, 19 Dec 2018 14:46:31 +0100 Subject: [PATCH 11/11] Added more tests --- tests/Subacounts/ListAllSubaccountsTest.php | 63 ++++++++++++++++++++- 1 file changed, 61 insertions(+), 2 deletions(-) diff --git a/tests/Subacounts/ListAllSubaccountsTest.php b/tests/Subacounts/ListAllSubaccountsTest.php index 0a4ef00..9be60a2 100644 --- a/tests/Subacounts/ListAllSubaccountsTest.php +++ b/tests/Subacounts/ListAllSubaccountsTest.php @@ -22,10 +22,10 @@ public function test() public function testWithFilter() { $this->seatsioClient->subaccounts->create(); - $subaccount2 = $this->seatsioClient->subaccounts->create("test-/@/"); + $subaccount2 = $this->seatsioClient->subaccounts->create("subaccount2"); $this->seatsioClient->subaccounts->create(); - $subaccounts = $this->seatsioClient->subaccounts->listAll((new SubaccountListParams())->withFilter('test')); + $subaccounts = $this->seatsioClient->subaccounts->listAll((new SubaccountListParams())->withFilter('subaccount2')); $subaccountIds = \Functional\map($subaccounts, function($subaccount) { return $subaccount->id; }); self::assertEquals([$subaccount2->id], array_values($subaccountIds)); @@ -48,4 +48,63 @@ public function testWithFilterContainingSpecialCharacter() self::assertEquals($createdSubaccountIds, $retrievedSubaccountIds, "", 0.0, 10, true); } + public function testWithFilterNoResult() + { + $subaccounts = $this->seatsioClient->subaccounts->listAll((new SubaccountListParams())->withFilter('test')); + $subaccountIds = \Functional\map($subaccounts, function($subaccount) { return $subaccount->id; }); + + self::assertEmpty(array_values($subaccountIds)); + } + + public function testWithFilterFirstPage() + { + $this->seatsioClient->subaccounts->create("test-/@/1"); + $subaccount2 = $this->seatsioClient->subaccounts->create("test-/@/2"); + $this->seatsioClient->subaccounts->create("test-/@/3"); + + $subaccounts = $this->seatsioClient->subaccounts->listFirstPage(null, (new SubaccountListParams())->withFilter('test-/@/2')); + $subaccountIds = \Functional\map($subaccounts->items, function($subaccount) { return $subaccount->id; }); + + self::assertEquals([$subaccount2->id], array_values($subaccountIds)); + self::assertEmpty($subaccounts->nextPageStartsAfter); + self::assertEmpty($subaccounts->previousPageEndsBefore); + } + + public function testWithFilterPreviousPage() + { + $subaccount1 = $this->seatsioClient->subaccounts->create("test-/@/11"); + $subaccount2 = $this->seatsioClient->subaccounts->create("test-/@/12"); + $subaccount3 = $this->seatsioClient->subaccounts->create("test-/@/33"); + $this->seatsioClient->subaccounts->create("test-/@/14"); + $this->seatsioClient->subaccounts->create("test-/@/5"); + $this->seatsioClient->subaccounts->create("test-/@/6"); + $this->seatsioClient->subaccounts->create("test-/@/7"); + $this->seatsioClient->subaccounts->create("test-/@/8"); + + $subaccounts = $this->seatsioClient->subaccounts->listPageAfter($subaccount3->id, null, (new SubaccountListParams())->withFilter('test-/@/1')); + $subaccountIds = \Functional\map($subaccounts->items, function($subaccount) { return $subaccount->id; }); + + self::assertEquals([$subaccount1->id, $subaccount2->id], $subaccountIds, "", 0.0, 10, true); + self::assertEmpty($subaccounts->nextPageStartsAfter); + self::assertEquals($subaccount2->id, $subaccounts->previousPageEndsBefore); + } + + public function testWithFilterNextPage() + { + $subaccount1 = $this->seatsioClient->subaccounts->create("test-/@/11"); + $subaccount2 = $this->seatsioClient->subaccounts->create("test-/@/12"); + $subaccount3 = $this->seatsioClient->subaccounts->create("test-/@/13"); + $this->seatsioClient->subaccounts->create("test-/@/4"); + $this->seatsioClient->subaccounts->create("test-/@/5"); + $this->seatsioClient->subaccounts->create("test-/@/6"); + $this->seatsioClient->subaccounts->create("test-/@/7"); + $this->seatsioClient->subaccounts->create("test-/@/8"); + + $subaccounts = $this->seatsioClient->subaccounts->listPageBefore($subaccount1->id, null, (new SubaccountListParams())->withFilter('test-/@/1')); + $subaccountIds = \Functional\map($subaccounts->items, function($subaccount) { return $subaccount->id; }); + + self::assertEquals([$subaccount3->id, $subaccount2->id], $subaccountIds, "", 0.0, 10, true); + self::assertEmpty($subaccounts->previousPageEndsBefore); + self::assertEquals($subaccount2->id, $subaccounts->nextPageStartsAfter); + } } \ No newline at end of file