57 lines
1.8 KiB
PHP
57 lines
1.8 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Integration\WithApp\App\Cqs\Queries\Ranges;
|
|
|
|
use App\Cqs\Queries\Ranges\GetPaginatedRangesQuery;
|
|
use App\Cqs\Queries\Ranges\GetPaginatedRangesQueryInput;
|
|
use App\Models\Range;
|
|
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('GetPaginatedRangesQuery', function () {
|
|
test('it executes and returns paginated RangeDto collection', function () {
|
|
// GIVEN
|
|
$range1 = new Range();
|
|
$range1->name = 'Gamme Alpha';
|
|
$range1->picture_alt = 'Alt 1';
|
|
$range1->picture_title = 'Title 1';
|
|
$range1->status = true;
|
|
$range1->save();
|
|
|
|
$range2 = new Range();
|
|
$range2->name = 'Gamme Beta';
|
|
$range2->picture_alt = 'Alt 2';
|
|
$range2->picture_title = 'Title 2';
|
|
$range2->status = true;
|
|
$range2->save();
|
|
|
|
$dataTableService = new DataTableService(
|
|
Request::create('/'),
|
|
new Store('test', new NullSessionHandler()),
|
|
static fn (string $table): array => Schema::getColumnListing($table),
|
|
);
|
|
$query = new GetPaginatedRangesQuery($dataTableService);
|
|
$input = new GetPaginatedRangesQueryInput(
|
|
pagination: Pagination::ofPage(new PageNumber(1), new PageSize(10)),
|
|
);
|
|
|
|
// WHEN
|
|
$result = $query($input);
|
|
|
|
// THEN
|
|
expect($result->total())->toBe(2)
|
|
->and($result->items())->toHaveCount(2);
|
|
});
|
|
});
|