type = DiscountType::PERCENT; $discount1->value = DiscountValue::fromPercentage(10); $discount1->is_old_price_displayed = true; $discount1->save(); $discount2 = new Discount(); $discount2->type = DiscountType::PERCENT; $discount2->value = DiscountValue::fromPercentage(20); $discount2->is_old_price_displayed = false; $discount2->save(); $query = new GetPaginatedDiscountsQuery(app(DataTableService::class)); $input = new GetPaginatedDiscountsQueryInput( pagination: Pagination::ofPage(new PageNumber(1), new PageSize(10)), ); // WHEN $paginator = $query($input); // THEN expect($paginator->total())->toBe(2) ->and($paginator->items())->toHaveCount(2) ->and($paginator->items()[0])->toBeInstanceOf(DiscountDto::class) ->and($paginator->items()[1])->toBeInstanceOf(DiscountDto::class); }); it('throws when an invalid input is passed', function (): void { // GIVEN $query = new GetPaginatedDiscountsQuery(app(DataTableService::class)); $invalidInput = new class () implements QueryInput { }; // WHEN expect( /** @phpstan-ignore argument.type */ fn () => $query($invalidInput) ) // THEN ->toThrow(\InvalidArgumentException::class); }); });