-
-
Notifications
You must be signed in to change notification settings - Fork 16
Use default order from Sort in KeysetPaginator
#223
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -166,15 +166,41 @@ public function testThrowsExceptionForWithSortNull(): void | |
| (new KeysetPaginator($dataReader))->withSort(null); | ||
| } | ||
|
|
||
| public function testThrowsExceptionWhenNotSorted(): void | ||
| public function testDefaultOrderUsage(): void | ||
| { | ||
| $sort = Sort::only(['id', 'name']); | ||
| $sort = Sort::only(['name', 'id']); | ||
| $dataReader = (new IterableDataReader(self::getDataSet()))->withSort($sort); | ||
| $paginator = new KeysetPaginator($dataReader); | ||
|
|
||
| $this->expectException(InvalidArgumentException::class); | ||
| $this->expectExceptionMessage('Data should be always sorted to work with keyset pagination.'); | ||
| $result = $paginator->read(); | ||
|
|
||
| new KeysetPaginator($dataReader); | ||
| $this->assertSame( | ||
| self::getDataSet([4, 3, 2, 0, 1]), | ||
| array_values($this->iterableToArray($result)), | ||
| ); | ||
| } | ||
|
|
||
| public function testDefaultOrderUsageInPrevious(): void | ||
| { | ||
| $sort = Sort::only(['name', 'id']); | ||
| $data = [ | ||
| ['id' => 2, 'name' => 'A'], | ||
| ['id' => 1, 'name' => 'A'], | ||
| ['id' => 3, 'name' => 'B'], | ||
| ]; | ||
| $dataReader = (new IterableDataReader($data))->withSort($sort); | ||
| $paginator = (new KeysetPaginator($dataReader)) | ||
| ->withToken(PageToken::previous('B')); | ||
|
|
||
| $result = $paginator->read(); | ||
|
|
||
| $this->assertSame( | ||
| [ | ||
| ['id' => 2, 'name' => 'A'], | ||
| ['id' => 1, 'name' => 'A'], | ||
| ], | ||
| array_values($this->iterableToArray($result)), | ||
| ); | ||
| } | ||
|
|
||
| public function testThrowsExceptionForWithSortNotSorted(): void | ||
|
|
@@ -185,7 +211,7 @@ public function testThrowsExceptionForWithSortNotSorted(): void | |
| $this->expectException(InvalidArgumentException::class); | ||
| $this->expectExceptionMessage('Data should be always sorted to work with keyset pagination.'); | ||
|
|
||
| (new KeysetPaginator($dataReader))->withSort(Sort::only(['id', 'name'])); | ||
| (new KeysetPaginator($dataReader))->withSort(Sort::only([])); | ||
|
||
| } | ||
|
|
||
| public function testPageSizeCannotBeLessThanOne(): void | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.