49 lines
1.4 KiB
PHP
49 lines
1.4 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Integration\WithApp\App\Cqs\Actions\Faqs;
|
|
|
|
use App\Contracts\ActionInput;
|
|
use App\Cqs\Actions\Faqs\CreateFaq;
|
|
use App\Cqs\Actions\Faqs\CreateFaqInput;
|
|
use App\Models\Faq;
|
|
|
|
describe('CreateFaq action', function (): void {
|
|
it('creates and persists a faq in database', function (): void {
|
|
// GIVEN
|
|
$action = new CreateFaq();
|
|
$input = new CreateFaqInput(
|
|
question: 'Comment contacter le support ?',
|
|
answer: 'Via notre formulaire de contact en ligne.',
|
|
);
|
|
|
|
// WHEN
|
|
$faq = $action($input);
|
|
|
|
// THEN
|
|
expect($faq->question)->toBe('Comment contacter le support ?')
|
|
->and($faq->answer)->toBe('Via notre formulaire de contact en ligne.');
|
|
|
|
$fresh = Faq::query()->find($faq->id);
|
|
expect($fresh)->not->toBeNull()
|
|
->and($fresh?->question)->toBe('Comment contacter le support ?')
|
|
->and($fresh?->answer)->toBe('Via notre formulaire de contact en ligne.');
|
|
});
|
|
|
|
it('throws when an invalid input is passed', function (): void {
|
|
// GIVEN
|
|
$action = new CreateFaq();
|
|
$invalidInput = new class () implements ActionInput
|
|
{
|
|
};
|
|
|
|
// WHEN
|
|
expect(
|
|
/** @phpstan-ignore argument.type */
|
|
fn () => $action($invalidInput)
|
|
)
|
|
// THEN
|
|
->toThrow(\InvalidArgumentException::class);
|
|
});
|
|
});
|