ldc-cocotte/tests/Integration/WithApp/App/Cqs/Queries/Faqs/GetFaqsQueryTest.php

39 lines
1.1 KiB
PHP
Raw Permalink Normal View History

<?php
declare(strict_types=1);
namespace Tests\Integration\WithApp\App\Cqs\Queries\Faqs;
use App\Contracts\QueryInputEmpty;
use App\Cqs\Queries\Faqs\GetFaqsQuery;
use App\Dto\FaqDto;
use App\Models\Faq;
describe('GetFaqsQuery', function (): void {
it('returns a collection of FaqDto instances ordered by order', function (): void {
// GIVEN
$faq2 = new Faq();
$faq2->question = 'Second question?';
$faq2->answer = 'Second answer.';
$faq2->order = 2;
$faq2->save();
$faq1 = new Faq();
$faq1->question = 'First question?';
$faq1->answer = 'First answer.';
$faq1->order = 1;
$faq1->save();
$query = new GetFaqsQuery();
// WHEN
$faqs = $query(new QueryInputEmpty());
// THEN
expect($faqs)->toHaveCount(2)
->and($faqs->first())->toBeInstanceOf(FaqDto::class)
->and($faqs->first()?->question)->toBe('First question?')
->and($faqs->last()?->question)->toBe('Second question?');
});
});