56 lines
1.6 KiB
PHP
56 lines
1.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use App\Actions\Faqs\UpdateFaq;
|
|
use App\Actions\Faqs\UpdateFaqInput;
|
|
use App\Contracts\ActionInput;
|
|
use App\Models\Faq;
|
|
|
|
describe('UpdateFaq action', function (): void {
|
|
it('updates an existing faq in database', function (): void {
|
|
// GIVEN
|
|
$faq = new Faq();
|
|
$faq->fill([
|
|
'question' => 'Ancienne question ?',
|
|
'answer' => 'Ancienne réponse.',
|
|
]);
|
|
$faq->saveOrFail();
|
|
|
|
$action = new UpdateFaq();
|
|
$input = new UpdateFaqInput(
|
|
faq: $faq,
|
|
question: 'Question mise à jour ?',
|
|
answer: 'Réponse mise à jour.',
|
|
);
|
|
|
|
// WHEN
|
|
$updatedFaq = $action($input);
|
|
|
|
// THEN
|
|
expect($updatedFaq->id)->toBe($faq->id)
|
|
->and($updatedFaq->question)->toBe('Question mise à jour ?')
|
|
->and($updatedFaq->answer)->toBe('Réponse mise à jour.');
|
|
|
|
$fresh = Faq::query()->find($faq->id);
|
|
expect($fresh)->not->toBeNull()
|
|
->and($fresh?->question)->toBe('Question mise à jour ?')
|
|
->and($fresh?->answer)->toBe('Réponse mise à jour.');
|
|
});
|
|
|
|
it('throws when an invalid input is passed', function (): void {
|
|
// GIVEN
|
|
$action = new UpdateFaq();
|
|
$invalidInput = new class () implements ActionInput
|
|
{
|
|
};
|
|
|
|
// WHEN
|
|
expect(
|
|
/** @phpstan-ignore argument.type */
|
|
fn () => $action($invalidInput)
|
|
)
|
|
// THEN
|
|
->toThrow(\InvalidArgumentException::class);
|
|
});
|
|
});
|