2026-09-29 14:53:02 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
use App\Dto\FaqDto;
|
|
|
|
|
use App\Models\Faq;
|
|
|
|
|
use App\Queries\Faqs\GetPaginatedFaqsQuery;
|
2026-10-02 12:14:48 +02:00
|
|
|
use App\Queries\Faqs\GetPaginatedFaqsQueryInput;
|
|
|
|
|
use Shared\Pagination\PageNumber;
|
|
|
|
|
use Shared\Pagination\PageSize;
|
|
|
|
|
use Shared\Pagination\Pagination;
|
2026-09-29 14:53:02 +02:00
|
|
|
|
|
|
|
|
describe('GetPaginatedFaqsQuery', function (): void {
|
|
|
|
|
it('returns a paginator of FaqDto instances', function (): void {
|
|
|
|
|
// GIVEN
|
|
|
|
|
$faq1 = new Faq();
|
|
|
|
|
$faq1->question = 'First question?';
|
|
|
|
|
$faq1->answer = 'First answer.';
|
|
|
|
|
$faq1->save();
|
|
|
|
|
|
|
|
|
|
$faq2 = new Faq();
|
|
|
|
|
$faq2->question = 'Second question?';
|
|
|
|
|
$faq2->answer = 'Second answer.';
|
|
|
|
|
$faq2->save();
|
|
|
|
|
|
|
|
|
|
/** @var GetPaginatedFaqsQuery $query */
|
|
|
|
|
$query = app(GetPaginatedFaqsQuery::class);
|
2026-10-02 12:14:48 +02:00
|
|
|
$input = new GetPaginatedFaqsQueryInput(
|
|
|
|
|
pagination: Pagination::ofPage(new PageNumber(1), new PageSize(10)),
|
|
|
|
|
);
|
2026-09-29 14:53:02 +02:00
|
|
|
|
|
|
|
|
// WHEN
|
2026-10-02 12:14:48 +02:00
|
|
|
$paginator = $query($input);
|
2026-09-29 14:53:02 +02:00
|
|
|
|
|
|
|
|
// THEN
|
|
|
|
|
expect($paginator->total())->toBe(2);
|
|
|
|
|
expect($paginator->items())->toHaveCount(2);
|
|
|
|
|
expect($paginator->items()[0])->toBeInstanceOf(FaqDto::class)
|
|
|
|
|
->and($paginator->items()[1])->toBeInstanceOf(FaqDto::class);
|
|
|
|
|
});
|
|
|
|
|
});
|