2026-09-29 14:53:02 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
2026-11-16 14:18:42 +01:00
|
|
|
namespace Tests\Unit\App\Cqs\Actions\Faqs;
|
|
|
|
|
|
2026-11-10 14:28:00 +01:00
|
|
|
use App\Cqs\Actions\Faqs\CreateFaqInput;
|
2026-09-29 14:53:02 +02:00
|
|
|
|
|
|
|
|
describe('CreateFaqInput', function (): void {
|
|
|
|
|
it('can be instantiated with valid data', function (): void {
|
|
|
|
|
// GIVEN
|
|
|
|
|
$question = 'Comment passer une commande ?';
|
|
|
|
|
$answer = 'Ajoutez des articles à votre panier et validez.';
|
|
|
|
|
|
|
|
|
|
// WHEN
|
|
|
|
|
$input = new CreateFaqInput(question: $question, answer: $answer);
|
|
|
|
|
|
|
|
|
|
// THEN
|
|
|
|
|
expect($input->question)->toBe($question)
|
|
|
|
|
->and($input->answer)->toBe($answer);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe('CreateFaqInput validation rules', function (): void {
|
|
|
|
|
it('throws when question is empty or too short', function (string $invalidQuestion): void {
|
|
|
|
|
// GIVEN
|
|
|
|
|
$answer = 'Une réponse valide.';
|
|
|
|
|
|
|
|
|
|
// WHEN
|
|
|
|
|
expect(fn () => new CreateFaqInput(question: $invalidQuestion, answer: $answer))
|
|
|
|
|
// THEN
|
|
|
|
|
->toThrow(\InvalidArgumentException::class);
|
|
|
|
|
})->with(['', ' ', 'abc']);
|
|
|
|
|
|
|
|
|
|
it('throws when question exceeds 255 characters', function (): void {
|
|
|
|
|
// GIVEN
|
|
|
|
|
$question = str_repeat('a', 256);
|
|
|
|
|
$answer = 'Une réponse valide.';
|
|
|
|
|
|
|
|
|
|
// WHEN
|
|
|
|
|
expect(fn () => new CreateFaqInput(question: $question, answer: $answer))
|
|
|
|
|
// THEN
|
|
|
|
|
->toThrow(\InvalidArgumentException::class);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('throws when answer is empty or too short', function (string $invalidAnswer): void {
|
|
|
|
|
// GIVEN
|
|
|
|
|
$question = 'Une question valide ?';
|
|
|
|
|
|
|
|
|
|
// WHEN
|
|
|
|
|
expect(fn () => new CreateFaqInput(question: $question, answer: $invalidAnswer))
|
|
|
|
|
// THEN
|
|
|
|
|
->toThrow(\InvalidArgumentException::class);
|
|
|
|
|
})->with(['', ' ', 'abc']);
|
|
|
|
|
});
|