Skip to content

Commit 5ec899e

Browse files
committed
[Tests] Remove cursor paginator as test dependency
1 parent 916f1b6 commit 5ec899e

File tree

3 files changed

+18
-17
lines changed

3 files changed

+18
-17
lines changed

composer.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
"laravel/framework": "^8.76|^9.0"
3535
},
3636
"require-dev": {
37-
"laravel-json-api/cursor-pagination": "^2.1",
3837
"laravel-json-api/testing": "^1.1.2",
3938
"orchestra/testbench": "^6.23|^7.0",
4039
"phpunit/phpunit": "^9.5.10"

tests/dummy/app/JsonApi/V1/Posts/PostSchema.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
namespace App\JsonApi\V1\Posts;
2121

2222
use App\Models\Post;
23-
use LaravelJsonApi\CursorPagination\CursorPagination;
2423
use LaravelJsonApi\Eloquent\Fields\DateTime;
2524
use LaravelJsonApi\Eloquent\Fields\ID;
2625
use LaravelJsonApi\Eloquent\Fields\Relations\BelongsTo;
@@ -117,7 +116,11 @@ public function pagination(): MultiPagination
117116
{
118117
return new MultiPagination(
119118
PagePagination::make()->withoutNestedMeta(),
120-
CursorPagination::make($this->id())->withoutNestedMeta(),
119+
PagePagination::make()
120+
->withoutNestedMeta()
121+
->withSimplePagination()
122+
->withPageKey('current-page')
123+
->withPerPageKey('per-page')
121124
);
122125
}
123126
}

tests/dummy/tests/Api/V1/Posts/IndexTest.php

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -119,50 +119,49 @@ public function testPagePagination(): void
119119
$response
120120
->assertFetchedMany($expected)
121121
->assertMeta($meta)
122-
->assertLinks($links);
122+
->assertExactLinks($links);
123123
}
124124

125-
public function testCursorPagination(): void
125+
public function testMultiPagination(): void
126126
{
127-
$posts = Post::factory()->count(5)->create([
127+
$posts = Post::factory()->count(6)->create([
128128
'created_at' => fn() => fake()->dateTime(),
129129
])->sortByDesc('created_at')->values();
130130

131-
$expected = $this->identifiersFor('posts', $posts->take(3));
131+
$expected = $this->identifiersFor('posts', $posts->skip(2)->take(2));
132132

133133
$meta = [
134-
'from' => $expected[0]['id'],
135-
'hasMore' => true,
136-
'perPage' => 3,
137-
'to' => $expected[2]['id'],
134+
'currentPage' => 2,
135+
'from' => 3,
136+
'perPage' => 2,
137+
'to' => 4,
138138
];
139139

140140
$links = [
141141
'first' => 'http://localhost/api/v1/posts?' . Arr::query([
142-
'page' => ['limit' => 3],
142+
'page' => ['current-page' => 1, 'per-page' => 2],
143143
'sort' => '-createdAt',
144144
]),
145145
'next' => 'http://localhost/api/v1/posts?' . Arr::query([
146-
'page' => ['after' => $expected[2]['id'], 'limit' => 3],
146+
'page' => ['current-page' => 3, 'per-page' => 2],
147147
'sort' => '-createdAt',
148148
]),
149149
'prev' => 'http://localhost/api/v1/posts?' . Arr::query([
150-
'page' => ['before' => $expected[0]['id'], 'limit' => 3],
150+
'page' => ['current-page' => 1, 'per-page' => 2],
151151
'sort' => '-createdAt',
152152
]),
153153
];
154154

155155
$response = $this
156-
->withoutExceptionHandling()
157156
->jsonApi()
158157
->expects('posts')
159-
->page(['limit' => 3])
158+
->page(['current-page' => 2, 'per-page' => 2])
160159
->get('/api/v1/posts');
161160

162161
$response
163162
->assertFetchedMany($expected)
164163
->assertMeta($meta)
165-
->assertLinks($links);
164+
->assertExactLinks($links);
166165
}
167166

168167
public function testIncludeAuthor(): void

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy