ldc-boutique-cnc-sable/tests/Unit/App/Actions/Faqs/CreateFaqInputTest.php

53 lines
1.7 KiB
PHP

<?php
declare(strict_types=1);
use App\Actions\Faqs\CreateFaqInput;
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']);
});