50 lines
1.5 KiB
PHP
50 lines
1.5 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
declare(strict_types=1);
|
||
|
|
|
||
|
|
use App\Actions\Faqs\CreateFaq;
|
||
|
|
use App\Actions\Faqs\CreateFaqInput;
|
||
|
|
use App\Contracts\ActionInput;
|
||
|
|
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)->toBeInstanceOf(Faq::class)
|
||
|
|
->and($faq->id)->toBeInt()
|
||
|
|
->and($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);
|
||
|
|
});
|
||
|
|
});
|