Skip to content

Commit

Permalink
implement tests for preparePageSize method
Browse files Browse the repository at this point in the history
  • Loading branch information
salehhashemi1992 committed Dec 22, 2023
1 parent 940cff2 commit 61f7653
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions tests/RepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

0 comments on commit 61f7653

Please sign in to comment.