ldc-cocotte/tests/Integration/WithApp/App/Cqs/Actions/Faqs/DeleteFaqTest.php

47 lines
1.2 KiB
PHP

<?php
declare(strict_types=1);
namespace Tests\Integration\WithApp\App\Cqs\Actions\Faqs;
use App\Contracts\ActionInput;
use App\Cqs\Actions\Faqs\DeleteFaq;
use App\Cqs\Actions\Faqs\DeleteFaqInput;
use App\Models\Faq;
describe('DeleteFaq action', function (): void {
it('deletes an existing faq from database', function (): void {
// GIVEN
$faq = new Faq();
$faq->fill([
'question' => 'Question à supprimer ?',
'answer' => 'Réponse à supprimer.',
]);
$faq->saveOrFail();
$action = new DeleteFaq();
$input = new DeleteFaqInput(faq: $faq);
// WHEN
$action($input);
// THEN
expect(Faq::query()->find($faq->id))->toBeNull();
});
it('throws when an invalid input is passed', function (): void {
// GIVEN
$action = new DeleteFaq();
$invalidInput = new class () implements ActionInput
{
};
// WHEN
expect(
/** @phpstan-ignore argument.type */
fn () => $action($invalidInput)
)
// THEN
->toThrow(\InvalidArgumentException::class);
});
});