54 lines
1.6 KiB
PHP
54 lines
1.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Integration\WithApp\App\Cqs\Queries\Faqs;
|
|
|
|
use App\Cqs\Queries\Faqs\GetPaginatedFaqsQuery;
|
|
use App\Cqs\Queries\Faqs\GetPaginatedFaqsQueryInput;
|
|
use App\Models\Faq;
|
|
use App\Services\DataTableService;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Session\NullSessionHandler;
|
|
use Illuminate\Session\Store;
|
|
use Illuminate\Support\Facades\Schema;
|
|
use Shared\Pagination\PageNumber;
|
|
use Shared\Pagination\PageSize;
|
|
use Shared\Pagination\Pagination;
|
|
|
|
afterEach(function (): void {
|
|
DataTableService::clearColumnsCache();
|
|
});
|
|
|
|
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();
|
|
|
|
$query = new GetPaginatedFaqsQuery(
|
|
new DataTableService(
|
|
Request::create('/'),
|
|
new Store('test', new NullSessionHandler()),
|
|
static fn (string $table): array => Schema::getColumnListing($table),
|
|
),
|
|
);
|
|
$input = new GetPaginatedFaqsQueryInput(
|
|
pagination: Pagination::ofPage(new PageNumber(1), new PageSize(10)),
|
|
);
|
|
|
|
// WHEN
|
|
$paginator = $query($input);
|
|
|
|
// THEN
|
|
expect($paginator->total())->toBe(2);
|
|
expect($paginator->items())->toHaveCount(2);
|
|
});
|
|
});
|