From 61f7653c7cd6a09fd6d65c62124ee939fc2981d8 Mon Sep 17 00:00:00 2001 From: salehhashemi1992 <81674631+salehhashemi1992@users.noreply.github.com> Date: Sat, 23 Dec 2023 00:24:29 +0330 Subject: [PATCH] implement tests for preparePageSize method --- tests/RepositoryTest.php | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tests/RepositoryTest.php b/tests/RepositoryTest.php index c6a2d65..58ec0e6 100644 --- a/tests/RepositoryTest.php +++ b/tests/RepositoryTest.php @@ -29,4 +29,32 @@ public function testFindOneReturnsModelInstance() $this->assertInstanceOf(Post::class, $foundPost); $this->assertEquals($post->id, $foundPost->id); } + + public function testPaginateWithSpecifiedPerPage() + { + Post::factory()->count(15)->create(); + + $postRepo = $this->app->make(PostRepositoryInterface::class); + + $perPage = 5; + $paginatedResults = $postRepo->paginate($perPage); + + $this->assertInstanceOf(Paginator::class, $paginatedResults); + $this->assertCount($perPage, $paginatedResults->items()); + $this->assertEquals(1, $paginatedResults->currentPage()); + $this->assertEquals(3, $paginatedResults->lastPage()); + } + + public function testPaginateWithDefaultPerPage() + { + Post::factory()->count(10)->create(); + + $postRepo = $this->app->make(PostRepositoryInterface::class); + + $defaultPerPage = 20; + $paginatedResults = $postRepo->paginate(); + + $this->assertInstanceOf(Paginator::class, $paginatedResults); + $this->assertCount(min(10, $defaultPerPage), $paginatedResults->items()); + } }